Add assembly generation stage

This commit is contained in:
2025-11-11 18:55:43 +01:00
parent d144cb2101
commit c24373927c
2 changed files with 674 additions and 504 deletions

View File

@@ -1109,10 +1109,10 @@ begin
_write_s("\tbeqz", 5) _write_s("\tbeqz", 5)
elsif instruction_kind = ElnaTacOperator.start then elsif instruction_kind = ElnaTacOperator.start then
argument_count := 0; argument_count := 0;
_write_z("\taddi sp, sp, -128\n\tsw ra, 124(sp)\n\tsw s0, 120(sp)\n\taddi s0, sp, 128\0") _write_z("\taddi sp, sp, -144\n\tsw ra, 140(sp)\n\tsw s0, 136(sp)\n\taddi s0, sp, 144\0")
elsif instruction_kind = ElnaTacOperator.ret then elsif instruction_kind = ElnaTacOperator.ret then
argument_count := 0; argument_count := 0;
_write_z("\tlw ra, 124(sp)\n\tlw s0, 120(sp)\n\taddi sp, sp, 128\0") _write_z("\tlw ra, 140(sp)\n\tlw s0, 136(sp)\n\taddi sp, sp, 144\0")
end; end;
return argument_count return argument_count
end; end;
@@ -1900,7 +1900,7 @@ begin
first_instruction := _elna_tac_unary_expression(operand_node, symbol_table); first_instruction := _elna_tac_unary_expression(operand_node, symbol_table);
(* Save the value of the left expression on the stack. *) (* Save the value of the left expression on the stack. *)
instruction := _elna_tac_store_word(ElnaTacRegister.t0, ElnaTacRegister.sp, 64); instruction := _elna_tac_store_word(ElnaTacRegister.t0, ElnaTacRegister.sp, 72);
_elna_tac_instruction_set_next(first_instruction, instruction); _elna_tac_instruction_set_next(first_instruction, instruction);
current_instruction := instruction; current_instruction := instruction;
@@ -1910,7 +1910,7 @@ begin
current_instruction := instruction; current_instruction := instruction;
(* Load the left expression from the stack; *) (* Load the left expression from the stack; *)
instruction := _elna_tac_load_word(ElnaTacRegister.t1, ElnaTacRegister.sp, 64); instruction := _elna_tac_load_word(ElnaTacRegister.t1, ElnaTacRegister.sp, 72);
_elna_tac_instruction_set_next(current_instruction, instruction); _elna_tac_instruction_set_next(current_instruction, instruction);
current_instruction := instruction; current_instruction := instruction;
@@ -2088,7 +2088,7 @@ begin
stack_offset := argument_count * 4; stack_offset := argument_count * 4;
instruction := _elna_tac_store_word(ElnaTacRegister.t0, instruction := _elna_tac_store_word(ElnaTacRegister.t0,
ElnaTacRegister.sp, 116 - stack_offset); ElnaTacRegister.sp, 132 - stack_offset);
_elna_tac_instruction_set_next(current_instruction, instruction); _elna_tac_instruction_set_next(current_instruction, instruction);
current_instruction := instruction; current_instruction := instruction;
@@ -2103,9 +2103,9 @@ begin
argument_count := argument_count - 1; argument_count := argument_count - 1;
stack_offset := argument_count * 4; stack_offset := argument_count * 4;
(* Calculate the stack offset: 116 - (4 * argument_counter) *) (* Calculate the stack offset: 132 - (4 * argument_counter) *)
instruction := _elna_tac_load_word(ElnaTacRegister.a0 + argument_count, instruction := _elna_tac_load_word(ElnaTacRegister.a0 + argument_count,
ElnaTacRegister.sp, 116 - stack_offset); ElnaTacRegister.sp, 132 - stack_offset);
_elna_tac_instruction_set_next(current_instruction, instruction); _elna_tac_instruction_set_next(current_instruction, instruction);
current_instruction := instruction; current_instruction := instruction;
@@ -2502,7 +2502,7 @@ begin
first_instruction := _elna_tac_designator(current_expression, symbol_table, @is_address); first_instruction := _elna_tac_designator(current_expression, symbol_table, @is_address);
(* Save the assignee address on the stack. *) (* Save the assignee address on the stack. *)
current_instruction := _elna_tac_store_word(ElnaTacRegister.t0, ElnaTacRegister.sp, 60); current_instruction := _elna_tac_store_word(ElnaTacRegister.t0, ElnaTacRegister.sp, 76);
_elna_tac_instruction_set_next(first_instruction, current_instruction); _elna_tac_instruction_set_next(first_instruction, current_instruction);
(* Compile the assignment. *) (* Compile the assignment. *)
@@ -2510,7 +2510,7 @@ begin
instruction := _elna_tac_binary_expression(current_expression, symbol_table); instruction := _elna_tac_binary_expression(current_expression, symbol_table);
_elna_tac_instruction_set_next(current_instruction, instruction); _elna_tac_instruction_set_next(current_instruction, instruction);
current_instruction := _elna_tac_load_word(ElnaTacRegister.t1, ElnaTacRegister.sp, 60); current_instruction := _elna_tac_load_word(ElnaTacRegister.t1, ElnaTacRegister.sp, 76);
_elna_tac_instruction_set_next(instruction, current_instruction); _elna_tac_instruction_set_next(instruction, current_instruction);
instruction := _elna_tac_store_word(ElnaTacRegister.t0, ElnaTacRegister.t1, 0); instruction := _elna_tac_store_word(ElnaTacRegister.t0, ElnaTacRegister.t1, 0);
@@ -3415,9 +3415,9 @@ begin
current_word := current_word + 4; current_word := current_word + 4;
(* Calculate the stack offset: 88 - (4 * parameter_counter) *) (* Calculate the stack offset: 104 - (4 * parameter_counter) *)
offset := parameter_index * 4; offset := parameter_index * 4;
current_word^ := 88 - offset; current_word^ := 104 - offset;
return result return result
end; end;

File diff suppressed because it is too large Load Diff