From 2323ca6c9ec3c8ee76b9acf13745b80b92952a6a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 18 Mar 2019 23:47:45 +0100 Subject: Add struct, import caching, binop ops etc --- src/ssa/ssa.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/ssa') diff --git a/src/ssa/ssa.c b/src/ssa/ssa.c index f892531..b04e469 100644 --- a/src/ssa/ssa.c +++ b/src/ssa/ssa.c @@ -123,6 +123,17 @@ static CHECK_RESULT int ssa_add_ins_form1(Ssa *self, SsaInstructionType ins_type return 0; } +static const char* binop_type_to_string(SsaInstructionType binop_type) { + assert(binop_type >= SSA_ADD && binop_type <= SSA_DIV); + switch(binop_type) { + case SSA_ADD: return "+"; + case SSA_SUB: return "-"; + case SSA_MUL: return "*"; + case SSA_DIV: return "/"; + default: return ""; + } +} + static CHECK_RESULT int ssa_add_ins_form2(Ssa *self, SsaInstructionType ins_type, SsaRegister lhs, SsaRegister rhs, SsaRegister *result) { usize index; index = self->instructions.size; @@ -138,7 +149,7 @@ static CHECK_RESULT int ssa_add_ins_form2(Ssa *self, SsaInstructionType ins_type *(SsaRegister*)&self->instructions.data[index + 1] = *result; *(SsaRegister*)&self->instructions.data[index + 3] = lhs; *(SsaRegister*)&self->instructions.data[index + 5] = rhs; - amal_log_debug("r%u = r%u + r%u", *result, lhs, rhs); + amal_log_debug("r%u = r%u %s r%u", *result, lhs, binop_type_to_string(ins_type), rhs); return 0; } @@ -261,6 +272,19 @@ static CHECK_RESULT SsaRegister funccall_generate_ssa(FunctionCall *self, SsaCom return reg; } +static CHECK_RESULT SsaRegister structdecl_generate_ssa(StructDecl *self, SsaCompilerContext *context) { + /* TODO: Implement */ + scope_generate_ssa(&self->body, context); + return 0; +} + +static CHECK_RESULT SsaRegister structfield_generate_ssa(StructField *self, SsaCompilerContext *context) { + /* TODO: Implement */ + (void)self; + (void)context; + return 0; +} + static CHECK_RESULT SsaRegister lhs_generate_ssa(LhsExpr *self, SsaCompilerContext *context) { /* TODO: Implement */ SsaRegister rhs_reg; @@ -321,6 +345,10 @@ CHECK_RESULT SsaRegister ast_generate_ssa(Ast *self, SsaCompilerContext *context return funcdecl_generate_ssa(self->value.func_decl, context); case AST_FUNCTION_CALL: return funccall_generate_ssa(self->value.func_call, context); + case AST_STRUCT_DECL: + return structdecl_generate_ssa(self->value.struct_decl, context); + case AST_STRUCT_FIELD: + return structfield_generate_ssa(self->value.struct_field, context); case AST_LHS: return lhs_generate_ssa(self->value.lhs_expr, context); case AST_IMPORT: -- cgit v1.2.3