Implement add_ptr instruction

This commit is contained in:
2026-04-04 22:35:42 +02:00
parent 8514fb4fa0
commit 7c37f7f1c7
2 changed files with 74 additions and 19 deletions
+25 -6
View File
@@ -49,13 +49,13 @@ type
ElnaTypePointer = record
kind: ElnaTypeKind;
size: Word;
base: Word
base: ^ElnaType
end;
ElnaTypeArray = record
kind: ElnaTypeKind;
size: Word;
base: Word;
length: Word
length: ^ElnaType
end;
(* Abstract syntax tree nodes. *)
@@ -135,8 +135,8 @@ type
ElnaTreeBinaryExpression = record
kind: ElnaTreeKind;
type_decoration: ^ElnaType;
lhs: Word;
rhs: Word;
lhs: ^ElnaTreeExpression;
rhs: ^ElnaTreeExpression;
operator: Word
end;
ElnaTreeUnaryExpression = record
@@ -2232,9 +2232,30 @@ var
rhs_type: Word;
rhs_value: Word;
rhs_length: Word;
pointer_type: ^ElnaTypePointer;
begin
if parser_node^.kind <> ElnaTreeKind.binary_expression then
first_instruction := elna_tac_unary_expression(parser_node, symbol_table, operand_type, operand_value, operand_length)
elsif parser_node^.operator = ElnaLexerKind.pipe then
first_instruction := elna_tac_unary_expression(parser_node^.lhs, symbol_table, @lhs_type, @lhs_value, @lhs_length);
instruction := elna_tac_unary_expression(parser_node^.rhs, symbol_table, @rhs_type, @rhs_value, @rhs_length);
first_instruction := elna_instruction_list_concatenate(first_instruction, instruction);
elna_tac_generate_pseudo(operand_type, operand_value, operand_length, symbol_table);
pointer_type := parser_node^.lhs^.type_decoration;
instruction := elna_tac_instruction_create(ElnaTacOperator.multiply);
elna_tac_instruction_set_operand(instruction, 1, operand_type^, operand_value^, operand_length^);
elna_tac_instruction_set_operand(instruction, 2, rhs_type, rhs_value, rhs_length);
elna_tac_instruction_set_operand(instruction, 3, ElnaTacKind.immediate, pointer_type^.base^.size, 0);
first_instruction := elna_instruction_list_concatenate(first_instruction, instruction);
instruction := elna_tac_instruction_create(ElnaTacOperator.add);
elna_tac_instruction_set_operand(instruction, 1, operand_type^, operand_value^, operand_length^);
elna_tac_instruction_set_operand(instruction, 2, operand_type^, operand_value^, operand_length^);
elna_tac_instruction_set_operand(instruction, 3, lhs_type, lhs_value, lhs_length);
first_instruction := elna_instruction_list_concatenate(first_instruction, instruction)
else
first_instruction := elna_tac_unary_expression(parser_node^.lhs, symbol_table, @lhs_type, @lhs_value, @lhs_length);
@@ -2245,8 +2266,6 @@ begin
instruction := elna_tac_instruction_create(ElnaTacOperator.add)
elsif parser_node^.operator = ElnaLexerKind.minus then
instruction := elna_tac_instruction_create(ElnaTacOperator.subtract)
elsif parser_node^.operator = ElnaLexerKind.pipe then
instruction := elna_tac_instruction_create(ElnaTacOperator.add)
elsif parser_node^.operator = ElnaLexerKind.multiplication then
instruction := elna_tac_instruction_create(ElnaTacOperator.multiply)
elsif parser_node^.operator = ElnaLexerKind.and then