fix: reserve return pointer and RBP on stack for user func bodies
This commit is contained in:
parent
82a3d6068b
commit
e740641ae8
@ -50,7 +50,7 @@ class Stack {
|
|||||||
* @param sizes
|
* @param sizes
|
||||||
* The sizes of the values to reserve space for.
|
* The sizes of the values to reserve space for.
|
||||||
*/
|
*/
|
||||||
def reserve(sizes: List[Size]): AsmLine = {
|
def reserve(sizes: Size*): AsmLine = {
|
||||||
sizes.foreach { itemSize =>
|
sizes.foreach { itemSize =>
|
||||||
stack += stack.size -> StackValue(itemSize, sizeBytes)
|
stack += stack.size -> StackValue(itemSize, sizeBytes)
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,9 @@ object asmGenerator {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def wrapBuiltinFunc(labelName: String, funcBody: Chain[AsmLine]): Chain[AsmLine] = {
|
private def wrapBuiltinFunc(labelName: String, funcBody: Chain[AsmLine])(using
|
||||||
|
stack: Stack
|
||||||
|
): Chain[AsmLine] = {
|
||||||
var chain = Chain.one[AsmLine](LabelDef(labelName))
|
var chain = Chain.one[AsmLine](LabelDef(labelName))
|
||||||
chain ++= funcPrologue()
|
chain ++= funcPrologue()
|
||||||
chain ++= funcBody
|
chain ++= funcBody
|
||||||
@ -108,6 +110,7 @@ object asmGenerator {
|
|||||||
given stack: Stack = Stack()
|
given stack: Stack = Stack()
|
||||||
// Setup the stack with param 7 and up
|
// Setup the stack with param 7 and up
|
||||||
func.params.drop(argRegs.size).foreach(stack.reserve(_))
|
func.params.drop(argRegs.size).foreach(stack.reserve(_))
|
||||||
|
stack.reserve(Q64) // Reserve return pointer slot
|
||||||
var chain = Chain.one[AsmLine](LabelDef(labelGenerator.getLabel(func.name)))
|
var chain = Chain.one[AsmLine](LabelDef(labelGenerator.getLabel(func.name)))
|
||||||
chain ++= funcPrologue()
|
chain ++= funcPrologue()
|
||||||
// Push the rest of params onto the stack for simplicity
|
// Push the rest of params onto the stack for simplicity
|
||||||
@ -120,6 +123,7 @@ object asmGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def generateBuiltInFuncs()(using
|
private def generateBuiltInFuncs()(using
|
||||||
|
stack: Stack,
|
||||||
labelGenerator: LabelGenerator
|
labelGenerator: LabelGenerator
|
||||||
): Chain[AsmLine] = {
|
): Chain[AsmLine] = {
|
||||||
var chain = Chain.empty[AsmLine]
|
var chain = Chain.empty[AsmLine]
|
||||||
@ -425,9 +429,9 @@ object asmGenerator {
|
|||||||
chain
|
chain
|
||||||
}
|
}
|
||||||
|
|
||||||
private def funcPrologue(): Chain[AsmLine] = {
|
private def funcPrologue()(using stack: Stack): Chain[AsmLine] = {
|
||||||
var chain = Chain.empty[AsmLine]
|
var chain = Chain.empty[AsmLine]
|
||||||
chain += Push(RBP)
|
chain += stack.push(Q64, RBP)
|
||||||
chain += Move(RBP, Register(Q64, SP))
|
chain += Move(RBP, Register(Q64, SP))
|
||||||
chain
|
chain
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll {
|
|||||||
// "^.*wacc-examples/valid/basic/exit.*$",
|
// "^.*wacc-examples/valid/basic/exit.*$",
|
||||||
// "^.*wacc-examples/valid/basic/skip.*$",
|
// "^.*wacc-examples/valid/basic/skip.*$",
|
||||||
// "^.*wacc-examples/valid/expressions.*$",
|
// "^.*wacc-examples/valid/expressions.*$",
|
||||||
"^.*wacc-examples/valid/function/nested_functions.*$",
|
// "^.*wacc-examples/valid/function/nested_functions.*$",
|
||||||
"^.*wacc-examples/valid/function/simple_functions.*$",
|
// "^.*wacc-examples/valid/function/simple_functions.*$",
|
||||||
// "^.*wacc-examples/valid/if.*$",
|
// "^.*wacc-examples/valid/if.*$",
|
||||||
// "^.*wacc-examples/valid/IO/print.*$",
|
// "^.*wacc-examples/valid/IO/print.*$",
|
||||||
// "^.*wacc-examples/valid/IO/read.*$",
|
// "^.*wacc-examples/valid/IO/read.*$",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user