Let elna_tac_make_variable accept an ElnaTacOperand type
This commit is contained in:
@@ -47,12 +47,14 @@ task :convert do
|
||||
|
||||
proc f();
|
||||
var
|
||||
y: ElnaLocation;
|
||||
x: ElnaLocation;
|
||||
y: ^ElnaLocation;
|
||||
begin
|
||||
y.line := 1;
|
||||
y.column := 3;
|
||||
x := y;
|
||||
printf("# %i %i %i %i\\n\\0", x.line, x.column, y.line, y.column)
|
||||
y := malloc(#size(ElnaLocation));
|
||||
y^.line := 1;
|
||||
y^.column := 3;
|
||||
x := y^;
|
||||
printf("# %i %i %i %i\\n\\0", x.line, x.column, y^.line, y^.column)
|
||||
end;
|
||||
|
||||
begin
|
||||
@@ -61,7 +63,6 @@ task :convert do
|
||||
elsif line.start_with?('var') && !seen_global_var
|
||||
current_stage << <<~FUN
|
||||
var
|
||||
x: ElnaLocation;
|
||||
FUN
|
||||
else
|
||||
current_stage << line
|
||||
|
||||
+17
-17
@@ -858,7 +858,7 @@ begin
|
||||
existing^.next := new
|
||||
end;
|
||||
|
||||
proc elna_tac_make_variable(operand_type: Word, operand_value: Word, operand_length: Word, symbol_table: ^ElnaSymbolTable);
|
||||
proc elna_tac_make_variable(operand: ^ElnaTacOperand, symbol_table: ^ElnaSymbolTable);
|
||||
var
|
||||
buffer: Word;
|
||||
temporary_info: ^ElnaSymbolTemporaryInfo;
|
||||
@@ -868,12 +868,12 @@ begin
|
||||
|
||||
sprintf(buffer, "$a%i\0", pseudo_counter);
|
||||
|
||||
operand_type^ := ElnaTacKind.variable;
|
||||
operand_value^ := buffer;
|
||||
operand_length^ := strlen(buffer);
|
||||
operand^.kind := ElnaTacKind.variable;
|
||||
operand^.value := buffer;
|
||||
operand^.length := strlen(buffer);
|
||||
|
||||
temporary_info := temporary_info_create(1, word_type);
|
||||
elna_symbol_table_enter(symbol_table, buffer, operand_length^, temporary_info)
|
||||
elna_symbol_table_enter(symbol_table, buffer, operand^.length, temporary_info)
|
||||
end;
|
||||
|
||||
proc elna_tac_instruction_set_operand(this: ^ElnaTacInstruction, n: Word, operand_type: Word, operand_value: Word, operand_length: Word);
|
||||
@@ -2235,7 +2235,7 @@ var
|
||||
begin
|
||||
offset := _add_string(string_literal_node^.value);
|
||||
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.get_address);
|
||||
elna_tac_instruction_set_operand(instruction, 1, ElnaTacKind.variable, "strings", 7);
|
||||
@@ -2454,31 +2454,31 @@ begin
|
||||
elna_tac_designator(instructions, unary_operand, symbol_table, @operand_result, @base);
|
||||
|
||||
if operator = '@' then
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
elna_tac_copy_address(instructions, @operand_result, @base, operand)
|
||||
elsif operator = '-' then
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.negate);
|
||||
elna_tac_instruction_set_operand(instruction, 1, base.kind, base.value, base.length);
|
||||
elna_tac_instruction_set_operand(instruction, 2, operand^.kind, operand^.value, operand^.length);
|
||||
elna_list_append(instructions, instruction)
|
||||
elsif operator = '~' then
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.complement);
|
||||
elna_tac_instruction_set_operand(instruction, 1, base.kind, base.value, base.length);
|
||||
elna_tac_instruction_set_operand(instruction, 2, operand^.kind, operand^.value, operand^.length);
|
||||
elna_list_append(instructions, instruction)
|
||||
elsif operand_result.kind = ElnaTacOperandType.dereferenced_pointer then
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.load);
|
||||
elna_tac_instruction_set_operand(instruction, 1, base.kind, base.value, base.length);
|
||||
elna_tac_instruction_set_operand(instruction, 2, operand^.kind, operand^.value, operand^.length);
|
||||
elna_list_append(instructions, instruction)
|
||||
elsif operand_result.kind = ElnaTacOperandType.sub_object then
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.copy_from_offset);
|
||||
elna_tac_instruction_set_operand(instruction, 1, base.kind, base.value, base.length);
|
||||
@@ -2569,7 +2569,7 @@ begin
|
||||
pointer_type := parser_node^.type_decoration;
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.add_ptr);
|
||||
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
elna_tac_instruction_set_operand(instruction, 1, lhs^.kind, lhs^.value, lhs^.length);
|
||||
elna_tac_instruction_set_operand(instruction, 2, rhs^.kind, rhs^.value, rhs^.length);
|
||||
elna_tac_instruction_set_operand(instruction, 3, ElnaTacKind.constant, pointer_type^.base^.size, 0);
|
||||
@@ -2608,7 +2608,7 @@ var
|
||||
begin
|
||||
instruction := elna_tac_instruction_create(operator);
|
||||
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
elna_tac_instruction_set_operand(instruction, 1, lhs^.kind, lhs^.value, lhs^.length);
|
||||
elna_tac_instruction_set_operand(instruction, 2, rhs^.kind, rhs^.value, rhs^.length);
|
||||
elna_tac_instruction_set_operand(instruction, 3, operand^.kind, operand^.value, operand^.length);
|
||||
@@ -2727,7 +2727,7 @@ begin
|
||||
parsed_expression := parsed_call^.callee;
|
||||
arguments_operand := malloc(parsed_call^.count * #size(ElnaTacOperand));
|
||||
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
call_instruction := elna_tac_instruction_create(ElnaTacOperator.proc_call);
|
||||
elna_tac_instruction_set_operand(call_instruction, 1, ElnaTacKind.label, parsed_expression^.name, parsed_expression^.length);
|
||||
@@ -2971,7 +2971,7 @@ begin
|
||||
end;
|
||||
|
||||
if operand_result^.kind = ElnaTacOperandType.dereferenced_pointer then
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.add);
|
||||
elna_tac_instruction_set_operand(instruction, 1, base.kind, base.value, base.length);
|
||||
@@ -3004,7 +3004,7 @@ begin
|
||||
element_type := aggregate_type^.base;
|
||||
|
||||
elna_tac_binary_expression(instructions, array_access_expression^.index, symbol_table, @inter_operand);
|
||||
elna_tac_make_variable(@index_operand.kind, @index_operand.value, @index_operand.length, symbol_table);
|
||||
elna_tac_make_variable(@index_operand, symbol_table);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.subtract);
|
||||
elna_tac_instruction_set_operand(instruction, 1, inter_operand.kind, inter_operand.value, inter_operand.length);
|
||||
@@ -3014,7 +3014,7 @@ begin
|
||||
|
||||
elna_tac_designator(instructions, array_access_expression^.array,
|
||||
symbol_table, @operand_result, @inter_operand);
|
||||
elna_tac_make_variable(@operand^.kind, @operand^.value, @operand^.length, symbol_table);
|
||||
elna_tac_make_variable(operand, symbol_table);
|
||||
elna_tac_copy_address(instructions, @operand_result, @inter_operand, operand);
|
||||
|
||||
instruction := elna_tac_instruction_create(ElnaTacOperator.add_ptr);
|
||||
|
||||
Reference in New Issue
Block a user