Align the stack upon function entry
This commit is contained in:
@@ -1516,6 +1516,8 @@ begin
|
|||||||
elna_alloc_operation_target(instruction, variable_map)
|
elna_alloc_operation_target(instruction, variable_map)
|
||||||
elsif instruction^.operator = ElnaRtlOperator._xor then
|
elsif instruction^.operator = ElnaRtlOperator._xor then
|
||||||
elna_alloc_operation_target(instruction, variable_map)
|
elna_alloc_operation_target(instruction, variable_map)
|
||||||
|
elsif instruction^.operator = ElnaRtlOperator.div then
|
||||||
|
elna_alloc_operation_target(instruction, variable_map)
|
||||||
elsif instruction^.operator = ElnaRtlOperator.rem then
|
elsif instruction^.operator = ElnaRtlOperator.rem then
|
||||||
elna_alloc_operation_target(instruction, variable_map)
|
elna_alloc_operation_target(instruction, variable_map)
|
||||||
elsif instruction^.operator = ElnaRtlOperator.slt then
|
elsif instruction^.operator = ElnaRtlOperator.slt then
|
||||||
|
|||||||
@@ -1565,6 +1565,8 @@ begin
|
|||||||
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
||||||
elsif instruction^.operator = ElnaRtlOperator._xor then
|
elsif instruction^.operator = ElnaRtlOperator._xor then
|
||||||
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
||||||
|
elsif instruction^.operator = ElnaRtlOperator.div then
|
||||||
|
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
||||||
elsif instruction^.operator = ElnaRtlOperator.rem then
|
elsif instruction^.operator = ElnaRtlOperator.rem then
|
||||||
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
instruction := elna_alloc_binary(instructions, instruction, variable_map)
|
||||||
elsif instruction^.operator = ElnaRtlOperator.slt then
|
elsif instruction^.operator = ElnaRtlOperator.slt then
|
||||||
@@ -1615,13 +1617,13 @@ begin
|
|||||||
|
|
||||||
(* Write the prologue. *)
|
(* Write the prologue. *)
|
||||||
printf("\taddi sp, sp, -%i\n\tsw ra, %i(sp)\n\tsw s0, %i(sp)\n\taddi s0, sp, %i\n\0",
|
printf("\taddi sp, sp, -%i\n\tsw ra, %i(sp)\n\tsw s0, %i(sp)\n\taddi s0, sp, %i\n\0",
|
||||||
operand_value + 8, operand_value + 4, operand_value, operand_value + 8);
|
operand_value, operand_value - 4, operand_value - 8, operand_value);
|
||||||
fflush(nil)
|
fflush(nil)
|
||||||
elsif instruction^.operator = ElnaRtlOperator.ret then
|
elsif instruction^.operator = ElnaRtlOperator.ret then
|
||||||
operand_value := instruction^.operands[1].value;
|
operand_value := instruction^.operands[1].value;
|
||||||
|
|
||||||
(* Write the epilogue. *)
|
(* Write the epilogue. *)
|
||||||
printf("\tlw ra, %i(sp)\n\tlw s0, %i(sp)\n\taddi sp, sp, %i\n\0", operand_value + 4, operand_value, operand_value + 8);
|
printf("\tlw ra, %i(sp)\n\tlw s0, %i(sp)\n\taddi sp, sp, %i\n\0", operand_value - 4, operand_value - 8, operand_value);
|
||||||
fflush(nil)
|
fflush(nil)
|
||||||
elsif instruction^.operator = ElnaRtlOperator.nop then
|
elsif instruction^.operator = ElnaRtlOperator.nop then
|
||||||
else
|
else
|
||||||
@@ -1750,6 +1752,44 @@ begin
|
|||||||
elna_alloc_procedure(pair^.code)
|
elna_alloc_procedure(pair^.code)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
proc elna_fixup_instructions(instructions: ^ElnaList);
|
||||||
|
var
|
||||||
|
instruction: ^ElnaRtlInstruction;
|
||||||
|
stack_size: Word;
|
||||||
|
begin
|
||||||
|
instruction := instructions^.first;
|
||||||
|
stack_size := instruction^.operands[1].value;
|
||||||
|
|
||||||
|
(* Align the stack. *)
|
||||||
|
stack_size := stack_size + 8;
|
||||||
|
if stack_size % 16 then
|
||||||
|
stack_size := stack_size + 16
|
||||||
|
end;
|
||||||
|
stack_size := stack_size / 16;
|
||||||
|
stack_size := stack_size * 16;
|
||||||
|
|
||||||
|
instruction^.operands[1].value := stack_size;
|
||||||
|
instruction := instructions^.last;
|
||||||
|
instruction^.operands[1].value := stack_size
|
||||||
|
end;
|
||||||
|
|
||||||
|
proc elna_fixup_procedure(rtl_declaration: ^ElnaRtlProcedure);
|
||||||
|
begin
|
||||||
|
.elna_fixup_procedure_loop;
|
||||||
|
|
||||||
|
elna_fixup_instructions(@rtl_declaration^.body);
|
||||||
|
|
||||||
|
rtl_declaration := rtl_declaration^.next;
|
||||||
|
if rtl_declaration <> nil then
|
||||||
|
goto elna_fixup_procedure_loop
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
proc elna_fixup_module(pair: ^ElnaInstructionModule);
|
||||||
|
begin
|
||||||
|
elna_fixup_procedure(pair^.code)
|
||||||
|
end;
|
||||||
|
|
||||||
proc elna_riscv_module(pair: ^ElnaInstructionModule);
|
proc elna_riscv_module(pair: ^ElnaInstructionModule);
|
||||||
var
|
var
|
||||||
compiler_strings_copy: Word;
|
compiler_strings_copy: Word;
|
||||||
@@ -4378,6 +4418,7 @@ begin
|
|||||||
tac := elna_tac_module_declaration(parser_node);
|
tac := elna_tac_module_declaration(parser_node);
|
||||||
rtl := elna_rtl_module_declaration(tac);
|
rtl := elna_rtl_module_declaration(tac);
|
||||||
elna_alloc_module(rtl);
|
elna_alloc_module(rtl);
|
||||||
|
elna_fixup_module(rtl);
|
||||||
elna_riscv_module(rtl);
|
elna_riscv_module(rtl);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user