aboutsummaryrefslogtreecommitdiff
path: root/src/bytecode/bytecode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bytecode/bytecode.c')
-rw-r--r--src/bytecode/bytecode.c274
1 files changed, 137 insertions, 137 deletions
diff --git a/src/bytecode/bytecode.c b/src/bytecode/bytecode.c
index 98698bc..af9251b 100644
--- a/src/bytecode/bytecode.c
+++ b/src/bytecode/bytecode.c
@@ -1,7 +1,7 @@
#include "../../include/bytecode/bytecode.h"
#include "../../include/std/mem.h"
#include "../../include/std/log.h"
-#include "../../include/ssa/ssa.h"
+#include "../../include/ir/ir.h"
#include "../../include/parser.h"
#include "../../include/ast.h"
#include "../../include/compiler.h"
@@ -60,7 +60,7 @@ CHECK_RESULT int buffer_append_header(Buffer *program_data) {
return 0;
}
-static CHECK_RESULT usize ssa_extract_data(u8 *instruction_data, void *result, usize size) {
+static CHECK_RESULT usize ir_extract_data(u8 *instruction_data, void *result, usize size) {
am_memcpy(result, instruction_data, size);
return size;
}
@@ -80,13 +80,13 @@ static void add_intermediates(BytecodeCompilerContext *self) {
|u64 |Value|The type of the value depends on the value of @Type.|
*/
- Ssa *ssa = self->parser->ssa;
+ Ir *ir = self->parser->ir;
Buffer *instructions = &self->bytecode->data;
- SsaNumber *intermediate = buffer_begin(&ssa->intermediates);
- SsaNumber *intermediates_end = buffer_end(&ssa->intermediates);
+ IrNumber *intermediate = buffer_begin(&ir->intermediates);
+ IrNumber *intermediates_end = buffer_end(&ir->intermediates);
int i = 0;
- u32 intemediates_size = (sizeof(u8) + sizeof(u64)) * buffer_get_size(&ssa->intermediates, SsaNumber);
+ u32 intemediates_size = (sizeof(u8) + sizeof(u64)) * buffer_get_size(&ir->intermediates, IrNumber);
throw_if_error(buffer_expand(instructions, sizeof(u32) + intemediates_size));
throw_if_error(buffer_append(instructions, &intemediates_size, sizeof(u32)));
for(; intermediate != intermediates_end; ++intermediate) {
@@ -113,19 +113,19 @@ static void add_strings(BytecodeCompilerContext *self) {
|u8* |Data|The data of the string, where the size is defined by @Size. Strings are null-terminated.|
*/
- Ssa *ssa = self->parser->ssa;
+ Ir *ir = self->parser->ir;
Buffer *instructions = &self->bytecode->data;
- BufferView *string = buffer_begin(&ssa->strings);
- BufferView *strings_end = buffer_end(&ssa->strings);
+ BufferView *string = buffer_begin(&ir->strings);
+ BufferView *strings_end = buffer_end(&ir->strings);
u32 strings_size = 0;
for(; string != strings_end; ++string) {
strings_size += sizeof(u16) + string->size + 1; /* +1 for null-termination of string */
}
- string = buffer_begin(&ssa->strings);
+ string = buffer_begin(&ir->strings);
throw_if_error(buffer_expand(instructions, sizeof(u16) + sizeof(u32) + strings_size));
- throw_if_error(buffer_append(instructions, &ssa->string_counter, sizeof(u16)));
+ throw_if_error(buffer_append(instructions, &ir->string_counter, sizeof(u16)));
throw_if_error(buffer_append(instructions, &strings_size, sizeof(u32)));
for(; string != strings_end; ++string) {
const char null_s = '\0';
@@ -188,16 +188,16 @@ static void add_functions(BytecodeCompilerContext *self) {
|u32 |return_types_fixed_size |The size of all non-pointer type return types, in bytes. |
*/
- Ssa *ssa = self->parser->ssa;
+ Ir *ir = self->parser->ir;
Buffer *instructions = &self->bytecode->data;
- SsaFunc *func = buffer_begin(&ssa->funcs);
- SsaFunc *func_end = buffer_end(&ssa->funcs);
- u32 funcs_size = (u32)ssa->func_counter * sizeof(BytecodeHeaderFunction);
+ IrFunc *func = buffer_begin(&ir->funcs);
+ IrFunc *func_end = buffer_end(&ir->funcs);
+ u32 funcs_size = (u32)ir->func_counter * sizeof(BytecodeHeaderFunction);
assert(sizeof(BytecodeHeaderFunction) == 22);
self->bytecode->funcs_index = instructions->size;
throw_if_error(buffer_expand(instructions, sizeof(u16) + sizeof(u32) + funcs_size));
- throw_if_error(buffer_append(instructions, &ssa->func_counter, sizeof(u16)));
+ throw_if_error(buffer_append(instructions, &ir->func_counter, sizeof(u16)));
throw_if_error(buffer_append(instructions, &funcs_size, sizeof(u32)));
for(; func != func_end; ++func) {
BytecodeHeaderFunction header_func;
@@ -216,7 +216,7 @@ static void add_functions(BytecodeCompilerContext *self) {
throw_if_error(buffer_append(instructions, &header_func, sizeof(header_func)));
}
- assert(sizeof(ssa->func_counter) == sizeof(u16) && "Program decoder needs to be updated since size of func index has changed");
+ assert(sizeof(ir->func_counter) == sizeof(u16) && "Program decoder needs to be updated since size of func index has changed");
}
static void add_extern_functions(BytecodeCompilerContext *self) {
@@ -241,21 +241,21 @@ static void add_extern_functions(BytecodeCompilerContext *self) {
|u32 |return_types_fixed_size |The size of all non-pointer type return types, in bytes. |
|u8[]|name |The name of the external function, where the size is defined by @name_len. Names are null-terminated.|
*/
- Ssa *ssa = self->parser->ssa;
+ Ir *ir = self->parser->ir;
Buffer *instructions = &self->bytecode->data;
- SsaExternFunc *extern_func = buffer_begin(&ssa->extern_funcs);
- SsaExternFunc *extern_func_end = buffer_end(&ssa->extern_funcs);
- u32 extern_funcs_size = (u32)ssa->extern_func_counter * sizeof(BytecodeHeaderExternFunction);
+ IrExternFunc *extern_func = buffer_begin(&ir->extern_funcs);
+ IrExternFunc *extern_func_end = buffer_end(&ir->extern_funcs);
+ u32 extern_funcs_size = (u32)ir->extern_func_counter * sizeof(BytecodeHeaderExternFunction);
assert(sizeof(BytecodeHeaderExternFunction) == 20);
for(; extern_func != extern_func_end; ++extern_func) {
extern_funcs_size += extern_func->name.size + 1; /* +1 for null-termination of string */
}
- extern_func = buffer_begin(&ssa->extern_funcs);
+ extern_func = buffer_begin(&ir->extern_funcs);
self->bytecode->extern_funcs_index = instructions->size;
throw_if_error(buffer_expand(instructions, sizeof(u16) + sizeof(u32) + extern_funcs_size));
- throw_if_error(buffer_append(instructions, &ssa->extern_func_counter, sizeof(u16)));
+ throw_if_error(buffer_append(instructions, &ir->extern_func_counter, sizeof(u16)));
throw_if_error(buffer_append(instructions, &extern_funcs_size, sizeof(u32)));
for(; extern_func != extern_func_end; ++extern_func) {
const char null_s = '\0';
@@ -288,7 +288,7 @@ static void add_extern_functions(BytecodeCompilerContext *self) {
throw_if_error(buffer_append(instructions, &null_s, sizeof(char)));
}
- assert(sizeof(SsaExternFuncIndex) == sizeof(u16) && "Program decoder needs to be updated since size of extern func index has changed");
+ assert(sizeof(IrExternFuncIndex) == sizeof(u16) && "Program decoder needs to be updated since size of extern func index has changed");
}
static void add_export_functions(BytecodeCompilerContext *self) {
@@ -308,19 +308,19 @@ static void add_export_functions(BytecodeCompilerContext *self) {
|u8 |name_len |The length of the exported function name, in bytes. Excluding the null-terminate character. |
|u8[]|name |The name of the exported function, where the size is defined by @name_len. Names are null-terminated. |
*/
- Ssa *ssa = self->parser->ssa;
+ Ir *ir = self->parser->ir;
Buffer *instructions = &self->bytecode->data;
- SsaExportFunc *export_func = buffer_begin(&ssa->export_funcs);
- SsaExportFunc *export_func_end = buffer_end(&ssa->export_funcs);
- u32 export_funcs_size = (u32)ssa->export_func_counter * (sizeof(u32) + sizeof(u8) + sizeof(u8));
+ IrExportFunc *export_func = buffer_begin(&ir->export_funcs);
+ IrExportFunc *export_func_end = buffer_end(&ir->export_funcs);
+ u32 export_funcs_size = (u32)ir->export_func_counter * (sizeof(u32) + sizeof(u8) + sizeof(u8));
for(; export_func != export_func_end; ++export_func) {
export_funcs_size += export_func->name.size + 1; /* +1 for null-termination of string */
}
- export_func = buffer_begin(&ssa->export_funcs);
+ export_func = buffer_begin(&ir->export_funcs);
throw_if_error(buffer_expand(instructions, sizeof(u16) + sizeof(u32) + export_funcs_size));
- throw_if_error(buffer_append(instructions, &ssa->export_func_counter, sizeof(u16)));
+ throw_if_error(buffer_append(instructions, &ir->export_func_counter, sizeof(u16)));
throw_if_error(buffer_append(instructions, &export_funcs_size, sizeof(u32)));
for(; export_func != export_func_end; ++export_func) {
const char null_s = '\0';
@@ -333,7 +333,7 @@ static void add_export_functions(BytecodeCompilerContext *self) {
throw_if_error(buffer_append(instructions, &null_s, sizeof(char)));
}
- assert(sizeof(SsaExportFuncIndex) == sizeof(u16) && "Program decoder needs to be updated since size of export func index has changed");
+ assert(sizeof(IrExportFuncIndex) == sizeof(u16) && "Program decoder needs to be updated since size of export func index has changed");
}
static void add_imports(BytecodeCompilerContext *self) {
@@ -455,183 +455,183 @@ static void add_instructions(BytecodeCompilerContext *self) {
|Instruction[]|Instructions data|The instructions data. Each instructions begins with an opcode, see #Opcode|
*/
- SsaInsForm1 ssa_ins_form1;
- SsaInsForm2 ssa_ins_form2;
- SsaInsFuncStart ssa_ins_func_start;
- SsaInsFuncCall ssa_ins_func_call;
- SsaInsFuncCallExtern ssa_ins_func_call_extern;
- SsaInsCallStart ssa_ins_call_start;
- SsaInsJumpZero ssa_ins_jump_zero;
- SsaInsJump ssa_ins_jump;
-
- Ssa *ssa = self->parser->ssa;
- u8 *instruction = buffer_begin(&ssa->instructions);
- u8 *instructions_end = buffer_end(&ssa->instructions);
+ IrInsForm1 ir_ins_form1;
+ IrInsForm2 ir_ins_form2;
+ IrInsFuncStart ir_ins_func_start;
+ IrInsFuncCall ir_ins_func_call;
+ IrInsFuncCallExtern ir_ins_func_call_extern;
+ IrInsCallStart ir_ins_call_start;
+ IrInsJumpZero ir_ins_jump_zero;
+ IrInsJump ir_ins_jump;
+
+ Ir *ir = self->parser->ir;
+ u8 *instruction = buffer_begin(&ir->instructions);
+ u8 *instructions_end = buffer_end(&ir->instructions);
u16 label_counter = 0;
u32 num_instructions_index = self->bytecode->data.size;
throw_if_error(buffer_append_empty(&self->bytecode->data, sizeof(num_instructions_index)));
while(instruction != instructions_end) {
- SsaInstruction ins = (SsaInstruction)*instruction++;
+ IrInstruction ins = (IrInstruction)*instruction++;
switch(ins) {
- case SSA_ASSIGN_INTER: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form1, sizeof(ssa_ins_form1));
- add_ins6(self, AMAL_OP_MOVI, ssa_ins_form1.lhs, ssa_ins_form1.rhs, "movi r%d, i%d");
+ case IR_ASSIGN_INTER: {
+ instruction += ir_extract_data(instruction, &ir_ins_form1, sizeof(ir_ins_form1));
+ add_ins6(self, AMAL_OP_MOVI, ir_ins_form1.lhs, ir_ins_form1.rhs, "movi r%d, i%d");
break;
}
- case SSA_ASSIGN_STRING: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form1, sizeof(ssa_ins_form1));
- add_ins6(self, AMAL_OP_MOVD, ssa_ins_form1.lhs, ssa_ins_form1.rhs, "movd r%d, s%d");
+ case IR_ASSIGN_STRING: {
+ instruction += ir_extract_data(instruction, &ir_ins_form1, sizeof(ir_ins_form1));
+ add_ins6(self, AMAL_OP_MOVD, ir_ins_form1.lhs, ir_ins_form1.rhs, "movd r%d, s%d");
break;
}
- case SSA_ASSIGN_REG: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form1, sizeof(ssa_ins_form1));
- add_ins3(self, AMAL_OP_MOV, ssa_ins_form1.lhs, ssa_ins_form1.rhs, "mov r%d, r%d");
+ case IR_ASSIGN_REG: {
+ instruction += ir_extract_data(instruction, &ir_ins_form1, sizeof(ir_ins_form1));
+ add_ins3(self, AMAL_OP_MOV, ir_ins_form1.lhs, ir_ins_form1.rhs, "mov r%d, r%d");
break;
}
- case SSA_ADD: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_ADD, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "add r%d, r%d, r%d");
+ case IR_ADD: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_ADD, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "add r%d, r%d, r%d");
break;
}
- case SSA_SUB: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_SUB, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "sub r%d, r%d, r%d");
+ case IR_SUB: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_SUB, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "sub r%d, r%d, r%d");
break;
}
- case SSA_IMUL: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_IMUL, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "imul r%d, r%d, r%d");
+ case IR_IMUL: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_IMUL, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "imul r%d, r%d, r%d");
break;
}
- case SSA_MUL: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_MUL, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "mul r%d, r%d, r%d");
+ case IR_MUL: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_MUL, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "mul r%d, r%d, r%d");
break;
}
- case SSA_IDIV: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_IDIV, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "idiv r%d, r%d, r%d");
+ case IR_IDIV: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_IDIV, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "idiv r%d, r%d, r%d");
break;
}
- case SSA_DIV: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_DIV, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "div r%d, r%d, r%d");
+ case IR_DIV: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_DIV, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "div r%d, r%d, r%d");
break;
}
- case SSA_EQUALS: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_EQ, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "eq r%d, r%d, r%d");
+ case IR_EQUALS: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_EQ, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "eq r%d, r%d, r%d");
break;
}
- case SSA_NOT_EQUAL: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_NEQ, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "neq r%d, r%d, r%d");
+ case IR_NOT_EQUAL: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_NEQ, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "neq r%d, r%d, r%d");
break;
}
- case SSA_AND: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_BIT_AND, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "and r%d, r%d, r%d");
+ case IR_AND: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_BIT_AND, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "and r%d, r%d, r%d");
break;
}
- case SSA_ILT: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_ILT, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "ilt r%d, r%d, r%d");
+ case IR_ILT: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_ILT, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "ilt r%d, r%d, r%d");
break;
}
- case SSA_ILE: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_ILE, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "ile r%d, r%d, r%d");
+ case IR_ILE: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_ILE, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "ile r%d, r%d, r%d");
break;
}
- case SSA_IGT: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_IGT, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "igt r%d, r%d, r%d");
+ case IR_IGT: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_IGT, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "igt r%d, r%d, r%d");
break;
}
- case SSA_IGE: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_IGE, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "ige r%d, r%d, r%d");
+ case IR_IGE: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_IGE, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "ige r%d, r%d, r%d");
break;
}
- case SSA_LT: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_LT, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "lt r%d, r%d, r%d");
+ case IR_LT: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_LT, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "lt r%d, r%d, r%d");
break;
}
- case SSA_LE: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_LE, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "le r%d, r%d, r%d");
+ case IR_LE: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_LE, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "le r%d, r%d, r%d");
break;
}
- case SSA_GT: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_GT, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "gt r%d, r%d, r%d");
+ case IR_GT: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_GT, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "gt r%d, r%d, r%d");
break;
}
- case SSA_GE: {
- instruction += ssa_extract_data(instruction, &ssa_ins_form2, sizeof(ssa_ins_form2));
- add_ins5(self, AMAL_OP_GE, ssa_ins_form2.result, ssa_ins_form2.lhs, ssa_ins_form2.rhs, "ge r%d, r%d, r%d");
+ case IR_GE: {
+ instruction += ir_extract_data(instruction, &ir_ins_form2, sizeof(ir_ins_form2));
+ add_ins5(self, AMAL_OP_GE, ir_ins_form2.result, ir_ins_form2.lhs, ir_ins_form2.rhs, "ge r%d, r%d, r%d");
break;
}
- case SSA_FUNC_START: {
- instruction += ssa_extract_data(instruction, &ssa_ins_func_start, sizeof(ssa_ins_func_start));
- add_ins6(self, AMAL_OP_FUNC_START, ssa_ins_func_start.flags, ssa_ins_func_start.num_local_vars_regs, "func_start 0x%02x, %u");
+ case IR_FUNC_START: {
+ instruction += ir_extract_data(instruction, &ir_ins_func_start, sizeof(ir_ins_func_start));
+ add_ins6(self, AMAL_OP_FUNC_START, ir_ins_func_start.flags, ir_ins_func_start.num_local_vars_regs, "func_start 0x%02x, %u");
label_counter = 0;
break;
}
- case SSA_FUNC_END: {
+ case IR_FUNC_END: {
add_ins1(self, AMAL_OP_FUNC_END, "func_end");
break;
}
- case SSA_PUSH: {
- SsaRegister reg;
- am_memcpy(&reg, instruction, sizeof(SsaRegister));
- instruction += sizeof(SsaRegister);
+ case IR_PUSH: {
+ IrRegister reg;
+ am_memcpy(&reg, instruction, sizeof(IrRegister));
+ instruction += sizeof(IrRegister);
add_ins2(self, AMAL_OP_PUSH, reg, "push r%d");
break;
}
- case SSA_PUSH_RET: {
- SsaRegister reg;
- am_memcpy(&reg, instruction, sizeof(SsaRegister));
- instruction += sizeof(SsaRegister);
+ case IR_PUSH_RET: {
+ IrRegister reg;
+ am_memcpy(&reg, instruction, sizeof(IrRegister));
+ instruction += sizeof(IrRegister);
add_ins2(self, AMAL_OP_PUSH_RET, reg, "push_ret r%d");
break;
}
- case SSA_CALL_START: {
- instruction += ssa_extract_data(instruction, &ssa_ins_call_start, sizeof(ssa_ins_call_start));
- add_ins2(self, AMAL_OP_CALL_START, ssa_ins_call_start.num_args, "call_start %d");
+ case IR_CALL_START: {
+ instruction += ir_extract_data(instruction, &ir_ins_call_start, sizeof(ir_ins_call_start));
+ add_ins2(self, AMAL_OP_CALL_START, ir_ins_call_start.num_args, "call_start %d");
break;
}
- case SSA_CALL: {
- instruction += ssa_extract_data(instruction, &ssa_ins_func_call, sizeof(ssa_ins_func_call));
- add_ins6(self, AMAL_OP_CALL, ssa_ins_func_call.import_index, ssa_ins_func_call.func_decl->ssa_func_index, "call f(%d,%d)");
+ case IR_CALL: {
+ instruction += ir_extract_data(instruction, &ir_ins_func_call, sizeof(ir_ins_func_call));
+ add_ins6(self, AMAL_OP_CALL, ir_ins_func_call.import_index, ir_ins_func_call.func_decl->ir_func_index, "call f(%d,%d)");
break;
}
- case SSA_CALL_EXTERN: {
- instruction += ssa_extract_data(instruction, &ssa_ins_func_call_extern, sizeof(ssa_ins_func_call_extern));
- add_ins6(self, AMAL_OP_CALLE, ssa_ins_func_call_extern.import_index, ssa_ins_func_call_extern.func_decl_lhs->extern_index, "calle ef(%d,%d)");
+ case IR_CALL_EXTERN: {
+ instruction += ir_extract_data(instruction, &ir_ins_func_call_extern, sizeof(ir_ins_func_call_extern));
+ add_ins6(self, AMAL_OP_CALLE, ir_ins_func_call_extern.import_index, ir_ins_func_call_extern.func_decl_lhs->extern_index, "calle ef(%d,%d)");
break;
}
- case SSA_JUMP_ZERO: {
- instruction += ssa_extract_data(instruction, &ssa_ins_jump_zero, sizeof(ssa_ins_jump_zero));
- add_ins6(self, AMAL_OP_JZ, ssa_ins_jump_zero.condition_reg, ssa_ins_jump_zero.target_label, "jz r%d, l%d");
+ case IR_JUMP_ZERO: {
+ instruction += ir_extract_data(instruction, &ir_ins_jump_zero, sizeof(ir_ins_jump_zero));
+ add_ins6(self, AMAL_OP_JZ, ir_ins_jump_zero.condition_reg, ir_ins_jump_zero.target_label, "jz r%d, l%d");
break;
}
- case SSA_JUMP: {
- instruction += ssa_extract_data(instruction, &ssa_ins_jump, sizeof(ssa_ins_jump));
- add_ins4(self, AMAL_OP_JMP, ssa_ins_jump.target_label, "jmp l%d");
+ case IR_JUMP: {
+ instruction += ir_extract_data(instruction, &ir_ins_jump, sizeof(ir_ins_jump));
+ add_ins4(self, AMAL_OP_JMP, ir_ins_jump.target_label, "jmp l%d");
break;
}
- case SSA_RET: {
- SsaRegister reg;
- am_memcpy(&reg, instruction, sizeof(SsaRegister));
- instruction += sizeof(SsaRegister);
+ case IR_RET: {
+ IrRegister reg;
+ am_memcpy(&reg, instruction, sizeof(IrRegister));
+ instruction += sizeof(IrRegister);
add_ins2(self, AMAL_OP_RET, reg, "ret r%d");
break;
}
- case SSA_LABEL: {
+ case IR_LABEL: {
add_ins1(self, AMAL_OP_LABEL, NULL);
fprintf(stderr, "label l%d\n", label_counter++);
break;
@@ -652,7 +652,7 @@ static void add_section_magic_number(BytecodeCompilerContext *self) {
throw_if_error(buffer_append(&self->bytecode->data, &section_magic_number, sizeof(section_magic_number)));
}
-void generate_bytecode_from_ssa(BytecodeCompilerContext *self) {
+void generate_bytecode_from_ir(BytecodeCompilerContext *self) {
add_section_magic_number(self);
add_intermediates(self);