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