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