Rename RTL instructions to Risc-V versions

This commit is contained in:
2025-11-18 10:50:28 +01:00
parent 8da9241233
commit 15f716ce2c

View File

@@ -376,12 +376,12 @@ type
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
@@ -1135,7 +1135,7 @@ begin
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 elsif instruction_kind = ElnaTacOperator.start then
result := elna_rtl_instruction_create(ElnaRtlOperator.start) result := elna_rtl_instruction_create(ElnaRtlOperator.allocate_stack)
elsif instruction_kind = ElnaTacOperator.ret then elsif instruction_kind = ElnaTacOperator.ret then
result := elna_rtl_instruction_create(ElnaRtlOperator.ret) result := elna_rtl_instruction_create(ElnaRtlOperator.ret)
elsif instruction_kind = ElnaTacOperator.label then elsif instruction_kind = ElnaTacOperator.label then
@@ -1153,7 +1153,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 +1201,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 +1240,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,7 +1270,7 @@ 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 elsif instruction_kind = ElnaRtlOperator.allocate_stack then
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") _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 elsif instruction_kind = ElnaRtlOperator.ret then