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
);
ElnaRtlOperator = (
load_immediate,
load_address,
li,
la,
add,
add_immediate,
load_word,
store_word,
addi,
lw,
sw,
jal,
move,
sub,
@@ -394,13 +394,13 @@ type
seqz,
snez,
slt,
xor_immediate,
xori,
neg,
not,
jump,
beqz,
label,
start,
allocate_stack,
ret
);
ElnaTacOperand = (temporary, immediate, symbol, stack);
@@ -837,19 +837,19 @@ begin
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, operand_number);
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, 2, ElnaRtlOperand.immediate, operand_value, operand_length)
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, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value)
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, 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, 2, ElnaRtlOperand.offset, into, 0);
@@ -875,11 +875,11 @@ begin
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, operand_number);
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, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value)
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, 2, ElnaRtlOperand.symbol, operand_value, operand_length)
end;
@@ -991,7 +991,7 @@ begin
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.sp, 0);
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, operand_value, 0)
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, 2, result)
@@ -1007,10 +1007,10 @@ begin
operand_type := _elna_tac_instruction_get_operand_type(tac_instruction, 2);
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);
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^, 2, ElnaRtlOperand.offset, operand_value, 0);
@@ -1018,7 +1018,7 @@ begin
elna_rtl_instruction_set_operand(result, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value);
ElnaInstructionList_set_next(result, next_instruction^)
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);
operand_value := _elna_tac_instruction_get_operand_value(tac_instruction, 2);
@@ -1026,7 +1026,7 @@ begin
end
elsif instruction_kind = ElnaTacOperator.store_word then
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;
operands := ElnaInstructionList_get_next(result);
@@ -1087,7 +1087,7 @@ begin
ElnaInstructionList_set_next(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_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.t2, 0);
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, 1, 0);
@@ -1095,7 +1095,7 @@ begin
next_instruction^ := result;
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
operands := elna_rtl_binary_operands(tac_instruction, next_instruction);
intermediate_instruction := elna_rtl_instruction_create(ElnaRtlOperator.slt);
@@ -1106,7 +1106,7 @@ begin
ElnaInstructionList_set_next(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_instruction_set_operand(result, 2, ElnaRtlOperand.register, ElnaRtlRegister.t2, 0);
elna_rtl_instruction_set_operand(result, 3, ElnaRtlOperand.immediate, 1, 0);
@@ -1114,7 +1114,7 @@ begin
next_instruction^ := result;
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
result := elna_rtl_binary_equality(tac_instruction, ElnaRtlOperator.seqz, next_instruction)
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, 2, result)
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
result := elna_rtl_instruction_create(ElnaRtlOperator.ret)
elsif instruction_kind = ElnaTacOperator.label then
@@ -1153,7 +1153,7 @@ begin
result := operands;
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^, 2, ElnaRtlOperand.offset, ElnaRtlRegister.sp, operand_value);
@@ -1201,22 +1201,22 @@ proc _elna_writer_instruction_name(instruction_kind: Word);
var
argument_count: Word;
begin
if instruction_kind = ElnaRtlOperator.load_immediate then
if instruction_kind = ElnaRtlOperator.li then
argument_count := 2;
_write_s("\tli", 3)
elsif instruction_kind = ElnaRtlOperator.load_address then
elsif instruction_kind = ElnaRtlOperator.la then
argument_count := 2;
_write_s("\tla", 3)
elsif instruction_kind = ElnaRtlOperator.add then
argument_count := 3;
_write_s("\tadd", 4)
elsif instruction_kind = ElnaRtlOperator.add_immediate then
elsif instruction_kind = ElnaRtlOperator.addi then
argument_count := 3;
_write_s("\taddi", 5)
elsif instruction_kind = ElnaRtlOperator.load_word then
elsif instruction_kind = ElnaRtlOperator.lw then
argument_count := 2;
_write_s("\tlw", 3)
elsif instruction_kind = ElnaRtlOperator.store_word then
elsif instruction_kind = ElnaRtlOperator.sw then
argument_count := 2;
_write_s("\tsw", 3)
elsif instruction_kind = ElnaRtlOperator.jal then
@@ -1240,7 +1240,7 @@ begin
elsif instruction_kind = ElnaRtlOperator._xor then
argument_count := 3;
_write_s("\txor", 4)
elsif instruction_kind = ElnaRtlOperator.xor_immediate then
elsif instruction_kind = ElnaRtlOperator.xori then
argument_count := 3;
_write_s("\txori", 5)
elsif instruction_kind = ElnaRtlOperator._or then
@@ -1270,7 +1270,7 @@ begin
elsif instruction_kind = ElnaRtlOperator.beqz then
argument_count := 2;
_write_s("\tbeqz", 5)
elsif instruction_kind = ElnaRtlOperator.start then
elsif instruction_kind = ElnaRtlOperator.allocate_stack then
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