Rename RTL instructions to Risc-V versions
This commit is contained in:
@@ -17,7 +17,8 @@ type
|
|||||||
next: Word;
|
next: Word;
|
||||||
name: Word;
|
name: Word;
|
||||||
length: Word;
|
length: Word;
|
||||||
body: Word
|
body: Word;
|
||||||
|
stack: Word
|
||||||
end;
|
end;
|
||||||
_node = record
|
_node = record
|
||||||
kind: Word
|
kind: Word
|
||||||
@@ -372,16 +373,15 @@ type
|
|||||||
jump,
|
jump,
|
||||||
beqz,
|
beqz,
|
||||||
label,
|
label,
|
||||||
start,
|
|
||||||
ret
|
ret
|
||||||
);
|
);
|
||||||
ElnaRtlOperator = (
|
ElnaRtlOperator = (
|
||||||
load_immediate,
|
li,
|
||||||
load_address,
|
la,
|
||||||
add,
|
add,
|
||||||
add_immediate,
|
addi,
|
||||||
load_word,
|
lw,
|
||||||
store_word,
|
sw,
|
||||||
jal,
|
jal,
|
||||||
move,
|
move,
|
||||||
sub,
|
sub,
|
||||||
@@ -394,13 +394,13 @@ type
|
|||||||
seqz,
|
seqz,
|
||||||
snez,
|
snez,
|
||||||
slt,
|
slt,
|
||||||
xor_immediate,
|
xori,
|
||||||
neg,
|
neg,
|
||||||
not,
|
not,
|
||||||
jump,
|
jump,
|
||||||
beqz,
|
beqz,
|
||||||
label,
|
label,
|
||||||
start,
|
allocate_stack,
|
||||||
ret
|
ret
|
||||||
);
|
);
|
||||||
ElnaTacOperand = (temporary, immediate, symbol, stack);
|
ElnaTacOperand = (temporary, immediate, symbol, stack);
|
||||||
@@ -837,19 +837,19 @@ begin
|
|||||||
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, operand_number);
|
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, operand_number);
|
||||||
|
|
||||||
if operand_type = ElnaTacOperand.immediate then
|
if operand_type = ElnaTacOperand.immediate then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_immediate);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.li);
|
||||||
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.immediate, operand_value, operand_length)
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.immediate, operand_value, operand_length)
|
||||||
elsif operand_type = ElnaTacOperand.stack then
|
elsif operand_type = ElnaTacOperand.stack then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_word);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value)
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value)
|
||||||
elsif operand_type = ElnaTacOperand.symbol then
|
elsif operand_type = ElnaTacOperand.symbol then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_address);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
||||||
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.symbol, operand_value, operand_length);
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.symbol, operand_value, operand_length);
|
||||||
|
|
||||||
next_instruction := elna_rtl_instruction_create(ElnaRtlOperator.load_word);
|
next_instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
elna_rtl_instruction_set_operand(next_instruction, 1, ElnaRtlOperand.register, into, 0);
|
elna_rtl_instruction_set_operand(next_instruction, 1, ElnaRtlOperand.register, into, 0);
|
||||||
elna_rtl_instruction_set_operand(next_instruction, 2, ElnaRtlOperand.offset, into, 0);
|
elna_rtl_instruction_set_operand(next_instruction, 2, ElnaRtlOperand.offset, into, 0);
|
||||||
|
|
||||||
@@ -875,11 +875,11 @@ begin
|
|||||||
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, operand_number);
|
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, operand_number);
|
||||||
|
|
||||||
if operand_type = ElnaTacOperand.stack then
|
if operand_type = ElnaTacOperand.stack then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.add_immediate);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.addi);
|
||||||
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value)
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value)
|
||||||
elsif operand_type = ElnaTacOperand.symbol then
|
elsif operand_type = ElnaTacOperand.symbol then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_address);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
||||||
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
elna_rtl_instruction_set_operand(result, 1, ElnaRtlOperand.register, into, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.symbol, operand_value, operand_length)
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.symbol, operand_value, operand_length)
|
||||||
end;
|
end;
|
||||||
@@ -991,7 +991,7 @@ begin
|
|||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.sp, 0);
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.sp, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, operand_value, 0)
|
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, operand_value, 0)
|
||||||
elsif operand_type = ElnaTacOperand.symbol then
|
elsif operand_type = ElnaTacOperand.symbol then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_address);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
||||||
|
|
||||||
elna_rtl_copy_operand(tac_instruction, 1, result);
|
elna_rtl_copy_operand(tac_instruction, 1, result);
|
||||||
elna_rtl_copy_operand(tac_instruction, 2, result)
|
elna_rtl_copy_operand(tac_instruction, 2, result)
|
||||||
@@ -1007,10 +1007,10 @@ begin
|
|||||||
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, 2);
|
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, 2);
|
||||||
|
|
||||||
if operand_type = ElnaTacOperand.stack then
|
if operand_type = ElnaTacOperand.stack then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_word);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
|
|
||||||
operand_value := _elna_tac_instruction_get_operand_value(tac_instruction, 1);
|
operand_value := _elna_tac_instruction_get_operand_value(tac_instruction, 1);
|
||||||
next_instruction^ := elna_rtl_instruction_create(ElnaRtlOperator.load_word);
|
next_instruction^ := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
elna_rtl_instruction_set_operand(next_instruction^, 1, ElnaRtlOperand.register, operand_value, 0);
|
elna_rtl_instruction_set_operand(next_instruction^, 1, ElnaRtlOperand.register, operand_value, 0);
|
||||||
elna_rtl_instruction_set_operand(next_instruction^, 2, ElnaRtlOperand.offset, operand_value, 0);
|
elna_rtl_instruction_set_operand(next_instruction^, 2, ElnaRtlOperand.offset, operand_value, 0);
|
||||||
|
|
||||||
@@ -1018,7 +1018,7 @@ begin
|
|||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value);
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value);
|
||||||
ElnaInstructionList_set_next(result, next_instruction^)
|
ElnaInstructionList_set_next(result, next_instruction^)
|
||||||
elsif operand_type = ElnaTacOperand.temporary then
|
elsif operand_type = ElnaTacOperand.temporary then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.load_word);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
|
|
||||||
elna_rtl_copy_operand(tac_instruction, 1, result);
|
elna_rtl_copy_operand(tac_instruction, 1, result);
|
||||||
operand_value := _elna_tac_instruction_get_operand_value(tac_instruction, 2);
|
operand_value := _elna_tac_instruction_get_operand_value(tac_instruction, 2);
|
||||||
@@ -1026,7 +1026,7 @@ begin
|
|||||||
end
|
end
|
||||||
elsif instruction_kind = ElnaTacOperator.store_word then
|
elsif instruction_kind = ElnaTacOperator.store_word then
|
||||||
operands := elna_rtl_load_operand_value(tac_instruction, 1, ElnaRtlRegister.t0);
|
operands := elna_rtl_load_operand_value(tac_instruction, 1, ElnaRtlRegister.t0);
|
||||||
next_instruction^ := elna_rtl_instruction_create(ElnaRtlOperator.store_word);
|
next_instruction^ := elna_rtl_instruction_create(ElnaRtlOperator.sw);
|
||||||
result := operands;
|
result := operands;
|
||||||
operands := ElnaInstructionList_get_next(result);
|
operands := ElnaInstructionList_get_next(result);
|
||||||
|
|
||||||
@@ -1087,7 +1087,7 @@ begin
|
|||||||
ElnaInstructionList_set_next(next_instruction^, intermediate_instruction);
|
ElnaInstructionList_set_next(next_instruction^, intermediate_instruction);
|
||||||
next_instruction^ := intermediate_instruction;
|
next_instruction^ := intermediate_instruction;
|
||||||
|
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.xor_immediate);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.xori);
|
||||||
elna_rtl_copy_operand(tac_instruction, 1, result);
|
elna_rtl_copy_operand(tac_instruction, 1, result);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.t2, 0);
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.t2, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, 1, 0);
|
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, 1, 0);
|
||||||
@@ -1095,7 +1095,7 @@ begin
|
|||||||
next_instruction^ := result;
|
next_instruction^ := result;
|
||||||
|
|
||||||
result := operands;
|
result := operands;
|
||||||
elna_rtl_instruction_set_kind(next_instruction^, ElnaRtlOperator.xor_immediate)
|
elna_rtl_instruction_set_kind(next_instruction^, ElnaRtlOperator.xori)
|
||||||
elsif instruction_kind = ElnaTacOperator.sge then
|
elsif instruction_kind = ElnaTacOperator.sge then
|
||||||
operands := elna_rtl_binary_operands(tac_instruction, next_instruction);
|
operands := elna_rtl_binary_operands(tac_instruction, next_instruction);
|
||||||
intermediate_instruction := elna_rtl_instruction_create(ElnaRtlOperator.slt);
|
intermediate_instruction := elna_rtl_instruction_create(ElnaRtlOperator.slt);
|
||||||
@@ -1106,7 +1106,7 @@ begin
|
|||||||
ElnaInstructionList_set_next(next_instruction^, intermediate_instruction);
|
ElnaInstructionList_set_next(next_instruction^, intermediate_instruction);
|
||||||
next_instruction^ := intermediate_instruction;
|
next_instruction^ := intermediate_instruction;
|
||||||
|
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.xor_immediate);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.xori);
|
||||||
elna_rtl_copy_operand(tac_instruction, 1, result);
|
elna_rtl_copy_operand(tac_instruction, 1, result);
|
||||||
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.t2, 0);
|
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.t2, 0);
|
||||||
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, 1, 0);
|
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, 1, 0);
|
||||||
@@ -1114,7 +1114,7 @@ begin
|
|||||||
next_instruction^ := result;
|
next_instruction^ := result;
|
||||||
|
|
||||||
result := operands;
|
result := operands;
|
||||||
elna_rtl_instruction_set_kind(next_instruction^, ElnaRtlOperator.xor_immediate)
|
elna_rtl_instruction_set_kind(next_instruction^, ElnaRtlOperator.xori)
|
||||||
elsif instruction_kind = ElnaTacOperator.seq then
|
elsif instruction_kind = ElnaTacOperator.seq then
|
||||||
result := elna_rtl_binary_equality(tac_instruction, ElnaRtlOperator.seqz, next_instruction)
|
result := elna_rtl_binary_equality(tac_instruction, ElnaRtlOperator.seqz, next_instruction)
|
||||||
elsif instruction_kind = ElnaTacOperator.sne then
|
elsif instruction_kind = ElnaTacOperator.sne then
|
||||||
@@ -1134,10 +1134,8 @@ begin
|
|||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.beqz);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.beqz);
|
||||||
elna_rtl_copy_operand(tac_instruction, 1, result);
|
elna_rtl_copy_operand(tac_instruction, 1, result);
|
||||||
elna_rtl_copy_operand(tac_instruction, 2, result)
|
elna_rtl_copy_operand(tac_instruction, 2, result)
|
||||||
elsif instruction_kind = ElnaTacOperator.start then
|
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.start)
|
|
||||||
elsif instruction_kind = ElnaTacOperator.ret then
|
elsif instruction_kind = ElnaTacOperator.ret then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.ret)
|
result := elna_rtl_load_operand_value(tac_instruction, 1, ElnaRtlRegister.a0)
|
||||||
elsif instruction_kind = ElnaTacOperator.label then
|
elsif instruction_kind = ElnaTacOperator.label then
|
||||||
result := elna_rtl_instruction_create(ElnaRtlOperator.label);
|
result := elna_rtl_instruction_create(ElnaRtlOperator.label);
|
||||||
elna_rtl_copy_operand(tac_instruction, 1, result)
|
elna_rtl_copy_operand(tac_instruction, 1, result)
|
||||||
@@ -1153,7 +1151,7 @@ begin
|
|||||||
result := operands;
|
result := operands;
|
||||||
operands := ElnaInstructionList_get_next(result);
|
operands := ElnaInstructionList_get_next(result);
|
||||||
|
|
||||||
next_instruction^ := elna_rtl_instruction_create(ElnaRtlOperator.store_word);
|
next_instruction^ := elna_rtl_instruction_create(ElnaRtlOperator.sw);
|
||||||
_elna_tac_instruction_set_operand(next_instruction^, 1, ElnaRtlOperand.register, ElnaRtlRegister.t4, 0);
|
_elna_tac_instruction_set_operand(next_instruction^, 1, ElnaRtlOperand.register, ElnaRtlRegister.t4, 0);
|
||||||
_elna_tac_instruction_set_operand(next_instruction^, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value);
|
_elna_tac_instruction_set_operand(next_instruction^, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value);
|
||||||
|
|
||||||
@@ -1201,22 +1199,22 @@ proc _elna_writer_instruction_name(instruction_kind: Word);
|
|||||||
var
|
var
|
||||||
argument_count: Word;
|
argument_count: Word;
|
||||||
begin
|
begin
|
||||||
if instruction_kind = ElnaRtlOperator.load_immediate then
|
if instruction_kind = ElnaRtlOperator.li then
|
||||||
argument_count := 2;
|
argument_count := 2;
|
||||||
_write_s("\tli", 3)
|
_write_s("\tli", 3)
|
||||||
elsif instruction_kind = ElnaRtlOperator.load_address then
|
elsif instruction_kind = ElnaRtlOperator.la then
|
||||||
argument_count := 2;
|
argument_count := 2;
|
||||||
_write_s("\tla", 3)
|
_write_s("\tla", 3)
|
||||||
elsif instruction_kind = ElnaRtlOperator.add then
|
elsif instruction_kind = ElnaRtlOperator.add then
|
||||||
argument_count := 3;
|
argument_count := 3;
|
||||||
_write_s("\tadd", 4)
|
_write_s("\tadd", 4)
|
||||||
elsif instruction_kind = ElnaRtlOperator.add_immediate then
|
elsif instruction_kind = ElnaRtlOperator.addi then
|
||||||
argument_count := 3;
|
argument_count := 3;
|
||||||
_write_s("\taddi", 5)
|
_write_s("\taddi", 5)
|
||||||
elsif instruction_kind = ElnaRtlOperator.load_word then
|
elsif instruction_kind = ElnaRtlOperator.lw then
|
||||||
argument_count := 2;
|
argument_count := 2;
|
||||||
_write_s("\tlw", 3)
|
_write_s("\tlw", 3)
|
||||||
elsif instruction_kind = ElnaRtlOperator.store_word then
|
elsif instruction_kind = ElnaRtlOperator.sw then
|
||||||
argument_count := 2;
|
argument_count := 2;
|
||||||
_write_s("\tsw", 3)
|
_write_s("\tsw", 3)
|
||||||
elsif instruction_kind = ElnaRtlOperator.jal then
|
elsif instruction_kind = ElnaRtlOperator.jal then
|
||||||
@@ -1240,7 +1238,7 @@ begin
|
|||||||
elsif instruction_kind = ElnaRtlOperator._xor then
|
elsif instruction_kind = ElnaRtlOperator._xor then
|
||||||
argument_count := 3;
|
argument_count := 3;
|
||||||
_write_s("\txor", 4)
|
_write_s("\txor", 4)
|
||||||
elsif instruction_kind = ElnaRtlOperator.xor_immediate then
|
elsif instruction_kind = ElnaRtlOperator.xori then
|
||||||
argument_count := 3;
|
argument_count := 3;
|
||||||
_write_s("\txori", 5)
|
_write_s("\txori", 5)
|
||||||
elsif instruction_kind = ElnaRtlOperator._or then
|
elsif instruction_kind = ElnaRtlOperator._or then
|
||||||
@@ -1270,12 +1268,8 @@ begin
|
|||||||
elsif instruction_kind = ElnaRtlOperator.beqz then
|
elsif instruction_kind = ElnaRtlOperator.beqz then
|
||||||
argument_count := 2;
|
argument_count := 2;
|
||||||
_write_s("\tbeqz", 5)
|
_write_s("\tbeqz", 5)
|
||||||
elsif instruction_kind = ElnaRtlOperator.start then
|
else (* ElnaRtlOperator.allocate_stack or ElnaRtlOperator.ret *)
|
||||||
argument_count := 0;
|
argument_count := 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 = ElnaRtlOperator.ret then
|
|
||||||
argument_count := 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;
|
||||||
@@ -1394,11 +1388,13 @@ var
|
|||||||
name_pointer: Word;
|
name_pointer: Word;
|
||||||
name_length: Word;
|
name_length: Word;
|
||||||
body_statements: Word;
|
body_statements: Word;
|
||||||
|
has_stack: Word;
|
||||||
begin
|
begin
|
||||||
.elna_writer_procedure_loop;
|
.elna_writer_procedure_loop;
|
||||||
name_pointer := ElnaInstructionDeclaration_get_name(procedure);
|
name_pointer := ElnaInstructionDeclaration_get_name(procedure);
|
||||||
name_length := ElnaInstructionDeclaration_get_length(procedure);
|
name_length := ElnaInstructionDeclaration_get_length(procedure);
|
||||||
body_statements := ElnaInstructionDeclaration_get_body(procedure);
|
body_statements := ElnaInstructionDeclaration_get_body(procedure);
|
||||||
|
has_stack := ElnaInstructionDeclaration_get_stack(procedure);
|
||||||
|
|
||||||
(* Write .type _procedure_name, @function. *)
|
(* Write .type _procedure_name, @function. *)
|
||||||
_write_z(".type \0");
|
_write_z(".type \0");
|
||||||
@@ -1410,7 +1406,15 @@ begin
|
|||||||
_write_s(name_pointer, name_length);
|
_write_s(name_pointer, name_length);
|
||||||
_write_z(":\n\0");
|
_write_z(":\n\0");
|
||||||
|
|
||||||
|
(* Write the prologue. *)
|
||||||
|
if has_stack then
|
||||||
|
_write_z("\taddi sp, sp, -144\n\tsw ra, 140(sp)\n\tsw s0, 136(sp)\n\taddi s0, sp, 144\n\0")
|
||||||
|
end;
|
||||||
_elna_writer_instructions(body_statements);
|
_elna_writer_instructions(body_statements);
|
||||||
|
(* Write the epilogue. *)
|
||||||
|
if has_stack then
|
||||||
|
_write_z("\tlw ra, 140(sp)\n\tlw s0, 136(sp)\n\taddi sp, sp, 144\n\0")
|
||||||
|
end;
|
||||||
_write_z("\tret\n\0");
|
_write_z("\tret\n\0");
|
||||||
|
|
||||||
procedure := ElnaInstructionList_get_next(procedure);
|
procedure := ElnaInstructionList_get_next(procedure);
|
||||||
@@ -2462,9 +2466,8 @@ begin
|
|||||||
return_expression := _return_statement_get_returned(parser_node);
|
return_expression := _return_statement_get_returned(parser_node);
|
||||||
first_instruction := _elna_tac_binary_expression(return_expression, symbol_table, @operand_type, @operand_value, @operand_length);
|
first_instruction := _elna_tac_binary_expression(return_expression, symbol_table, @operand_type, @operand_value, @operand_length);
|
||||||
|
|
||||||
instruction := _elna_tac_instruction_create(ElnaTacOperator.assign);
|
instruction := _elna_tac_instruction_create(ElnaTacOperator.ret);
|
||||||
_elna_tac_instruction_set_operand(instruction, 1, ElnaTacOperand.temporary, 11, 0);
|
_elna_tac_instruction_set_operand(instruction, 1, operand_type, operand_value, operand_length);
|
||||||
_elna_tac_instruction_set_operand(instruction, 2, operand_type, operand_value, operand_length);
|
|
||||||
|
|
||||||
return elna_instruction_list_concatenate(first_instruction, instruction)
|
return elna_instruction_list_concatenate(first_instruction, instruction)
|
||||||
end;
|
end;
|
||||||
@@ -3310,16 +3313,26 @@ var
|
|||||||
length: Word;
|
length: Word;
|
||||||
body: Word;
|
body: Word;
|
||||||
result: Word;
|
result: Word;
|
||||||
|
return_instruction: Word;
|
||||||
|
has_stack: Word;
|
||||||
begin
|
begin
|
||||||
result := malloc(ElnaInstructionDeclaration_size());
|
result := malloc(ElnaInstructionDeclaration_size());
|
||||||
name := ElnaInstructionDeclaration_get_name(tac_declaration);
|
name := ElnaInstructionDeclaration_get_name(tac_declaration);
|
||||||
length := ElnaInstructionDeclaration_get_length(tac_declaration);
|
length := ElnaInstructionDeclaration_get_length(tac_declaration);
|
||||||
|
has_stack := ElnaInstructionDeclaration_get_stack(tac_declaration);
|
||||||
body := ElnaInstructionDeclaration_get_body(tac_declaration);
|
body := ElnaInstructionDeclaration_get_body(tac_declaration);
|
||||||
body := elna_rtl_instructions(body);
|
body := elna_rtl_instructions(body);
|
||||||
|
|
||||||
|
return_instruction := elna_rtl_instruction_create(ElnaRtlOperator.allocate_stack);
|
||||||
|
ElnaInstructionList_set_next(return_instruction, body);
|
||||||
|
body := return_instruction;
|
||||||
|
return_instruction := elna_rtl_instruction_create(ElnaRtlOperator.ret);
|
||||||
|
elna_instruction_list_concatenate(body, return_instruction);
|
||||||
|
|
||||||
ElnaInstructionList_set_next(result, 0);
|
ElnaInstructionList_set_next(result, 0);
|
||||||
ElnaInstructionDeclaration_set_name(result, name);
|
ElnaInstructionDeclaration_set_name(result, name);
|
||||||
ElnaInstructionDeclaration_set_length(result, length);
|
ElnaInstructionDeclaration_set_length(result, length);
|
||||||
|
ElnaInstructionDeclaration_set_stack(result, has_stack);
|
||||||
ElnaInstructionDeclaration_set_body(result, body);
|
ElnaInstructionDeclaration_set_body(result, body);
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -3341,6 +3354,7 @@ begin
|
|||||||
result := malloc(ElnaInstructionDeclaration_size());
|
result := malloc(ElnaInstructionDeclaration_size());
|
||||||
|
|
||||||
ElnaInstructionList_set_next(result, 0);
|
ElnaInstructionList_set_next(result, 0);
|
||||||
|
ElnaInstructionDeclaration_set_stack(result, 1);
|
||||||
|
|
||||||
name_pointer := _declaration_get_name(parser_node);
|
name_pointer := _declaration_get_name(parser_node);
|
||||||
name_length := _declaration_get_length(parser_node);
|
name_length := _declaration_get_length(parser_node);
|
||||||
@@ -3351,20 +3365,12 @@ begin
|
|||||||
symbol_info := _symbol_table_lookup(@symbol_table_global, name_pointer, name_length);
|
symbol_info := _symbol_table_lookup(@symbol_table_global, name_pointer, name_length);
|
||||||
new_symbol_table := _procedure_info_get_symbol_table(symbol_info);
|
new_symbol_table := _procedure_info_get_symbol_table(symbol_info);
|
||||||
|
|
||||||
(* Write the prologue. *)
|
|
||||||
first_instruction := _elna_tac_instruction_create(ElnaTacOperator.start);
|
|
||||||
|
|
||||||
current_parameter := _procedure_declaration_get_parameters(parser_node);
|
current_parameter := _procedure_declaration_get_parameters(parser_node);
|
||||||
current_parameter := _elna_tac_parameters(current_parameter, new_symbol_table);
|
first_instruction := _elna_tac_parameters(current_parameter, new_symbol_table);
|
||||||
elna_instruction_list_concatenate(first_instruction, current_parameter);
|
|
||||||
|
|
||||||
body := _procedure_declaration_get_body(parser_node);
|
body := _procedure_declaration_get_body(parser_node);
|
||||||
instruction := _elna_tac_statements(body, new_symbol_table);
|
instruction := _elna_tac_statements(body, new_symbol_table);
|
||||||
elna_instruction_list_concatenate(first_instruction, instruction);
|
first_instruction := elna_instruction_list_concatenate(first_instruction, instruction);
|
||||||
|
|
||||||
(* Write the epilogue. *)
|
|
||||||
instruction := _elna_tac_instruction_create(ElnaTacOperator.ret);
|
|
||||||
elna_instruction_list_concatenate(first_instruction, instruction);
|
|
||||||
|
|
||||||
ElnaInstructionDeclaration_set_body(result, first_instruction);
|
ElnaInstructionDeclaration_set_body(result, first_instruction);
|
||||||
|
|
||||||
@@ -3663,6 +3669,7 @@ begin
|
|||||||
|
|
||||||
result^ := malloc(ElnaInstructionDeclaration_size());
|
result^ := malloc(ElnaInstructionDeclaration_size());
|
||||||
ElnaInstructionList_set_next(result^, 0);
|
ElnaInstructionList_set_next(result^, 0);
|
||||||
|
ElnaInstructionDeclaration_set_stack(result^, 0);
|
||||||
|
|
||||||
new_name := malloc(new_length);
|
new_name := malloc(new_length);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user