diff --git a/boot/stage21/cl.elna b/boot/stage21/cl.elna index c6d7837..3e9c47a 100644 --- a/boot/stage21/cl.elna +++ b/boot/stage21/cl.elna @@ -935,7 +935,6 @@ begin end end; - proc elna_rtl_operand_value(instructions: ^ElnaList, tac_operand: ^ElnaTacOperand, variable_map: ^ElnaSymbolTable, rtl_operand: ^ElnaRtlOperand) -> ^ElnaRtlInfo; var @@ -953,19 +952,7 @@ begin 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); - if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info 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 + if pseudo_symbol^.rtl_type^.kind = ElnaRtlTypeKind.byte_array then rtl_operand^.kind := ElnaRtlKind.pseudo_mem; rtl_operand^.value := tac_operand^.value; rtl_operand^.length := tac_operand^.length; @@ -1632,14 +1619,16 @@ proc elna_alloc_move(instructions: ^ElnaList, instruction: ^ElnaRtlInstruction, variable_map: ^ElnaSymbolTable) -> ^ElnaRtlInstruction; var load_instruction: ^ElnaRtlInstruction; + source_operand: ElnaRtlOperand; target_operand: ElnaRtlOperand; pseudo_symbol: ^ElnaRtlObjectInfo; destination_pseudo: Word; source_pseudo: Word; begin memcpy(@target_operand, @instruction^.operands[1], #size(ElnaRtlOperand)); - destination_pseudo := instruction^.operands[1].kind = ElnaRtlKind.pseudo; - source_pseudo := instruction^.operands[2].kind = ElnaRtlKind.pseudo; + memcpy(@source_operand, @instruction^.operands[2], #size(ElnaRtlOperand)); + destination_pseudo := target_operand.kind = ElnaRtlKind.pseudo; + source_pseudo := source_operand.kind = ElnaRtlKind.pseudo; if destination_pseudo & source_pseudo then 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, 2, ElnaRtlKind.memory, ElnaRtlRegister.t1, 0, 0) 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); instruction^.operator = ElnaRtlOperator.sw; elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, ElnaRtlRegister.t0, 0, 0); @@ -1667,8 +1656,7 @@ begin ElnaRtlRegister.sp, 0, pseudo_symbol^.counter) end elsif destination_pseudo then - pseudo_symbol := elna_symbol_table_lookup(variable_map, - instruction^.operands[1].value, instruction^.operands[1].length); + pseudo_symbol := elna_symbol_table_lookup(variable_map, target_operand.value, target_operand.length); if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then load_instruction := malloc(#size(ElnaRtlInstruction)); @@ -1685,14 +1673,13 @@ begin pseudo_symbol := elna_alloc_variable(target_operand.value, target_operand.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, 0); + elna_rtl_instruction_set_operand(instruction, 1, source_operand.kind, + source_operand.value, source_operand.length, 0); elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.memory, ElnaRtlRegister.sp, 0, pseudo_symbol^.counter) end elsif source_pseudo then - pseudo_symbol := elna_symbol_table_lookup(variable_map, - instruction^.operands[2].value, instruction^.operands[2].length); + pseudo_symbol := elna_symbol_table_lookup(variable_map, source_operand.value, source_operand.length); if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then load_instruction := malloc(#size(ElnaRtlInstruction)); @@ -1704,9 +1691,9 @@ begin load_instruction^.operator = ElnaRtlOperator.lw; 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 - 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); instruction^.operator = ElnaRtlOperator.lw; 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; var main_instruction: ^ElnaRtlInstruction; + load_instruction: ^ElnaRtlInstruction; pseudo_symbol: ^ElnaRtlObjectInfo; begin if instruction^.operands[number].kind = ElnaRtlKind.pseudo then pseudo_symbol := elna_alloc_variable(instruction^.operands[number].value, instruction^.operands[number].length, variable_map); main_instruction := malloc(#size(ElnaRtlInstruction)); + memcpy(main_instruction, instruction, #size(ElnaRtlInstruction)); main_instruction^.next := nil; elna_rtl_instruction_set_operand(main_instruction, number, ElnaRtlKind.register, target, 0, 0); - instruction^.operator := ElnaRtlOperator.lw; + if pseudo_symbol^.kind = ElnaRtlInfoKind.static_info then + instruction^.operator := ElnaRtlOperator.la; - 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); + 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; + + 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); + end; instruction := main_instruction end; return instruction