Rename RTL symbol to data
This commit is contained in:
33
Rakefile
33
Rakefile
@@ -36,22 +36,25 @@ end
|
|||||||
|
|
||||||
desc 'Convert previous stage language into the current stage language'
|
desc 'Convert previous stage language into the current stage language'
|
||||||
task :convert do
|
task :convert do
|
||||||
File.open('boot/stage21/cl.elna', 'w') do |current_stage|
|
File.open('boot/stage22/cl.elna', 'w') do |current_stage|
|
||||||
File.readlines('boot/stage20/cl.elna').each do |line|
|
seen_proc = false
|
||||||
|
File.readlines('boot/stage21/cl.elna').each do |line|
|
||||||
|
seen_proc = true if line.start_with? 'proc'
|
||||||
|
seen_proc = false if line.start_with? 'end'
|
||||||
|
if line.start_with?('begin') && !seen_proc
|
||||||
|
current_stage << <<~FUN
|
||||||
|
|
||||||
|
proc f();
|
||||||
|
var
|
||||||
|
x: ElnaLocation;
|
||||||
|
y: ElnaLocation;
|
||||||
|
begin
|
||||||
|
x := y;
|
||||||
|
end;
|
||||||
|
|
||||||
|
FUN
|
||||||
|
end
|
||||||
current_stage << line
|
current_stage << line
|
||||||
end
|
end
|
||||||
# current_stage << <<~FUN
|
|
||||||
#
|
|
||||||
# proc f(m: ElnaInstructionModule);
|
|
||||||
# begin
|
|
||||||
# end;
|
|
||||||
#
|
|
||||||
# proc g();
|
|
||||||
# var
|
|
||||||
# x: ElnaInstructionModule;
|
|
||||||
# begin
|
|
||||||
# f(x)
|
|
||||||
# end;
|
|
||||||
# FUN
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -566,7 +566,7 @@ type
|
|||||||
ret,
|
ret,
|
||||||
nop
|
nop
|
||||||
);
|
);
|
||||||
ElnaRtlKind = (register, immediate, symbol, pseudo, memory, pseudo_mem);
|
ElnaRtlKind = (register, immediate, data, pseudo, memory, pseudo_mem);
|
||||||
ElnaRtlOperand = record
|
ElnaRtlOperand = record
|
||||||
kind: ElnaRtlKind;
|
kind: ElnaRtlKind;
|
||||||
value: Word;
|
value: Word;
|
||||||
@@ -917,7 +917,7 @@ begin
|
|||||||
if pseudo_symbol = nil then
|
if pseudo_symbol = nil then
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0, 0);
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.register, into, 0, 0);
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol, operand^.value, operand^.length, 0);
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data, operand^.value, operand^.length, 0);
|
||||||
elna_list_append(instructions, instruction);
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
||||||
@@ -932,11 +932,14 @@ begin
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_rtl_operand_value(instructions: ^ElnaList, tac_operand: ^ElnaTacOperand, variable_map: ^ElnaSymbolTable, rtl_operand: ^ElnaRtlOperand);
|
proc elna_rtl_operand_value(instructions: ^ElnaList, tac_operand: ^ElnaTacOperand, variable_map: ^ElnaSymbolTable,
|
||||||
|
rtl_operand: ^ElnaRtlOperand) -> ^ElnaRtlInfo;
|
||||||
var
|
var
|
||||||
instruction: ^ElnaRtlInstruction;
|
instruction: ^ElnaRtlInstruction;
|
||||||
pseudo_symbol: ^ElnaRtlInfo;
|
pseudo_symbol: ^ElnaRtlInfo;
|
||||||
begin
|
begin
|
||||||
|
pseudo_symbol := nil;
|
||||||
|
|
||||||
if tac_operand^.kind = ElnaTacKind.constant then
|
if tac_operand^.kind = ElnaTacKind.constant then
|
||||||
elna_rtl_generate_pseudo(rtl_operand, variable_map);
|
elna_rtl_generate_pseudo(rtl_operand, variable_map);
|
||||||
|
|
||||||
@@ -951,19 +954,26 @@ begin
|
|||||||
|
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
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, 1, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol, tac_operand^.value, tac_operand^.length, 0);
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data, tac_operand^.value, tac_operand^.length, 0);
|
||||||
elna_list_append(instructions, instruction);
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.lw);
|
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, 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_rtl_instruction_set_operand(instruction, 2, rtl_operand^.kind, rtl_operand^.value, rtl_operand^.length, 0);
|
||||||
elna_list_append(instructions, instruction)
|
elna_list_append(instructions, instruction)
|
||||||
|
elsif 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;
|
||||||
|
rtl_operand^.offset := 0
|
||||||
else
|
else
|
||||||
rtl_operand^.kind := ElnaRtlKind.pseudo;
|
rtl_operand^.kind := ElnaRtlKind.pseudo;
|
||||||
rtl_operand^.value := tac_operand^.value;
|
rtl_operand^.value := tac_operand^.value;
|
||||||
rtl_operand^.length := tac_operand^.length
|
rtl_operand^.length := tac_operand^.length;
|
||||||
|
rtl_operand^.offset := 0
|
||||||
end
|
end
|
||||||
end
|
end;
|
||||||
|
return pseudo_symbol
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_rtl_binary_arithmetic(instructions: ^ElnaList, tac_instruction: ^ElnaTacInstruction,
|
proc elna_rtl_binary_arithmetic(instructions: ^ElnaList, tac_instruction: ^ElnaTacInstruction,
|
||||||
@@ -1081,9 +1091,14 @@ begin
|
|||||||
elna_rtl_instruction_set_operand(instruction, 1, target_operand^.kind,
|
elna_rtl_instruction_set_operand(instruction, 1, target_operand^.kind,
|
||||||
target_operand^.value, target_operand^.length, 0);
|
target_operand^.value, target_operand^.length, 0);
|
||||||
if pseudo_symbol = nil then
|
if pseudo_symbol = nil then
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data,
|
||||||
|
addressable^.value, addressable^.length, 0)
|
||||||
|
elsif pseudo_symbol^.rtl_type^.kind = ElnaRtlTypeKind.byte_array then
|
||||||
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo_mem,
|
||||||
addressable^.value, addressable^.length, 0)
|
addressable^.value, addressable^.length, 0)
|
||||||
else
|
else
|
||||||
|
(* Debug
|
||||||
|
printf("# %.*s, %i\n\0", addressable^.length, addressable^.value, pseudo_symbol^.rtl_type^.kind); *)
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo,
|
||||||
addressable^.value, addressable^.length, 0)
|
addressable^.value, addressable^.length, 0)
|
||||||
end;
|
end;
|
||||||
@@ -1112,7 +1127,7 @@ begin
|
|||||||
instruction := elna_rtl_instruction_create(condition);
|
instruction := elna_rtl_instruction_create(condition);
|
||||||
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
|
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
|
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.symbol,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data,
|
||||||
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
|
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
|
||||||
|
|
||||||
elna_list_append(instructions, instruction)
|
elna_list_append(instructions, instruction)
|
||||||
@@ -1157,7 +1172,7 @@ begin
|
|||||||
goto elna_rtl_call_loop
|
goto elna_rtl_call_loop
|
||||||
end;
|
end;
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.jal);
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.jal);
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.symbol,
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.data,
|
||||||
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
|
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
|
||||||
elna_list_append(instructions, instruction);
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
@@ -1174,8 +1189,8 @@ var
|
|||||||
rtl_operand: ElnaRtlOperand;
|
rtl_operand: ElnaRtlOperand;
|
||||||
begin
|
begin
|
||||||
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
|
elna_rtl_operand_value(instructions, @tac_instruction^.operands[1], variable_map, @rtl_operand);
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.sw);
|
|
||||||
|
|
||||||
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.sw);
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, rtl_operand.kind, rtl_operand.value, rtl_operand.length, 0);
|
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.pseudo,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.pseudo,
|
||||||
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
|
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
|
||||||
@@ -1250,7 +1265,7 @@ begin
|
|||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.la);
|
||||||
|
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, target_operand.kind, target_operand.value, target_operand.length, 0);
|
elna_rtl_instruction_set_operand(instruction, 1, target_operand.kind, target_operand.value, target_operand.length, 0);
|
||||||
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.symbol,
|
elna_rtl_instruction_set_operand(instruction, 2, ElnaRtlKind.data,
|
||||||
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
|
tac_instruction^.operands[2].value, tac_instruction^.operands[2].length, 0);
|
||||||
elna_list_append(instructions, instruction);
|
elna_list_append(instructions, instruction);
|
||||||
|
|
||||||
@@ -1320,7 +1335,7 @@ begin
|
|||||||
elna_rtl_unary(instructions, tac_instruction, ElnaRtlOperator.not, variable_map)
|
elna_rtl_unary(instructions, tac_instruction, ElnaRtlOperator.not, variable_map)
|
||||||
elsif tac_instruction^.operator = ElnaTacOperator.jump then
|
elsif tac_instruction^.operator = ElnaTacOperator.jump then
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.j);
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.j);
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.symbol,
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.data,
|
||||||
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
|
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
|
||||||
elna_list_append(instructions, instruction)
|
elna_list_append(instructions, instruction)
|
||||||
elsif tac_instruction^.operator = ElnaTacOperator.jump_if_zero then
|
elsif tac_instruction^.operator = ElnaTacOperator.jump_if_zero then
|
||||||
@@ -1331,7 +1346,7 @@ begin
|
|||||||
elna_rtl_load_operand_value(instructions, @tac_instruction^.operands[1], ElnaRtlRegister.a0, variable_map)
|
elna_rtl_load_operand_value(instructions, @tac_instruction^.operands[1], ElnaRtlRegister.a0, variable_map)
|
||||||
elsif tac_instruction^.operator = ElnaTacOperator.label then
|
elsif tac_instruction^.operator = ElnaTacOperator.label then
|
||||||
instruction := elna_rtl_instruction_create(ElnaRtlOperator.label);
|
instruction := elna_rtl_instruction_create(ElnaRtlOperator.label);
|
||||||
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.symbol,
|
elna_rtl_instruction_set_operand(instruction, 1, ElnaRtlKind.data,
|
||||||
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
|
tac_instruction^.operands[1].value, tac_instruction^.operands[1].length, 0);
|
||||||
elna_list_append(instructions, instruction)
|
elna_list_append(instructions, instruction)
|
||||||
elsif tac_instruction^.operator = ElnaTacOperator.copy then
|
elsif tac_instruction^.operator = ElnaTacOperator.copy then
|
||||||
@@ -1455,7 +1470,7 @@ begin
|
|||||||
_write_c('(');
|
_write_c('(');
|
||||||
elna_riscv_register(instruction^.operands[n].value);
|
elna_riscv_register(instruction^.operands[n].value);
|
||||||
_write_c(')')
|
_write_c(')')
|
||||||
elsif operand_type = ElnaRtlKind.symbol then
|
elsif operand_type = ElnaRtlKind.data then
|
||||||
if instruction^.operands[n].length = 0 then
|
if instruction^.operands[n].length = 0 then
|
||||||
_write_label(instruction^.operands[n].value, 0)
|
_write_label(instruction^.operands[n].value, 0)
|
||||||
else
|
else
|
||||||
@@ -1524,7 +1539,8 @@ proc elna_alloc_load_address(instructions: ^ElnaList, instruction: ^ElnaRtlInstr
|
|||||||
var
|
var
|
||||||
pseudo_symbol: ^ElnaRtlInfo;
|
pseudo_symbol: ^ElnaRtlInfo;
|
||||||
begin
|
begin
|
||||||
if instruction^.operands[2].kind = ElnaRtlKind.pseudo then
|
(* pseudo or pseudo_mem. *)
|
||||||
|
if instruction^.operands[2].kind <> ElnaRtlKind.data then
|
||||||
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
|
pseudo_symbol := elna_alloc_variable(instruction^.operands[2].value, instruction^.operands[2].length,
|
||||||
variable_map);
|
variable_map);
|
||||||
instruction^.operator := ElnaRtlOperator.addi;
|
instruction^.operator := ElnaRtlOperator.addi;
|
||||||
@@ -1969,7 +1985,7 @@ begin
|
|||||||
_write_c('\n');
|
_write_c('\n');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_parser_integer_literal(cursor: ^ElnaLexerCursor);
|
proc elna_parser_integer_literal(cursor: ^ElnaLexerCursor) -> ^ElnaTreeIntegerLiteral;
|
||||||
var
|
var
|
||||||
token: ^ElnaLexerToken;
|
token: ^ElnaLexerToken;
|
||||||
result: ^ElnaTreeIntegerLiteral;
|
result: ^ElnaTreeIntegerLiteral;
|
||||||
@@ -1989,7 +2005,7 @@ begin
|
|||||||
return result
|
return result
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_parser_boolean_literal(cursor: ^ElnaLexerCursor);
|
proc elna_parser_boolean_literal(cursor: ^ElnaLexerCursor) -> ^ElnaTreeBooleanLiteral;
|
||||||
var
|
var
|
||||||
result: ^ElnaTreeBooleanLiteral;
|
result: ^ElnaTreeBooleanLiteral;
|
||||||
begin
|
begin
|
||||||
@@ -2038,7 +2054,7 @@ begin
|
|||||||
operand^.length := 0
|
operand^.length := 0
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_parser_character_literal(cursor: ^ElnaLexerCursor);
|
proc elna_parser_character_literal(cursor: ^ElnaLexerCursor) -> ^ElnaTreeCharacterLiteral;
|
||||||
var
|
var
|
||||||
result: ^ElnaTreeCharacterLiteral;
|
result: ^ElnaTreeCharacterLiteral;
|
||||||
token: ^ElnaLexerToken;
|
token: ^ElnaLexerToken;
|
||||||
@@ -2084,7 +2100,7 @@ begin
|
|||||||
operand^.length := variable_expression^.length
|
operand^.length := variable_expression^.length
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_parser_string_literal(cursor: ^ElnaLexerCursor);
|
proc elna_parser_string_literal(cursor: ^ElnaLexerCursor) -> ^ElnaTreeStringLiteral;
|
||||||
var
|
var
|
||||||
result: ^ElnaTreeStringLiteral;
|
result: ^ElnaTreeStringLiteral;
|
||||||
token: ^ElnaLexerToken;
|
token: ^ElnaLexerToken;
|
||||||
@@ -2123,7 +2139,7 @@ begin
|
|||||||
elna_list_append(instructions, instruction)
|
elna_list_append(instructions, instruction)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_parser_trait_expression(cursor: ^ElnaLexerCursor);
|
proc elna_parser_trait_expression(cursor: ^ElnaLexerCursor) -> ^ElnaTreeTraitExpression;
|
||||||
var
|
var
|
||||||
result: ^ElnaTreeTraitExpression;
|
result: ^ElnaTreeTraitExpression;
|
||||||
token: ^ElnaLexerToken;
|
token: ^ElnaLexerToken;
|
||||||
@@ -2144,10 +2160,10 @@ begin
|
|||||||
return result
|
return result
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_parser_simple_expression(cursor: ^ElnaLexerCursor);
|
proc elna_parser_simple_expression(cursor: ^ElnaLexerCursor) -> ^ElnaTreeExpression;
|
||||||
var
|
var
|
||||||
current_character: Word;
|
current_character: Word;
|
||||||
parser_node: Word;
|
parser_node: ^ElnaTreeExpression;
|
||||||
token: ^ElnaLexerToken;
|
token: ^ElnaLexerToken;
|
||||||
begin
|
begin
|
||||||
parser_node := 0;
|
parser_node := 0;
|
||||||
@@ -3871,7 +3887,7 @@ begin
|
|||||||
return result
|
return result
|
||||||
end;
|
end;
|
||||||
|
|
||||||
proc elna_tac_procedure_declaration(parser_node: ElnaTreeProcedureDeclaration);
|
proc elna_tac_procedure_declaration(parser_node: ^ElnaTreeProcedureDeclaration);
|
||||||
var
|
var
|
||||||
symbol_info: ^ElnaSymbolProcedureInfo;
|
symbol_info: ^ElnaSymbolProcedureInfo;
|
||||||
result: ^ElnaTacProcedure;
|
result: ^ElnaTacProcedure;
|
||||||
|
|||||||
Reference in New Issue
Block a user