Loading static variable address at a later, allocation stage
This commit is contained in:
+29
-25
@@ -935,7 +935,6 @@ begin
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
proc elna_rtl_operand_value(instructions: ^ElnaList, tac_operand: ^ElnaTacOperand, variable_map: ^ElnaSymbolTable,
|
proc elna_rtl_operand_value(instructions: ^ElnaList, tac_operand: ^ElnaTacOperand, variable_map: ^ElnaSymbolTable,
|
||||||
rtl_operand: ^ElnaRtlOperand) -> ^ElnaRtlInfo;
|
rtl_operand: ^ElnaRtlOperand) -> ^ElnaRtlInfo;
|
||||||
var
|
var
|
||||||
@@ -953,19 +952,7 @@ begin
|
|||||||
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);
|
||||||
if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then
|
if pseudo_symbol^.rtl_type^.kind = ElnaRtlTypeKind.byte_array then
|
||||||
elna_rtl_generate_pseudo(rtl_operand, 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, 0);
|
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data, 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, 0);
|
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
|
|
||||||
elna_list_append(instructions, instruction)
|
|
||||||
elsif pseudo_symbol^.rtl_type^.kind = ElnaRtlTypeKind.byte_array then
|
|
||||||
rtl_operand^.kind := ElnaRtlKind.pseudo_mem;
|
rtl_operand^.kind := ElnaRtlKind.pseudo_mem;
|
||||||
rtl_operand^.value := tac_operand^.value;
|
rtl_operand^.value := tac_operand^.value;
|
||||||
rtl_operand^.length := tac_operand^.length;
|
rtl_operand^.length := tac_operand^.length;
|
||||||
@@ -1632,14 +1619,16 @@ proc elna_alloc_move(instructions: ^ElnaList, instruction: ^ElnaRtlInstruction,
|
|||||||
variable_map: ^ElnaSymbolTable) -> ^ElnaRtlInstruction;
|
variable_map: ^ElnaSymbolTable) -> ^ElnaRtlInstruction;
|
||||||
var
|
var
|
||||||
load_instruction: ^ElnaRtlInstruction;
|
load_instruction: ^ElnaRtlInstruction;
|
||||||
|
source_operand: ElnaRtlOperand;
|
||||||
target_operand: ElnaRtlOperand;
|
target_operand: ElnaRtlOperand;
|
||||||
pseudo_symbol: ^ElnaRtlObjectInfo;
|
pseudo_symbol: ^ElnaRtlObjectInfo;
|
||||||
destination_pseudo: Word;
|
destination_pseudo: Word;
|
||||||
source_pseudo: Word;
|
source_pseudo: Word;
|
||||||
begin
|
begin
|
||||||
memcpy(@target_operand, @instruction^.operands[1], #size(ElnaRtlOperand));
|
memcpy(@target_operand, @instruction^.operands[1], #size(ElnaRtlOperand));
|
||||||
destination_pseudo := instruction^.operands[1].kind = ElnaRtlKind.pseudo;
|
memcpy(@source_operand, @instruction^.operands[2], #size(ElnaRtlOperand));
|
||||||
source_pseudo := instruction^.operands[2].kind = ElnaRtlKind.pseudo;
|
destination_pseudo := target_operand.kind = ElnaRtlKind.pseudo;
|
||||||
|
source_pseudo := source_operand.kind = ElnaRtlKind.pseudo;
|
||||||
|
|
||||||
if destination_pseudo & source_pseudo then
|
if destination_pseudo & source_pseudo then
|
||||||
pseudo_symbol := elna_symbol_table_lookup(variable_map, target_operand.value, target_operand.length);
|
pseudo_symbol := elna_symbol_table_lookup(variable_map, target_operand.value, target_operand.length);
|
||||||
@@ -1659,7 +1648,7 @@ begin
|
|||||||
elna_rtl_instruction_set_operand(load_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
|
elna_rtl_instruction_set_operand(load_instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
|
||||||
elna_rtl_instruction_set_operand(load_instruction, 2, ElnaRtlKind.memory, ElnaRtlRegister.t1, 0, 0)
|
elna_rtl_instruction_set_operand(load_instruction, 2, ElnaRtlKind.memory, ElnaRtlRegister.t1, 0, 0)
|
||||||
else
|
else
|
||||||
pseudo_symbol := elna_alloc_variable(instruction^.operands[1].value, instruction^.operands[1].length,
|
pseudo_symbol := elna_alloc_variable(target_operand.value, target_operand.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, 0);
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0);
|
||||||
@@ -1667,8 +1656,7 @@ begin
|
|||||||
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
|
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
|
||||||
end
|
end
|
||||||
elsif destination_pseudo then
|
elsif destination_pseudo then
|
||||||
pseudo_symbol := elna_symbol_table_lookup(variable_map,
|
pseudo_symbol := elna_symbol_table_lookup(variable_map, target_operand.value, target_operand.length);
|
||||||
instruction^.operands[1].value, instruction^.operands[1].length);
|
|
||||||
|
|
||||||
if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then
|
if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then
|
||||||
load_instruction := malloc(#size(ElnaRtlInstruction));
|
load_instruction := malloc(#size(ElnaRtlInstruction));
|
||||||
@@ -1685,14 +1673,13 @@ begin
|
|||||||
pseudo_symbol := elna_alloc_variable(target_operand.value, target_operand.length, variable_map);
|
pseudo_symbol := elna_alloc_variable(target_operand.value, target_operand.length, 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, source_operand.kind,
|
||||||
instruction^.operands[2].value, instruction^.operands[2].length, 0);
|
source_operand.value, source_operand.length, 0);
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
|
||||||
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
|
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter)
|
||||||
end
|
end
|
||||||
elsif source_pseudo then
|
elsif source_pseudo then
|
||||||
pseudo_symbol := elna_symbol_table_lookup(variable_map,
|
pseudo_symbol := elna_symbol_table_lookup(variable_map, source_operand.value, source_operand.length);
|
||||||
instruction^.operands[2].value, instruction^.operands[2].length);
|
|
||||||
|
|
||||||
if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then
|
if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then
|
||||||
load_instruction := malloc(#size(ElnaRtlInstruction));
|
load_instruction := malloc(#size(ElnaRtlInstruction));
|
||||||
@@ -1704,9 +1691,9 @@ begin
|
|||||||
|
|
||||||
load_instruction^.operator = ElnaRtlOperator.lw;
|
load_instruction^.operator = ElnaRtlOperator.lw;
|
||||||
elna_rtl_instruction_set_operand(load_instruction, 2, ElnaRtlKind.memory,
|
elna_rtl_instruction_set_operand(load_instruction, 2, ElnaRtlKind.memory,
|
||||||
instruction^.operands[1].value, instruction^.operands[1].length, 0)
|
target_operand.value, target_operand.length, 0)
|
||||||
else
|
else
|
||||||
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
|
pseudo_symbol := elna_alloc_variable(source_operand.value, source_operand.length,
|
||||||
variable_map);
|
variable_map);
|
||||||
instruction^.operator = ElnaRtlOperator.lw;
|
instruction^.operator = ElnaRtlOperator.lw;
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
|
||||||
@@ -1725,23 +1712,40 @@ proc elna_alloc_operand(instructions: ^ElnaList, instruction: ^ElnaRtlInstructio
|
|||||||
number: Word, target: ElnaRtlRegister, variable_map: ^ElnaSymbolTable) -> ^ElnaRtlInstruction;
|
number: Word, target: ElnaRtlRegister, variable_map: ^ElnaSymbolTable) -> ^ElnaRtlInstruction;
|
||||||
var
|
var
|
||||||
main_instruction: ^ElnaRtlInstruction;
|
main_instruction: ^ElnaRtlInstruction;
|
||||||
|
load_instruction: ^ElnaRtlInstruction;
|
||||||
pseudo_symbol: ^ElnaRtlObjectInfo;
|
pseudo_symbol: ^ElnaRtlObjectInfo;
|
||||||
begin
|
begin
|
||||||
if instruction^.operands[number].kind = ElnaRtlKind.pseudo then
|
if instruction^.operands[number].kind = ElnaRtlKind.pseudo then
|
||||||
pseudo_symbol := elna_alloc_variable(instruction^.operands[number].value,
|
pseudo_symbol := elna_alloc_variable(instruction^.operands[number].value,
|
||||||
instruction^.operands[number].length, variable_map);
|
instruction^.operands[number].length, variable_map);
|
||||||
main_instruction := malloc(#size(ElnaRtlInstruction));
|
main_instruction := malloc(#size(ElnaRtlInstruction));
|
||||||
|
|
||||||
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, 0);
|
elna_rtl_instruction_set_operand(main_instruction, number, ElnaRtlKind.register, target, 0, 0);
|
||||||
|
|
||||||
|
if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then
|
||||||
|
instruction^.operator := ElnaRtlOperator.la;
|
||||||
|
|
||||||
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data,
|
||||||
|
instruction^.operands[number].value, instruction^.operands[number].length, 0);
|
||||||
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, target, 0, 0);
|
||||||
|
elna_list_insert(instructions, instruction, main_instruction);
|
||||||
|
|
||||||
|
load_instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
|
|
||||||
|
elna_rtl_instruction_set_operand(load_instruction, 1, ElnaRtlKind.register, target, 0, 0);
|
||||||
|
elna_rtl_instruction_set_operand(load_instruction, 2, ElnaRtlKind.memory, target, 0, 0);
|
||||||
|
elna_list_insert(instructions, instruction, load_instruction)
|
||||||
|
else
|
||||||
instruction^.operator := ElnaRtlOperator.lw;
|
instruction^.operator := ElnaRtlOperator.lw;
|
||||||
|
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, target, 0, 0);
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, target, 0, 0);
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory,
|
||||||
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
|
ElnaRtlRegister.sp, 0, pseudo_symbol^.counter);
|
||||||
elna_list_insert(instructions, instruction, main_instruction);
|
elna_list_insert(instructions, instruction, main_instruction);
|
||||||
|
end;
|
||||||
instruction := main_instruction
|
instruction := main_instruction
|
||||||
end;
|
end;
|
||||||
return instruction
|
return instruction
|
||||||
|
|||||||
Reference in New Issue
Block a user