Add offset field to the RTL operand

This commit is contained in:
2026-03-25 14:39:23 +01:00
parent 6256f66c34
commit 077dcf62a9
+92 -81
View File
@@ -560,11 +560,12 @@ type
ret,
nop
);
ElnaRtlKind = (register, immediate, symbol, pseudo, offset, pseudo_mem);
ElnaRtlKind = (register, immediate, symbol, pseudo, memory, pseudo_mem);
ElnaRtlOperand = record
kind: ElnaRtlKind;
value: Word;
length: Word
length: Word;
offset: Word
end;
ElnaRtlStaticVariable = record
next: Word;
@@ -882,11 +883,13 @@ begin
return result
end;
proc elna_rtl_instruction_set_operand(this: ^ElnaRtlInstruction, n: Word, operand_type: Word, operand_value: Word, operand_length: Word);
proc elna_rtl_instruction_set_operand(this: ^ElnaRtlInstruction, n: Word, operand_type: Word,
operand_value: Word, operand_length: Word, operand_offset: Word);
begin
this^.operands[n].kind := operand_type;
this^.operands[n].value := operand_value;
this^.operands[n].length := operand_length
this^.operands[n].length := operand_length;
this^.operands[n].offset := operand_offset
end;
(**
@@ -900,24 +903,24 @@ var
begin
if operand^.kind = ElnaTacKind.constant then
instruction := elna_rtl_instruction_create(ElnaRtlOperator.li);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.immediate, operand^.value, operand^.length);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.immediate, operand^.value, operand^.length, 0);
elna_list_append(instructions, instruction)
elsif operand^.kind = ElnaTacKind.variable then
pseudo_symbol := elna_symbol_table_lookup(variable_map, operand^.value, operand^.length);
if pseudo_symbol = nil then
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol, operand^.value, operand^.length);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol, operand^.value, operand^.length, 0);
elna_list_append(instructions, instruction);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, into, 0)
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory, into, 0, 0)
else
instruction := elna_rtl_instruction_create(ElnaRtlOperator.mv);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo, operand^.value, operand^.length)
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo, operand^.value, operand^.length, 0)
end;
elna_list_append(instructions, instruction)
end
@@ -933,8 +936,8 @@ begin
elna_rtl_generate_pseudo(@rtl_operand^.value, @rtl_operand^.length, variable_map);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.li);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.immediate, tac_operand^.value, tac_operand^.length);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.immediate, tac_operand^.value, tac_operand^.length, 0);
elna_list_append(instructions, instruction)
elsif tac_operand^.kind = ElnaTacKind.variable then
pseudo_symbol := elna_symbol_table_lookup(variable_map, tac_operand^.value, tac_operand^.length);
@@ -942,13 +945,13 @@ begin
elna_rtl_generate_pseudo(@rtl_operand^.value, @rtl_operand^.length, variable_map);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol, tac_operand^.value, tac_operand^.length);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol, tac_operand^.value, tac_operand^.length, 0);
elna_list_append(instructions, instruction);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length);
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
elna_list_append(instructions, instruction)
else
rtl_operand^.value := tac_operand^.value;
@@ -965,13 +968,13 @@ var
begin
result := elna_rtl_instruction_create(operation);
elna_rtl_instruction_set_operand(result, 1, ElnaRtlKind.pseudo,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_rtl_operand_value(instructions, @tac_instruction^.operands[2], variable_map, @rtl_operand);
elna_rtl_instruction_set_operand(result, 2, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(result, 2, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_rtl_operand_value(instructions, @tac_instruction^.operands[3], variable_map, @rtl_operand);
elna_rtl_instruction_set_operand(result, 3, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(result, 3, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_list_append(instructions, result);
return result
@@ -987,8 +990,8 @@ begin
target_operand := @instruction^.operands[1];
instruction := elna_rtl_instruction_create(instruction_kind);
elna_rtl_instruction_set_operand(instruction, 1, target_operand^.kind, target_operand^.value, target_operand^.length);
elna_rtl_instruction_set_operand(instruction, 2, target_operand^.kind, target_operand^.value, target_operand^.length);
elna_rtl_instruction_set_operand(instruction, 1, target_operand^.kind, target_operand^.value, target_operand^.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, target_operand^.kind, target_operand^.value, target_operand^.length, 0);
elna_list_append(instructions, instruction)
end;
@@ -1000,13 +1003,13 @@ var
begin
slt_instruction := elna_rtl_instruction_create(ElnaRtlOperator.slt);
elna_rtl_instruction_set_operand(slt_instruction, 1, ElnaRtlKind.pseudo,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_rtl_operand_value(instructions, @tac_instruction^.operands[2], variable_map, @rtl_operand);
elna_rtl_instruction_set_operand(slt_instruction, lhs, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(slt_instruction, lhs, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_rtl_operand_value(instructions, @tac_instruction^.operands[3], variable_map, @rtl_operand);
elna_rtl_instruction_set_operand(slt_instruction, rhs, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(slt_instruction, rhs, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_list_append(instructions, slt_instruction);
return slt_instruction
@@ -1023,10 +1026,10 @@ begin
xor_instruction := elna_rtl_instruction_create(ElnaRtlOperator.xori);
elna_rtl_instruction_set_operand(xor_instruction, 1, slt_instruction^.operands[1].kind,
slt_instruction^.operands[1].value, slt_instruction^.operands[1].length);
slt_instruction^.operands[1].value, slt_instruction^.operands[1].length, 0);
elna_rtl_instruction_set_operand(xor_instruction, 2, slt_instruction^.operands[1].kind,
slt_instruction^.operands[1].value, slt_instruction^.operands[1].length);
elna_rtl_instruction_set_operand(xor_instruction, 3, ElnaRtlKind.immediate, 1, 0);
slt_instruction^.operands[1].value, slt_instruction^.operands[1].length, 0);
elna_rtl_instruction_set_operand(xor_instruction, 3, ElnaRtlKind.immediate, 1, 0, 0);
elna_list_append(instructions, xor_instruction)
end;
@@ -1041,14 +1044,14 @@ begin
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.pseudo,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
if pseudo_symbol = nil then
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol,
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length)
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0)
else
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo,
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length)
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0)
end;
elna_list_append(instructions, instruction)
end;
@@ -1061,9 +1064,9 @@ var
begin
instruction := elna_rtl_instruction_create(condition);
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol,
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length);
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
elna_list_append(instructions, instruction)
end;
@@ -1077,9 +1080,9 @@ begin
instruction := elna_rtl_instruction_create(rtl_operator);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.pseudo,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_list_append(instructions, instruction)
end;
@@ -1108,13 +1111,13 @@ begin
end;
instruction := elna_rtl_instruction_create(ElnaRtlOperator.jal);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.symbol,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_list_append(instructions, instruction);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.mv);
elna_rtl_instruction_set_operand(instruction, 1, tac_instruction^.operands[3].kind,
tac_instruction^.operands[3].value, tac_instruction^.operands[3].length);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, ElnaRtlRegister.a0, 0);
tac_instruction^.operands[3].value, tac_instruction^.operands[3].length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, ElnaRtlRegister.a0, 0, 0);
elna_list_append(instructions, instruction)
end;
@@ -1126,9 +1129,9 @@ begin
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.sw);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo,
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length);
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
elna_list_append(instructions, instruction)
end;
@@ -1140,9 +1143,9 @@ begin
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand.kind, rtl_operand.value, rtl_operand.length);
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.pseudo,
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length);
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
elna_list_append(instructions, instruction)
end;
@@ -1163,20 +1166,20 @@ begin
elna_rtl_generate_pseudo(@target_operand.value, @target_operand.length, variable_map);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
elna_rtl_instruction_set_operand(instruction, 1, target_operand.kind, target_operand.value, target_operand.length);
elna_rtl_instruction_set_operand(instruction, 1, target_operand.kind, target_operand.value, target_operand.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_list_append(instructions, instruction);
instruction := elna_rtl_instruction_create(ElnaRtlOperator.sw);
elna_rtl_instruction_set_operand(instruction, 1, source_operand.kind, source_operand.value, source_operand.length);
elna_rtl_instruction_set_operand(instruction, 2, target_operand.kind, target_operand.value, target_operand.length);
elna_rtl_instruction_set_operand(instruction, 1, source_operand.kind, source_operand.value, source_operand.length, 0);
elna_rtl_instruction_set_operand(instruction, 2, target_operand.kind, target_operand.value, target_operand.length, 0);
elna_list_append(instructions, instruction)
else
instruction := elna_rtl_instruction_create(ElnaRtlOperator.mv);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.pseudo,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
elna_rtl_instruction_set_operand(instruction, 2, source_operand.kind, source_operand.value, source_operand.length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_rtl_instruction_set_operand(instruction, 2, source_operand.kind, source_operand.value, source_operand.length, 0);
elna_list_append(instructions, instruction);
end
end
@@ -1230,7 +1233,7 @@ begin
elsif tac_instruction^.operator = ElnaTacOperator.jump then
instruction := elna_rtl_instruction_create(ElnaRtlOperator.j);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.symbol,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_list_append(instructions, instruction)
elsif tac_instruction^.operator = ElnaTacOperator.jump_if_zero then
elna_rtl_conditional_jump(instructions, tac_instruction, ElnaRtlOperator.beqz, variable_map)
@@ -1241,7 +1244,7 @@ begin
elsif tac_instruction^.operator = ElnaTacOperator.label then
instruction := elna_rtl_instruction_create(ElnaRtlOperator.label);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.symbol,
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length);
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
elna_list_append(instructions, instruction)
elsif tac_instruction^.operator = ElnaTacOperator.copy then
elna_rtl_copy(instructions, tac_instruction, variable_map)
@@ -1359,8 +1362,8 @@ begin
_write_c(' ');
if operand_type = ElnaRtlKind.register then
elna_riscv_register(instruction^.operands[n].value)
elsif operand_type = ElnaRtlKind.offset then
_write_i(instruction^.operands[n].length);
elsif operand_type = ElnaRtlKind.memory then
_write_i(instruction^.operands[n].offset);
_write_c('(');
elna_riscv_register(instruction^.operands[n].value);
_write_c(')')
@@ -1418,10 +1421,11 @@ begin
pseudo_symbol := elna_alloc_variable(instruction^.operands[1].value, instruction^.operands[1].length,
variable_map);
elna_rtl_instruction_set_operand(store_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(store_instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter);
elna_rtl_instruction_set_operand(store_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_rtl_instruction_set_operand(store_instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_list_insert(instructions, instruction, store_instruction);
instruction := store_instruction
end;
@@ -1437,8 +1441,8 @@ begin
variable_map);
instruction^.operator := ElnaRtlOperator.addi;
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, ElnaRtlRegister.sp, 0);
elna_rtl_instruction_set_operand(instruction, 3, ElnaRtlKind.immediate, pseudo_symbol^.counter, 0)
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, ElnaRtlRegister.sp, 0, 0);
elna_rtl_instruction_set_operand(instruction, 3, ElnaRtlKind.immediate, pseudo_symbol^.counter, 0, 0)
end;
if instruction^.operands[1].kind = ElnaRtlKind.pseudo then
elna_alloc_operation_target(instructions, instruction, variable_map)
@@ -1455,15 +1459,16 @@ begin
if instruction^.operands[2].kind = ElnaRtlKind.pseudo then
store_instruction := elna_rtl_instruction_create(ElnaRtlOperator.sw);
elna_rtl_instruction_set_operand(store_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(store_instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.t1, 0);
elna_rtl_instruction_set_operand(store_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_rtl_instruction_set_operand(store_instruction, 2, ElnaRtlKind.memory, ElnaRtlRegister.t1, 0, 0);
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
variable_map);
instruction^.operator := ElnaRtlOperator.lw;
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t1, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t1, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
elna_list_insert(instructions, instruction, store_instruction);
instruction := store_instruction
end;
@@ -1482,12 +1487,13 @@ begin
memcpy(new_instruction, instruction, #size(ElnaRtlInstruction));
new_instruction^.next := nil;
elna_rtl_instruction_set_operand(new_instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(new_instruction, 2, ElnaRtlKind.memory, ElnaRtlRegister.t0, 0, 0);
instruction^.operator := ElnaRtlOperator.lw;
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
elna_list_insert(instructions, instruction, new_instruction);
instruction := new_instruction
end;
@@ -1509,21 +1515,24 @@ begin
pseudo_symbol := elna_alloc_variable(instruction^.operands[1].value, instruction^.operands[1].length,
variable_map);
instruction^.operator = ElnaRtlOperator.sw;
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter)
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
elsif destination_pseudo then
pseudo_symbol := elna_alloc_variable(instruction^.operands[1].value, instruction^.operands[1].length,
variable_map);
instruction^.operator = ElnaRtlOperator.sw;
elna_rtl_instruction_set_operand(instruction, 1, instruction^.operands[2].kind,
instruction^.operands[2].value, instruction^.operands[2].length);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter)
instruction^.operands[2].value, instruction^.operands[2].length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
elsif source_pseudo then
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
variable_map);
instruction^.operator = ElnaRtlOperator.lw;
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter)
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
end;
return instruction
end;
@@ -1546,12 +1555,13 @@ begin
memcpy(main_instruction, instruction, #size(ElnaRtlInstruction));
main_instruction^.next := nil;
elna_rtl_instruction_set_operand(main_instruction, number, ElnaRtlKind.register, target, 0);
elna_rtl_instruction_set_operand(main_instruction, number, ElnaRtlKind.register, target, 0, 0);
instruction^.operator := ElnaRtlOperator.lw;
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, target, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, target, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
elna_list_insert(instructions, instruction, main_instruction);
instruction := main_instruction
end;
@@ -1611,16 +1621,17 @@ begin
elsif instruction^.operator = ElnaRtlOperator.beqz then
if instruction^.operands[1].kind = ElnaRtlKind.pseudo then
new_instruction := elna_rtl_instruction_create(ElnaRtlOperator.beqz);
elna_rtl_instruction_set_operand(new_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(new_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_rtl_instruction_set_operand(new_instruction, 2, instruction^.operands[2].kind,
instruction^.operands[2].value, instruction^.operands[2].length);
instruction^.operands[2].value, instruction^.operands[2].length, 0);
pseudo_symbol := elna_alloc_variable(instruction^.operands[1].value, instruction^.operands[1].length,
variable_map);
instruction^.operator := ElnaRtlOperator.lw;
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.offset, ElnaRtlRegister.sp, pseudo_symbol^.counter);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
elna_list_insert(instructions, instruction, new_instruction)
end
@@ -1733,11 +1744,11 @@ begin
elna_alloc_instructions(@rtl_declaration^.body, rtl_declaration^.variable_map);
stack_instruction := elna_rtl_instruction_create(ElnaRtlOperator.allocate_stack);
elna_rtl_instruction_set_operand(stack_instruction, 1, ElnaRtlKind.immediate, temporary_variable_counter, 0);
elna_rtl_instruction_set_operand(stack_instruction, 1, ElnaRtlKind.immediate, temporary_variable_counter, 0, 0);
elna_list_prepend(@rtl_declaration^.body, stack_instruction);
stack_instruction := elna_rtl_instruction_create(ElnaRtlOperator.ret);
elna_rtl_instruction_set_operand(stack_instruction, 1, ElnaRtlKind.immediate, temporary_variable_counter, 0);
elna_rtl_instruction_set_operand(stack_instruction, 1, ElnaRtlKind.immediate, temporary_variable_counter, 0, 0);
elna_list_append(@rtl_declaration^.body, stack_instruction);
@@ -3565,8 +3576,8 @@ begin
parameters := parameters + 4;
instruction := elna_rtl_instruction_create(ElnaRtlOperator.mv);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.pseudo, parameter_name, name_length);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, 11 + parameter_index, 0);
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.pseudo, parameter_name, name_length, 0);
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.register, 11 + parameter_index, 0, 0);
elna_list_append(instructions, instruction);
parameter_index := parameter_index + 1;