diff options
Diffstat (limited to 'src/ssa')
-rw-r--r-- | src/ssa/ssa.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/ssa/ssa.c b/src/ssa/ssa.c index b04e469..e55f687 100644 --- a/src/ssa/ssa.c +++ b/src/ssa/ssa.c @@ -256,15 +256,15 @@ static CHECK_RESULT SsaRegister funcdecl_generate_ssa(FunctionDecl *self, SsaCom static CHECK_RESULT SsaRegister funccall_generate_ssa(FunctionCall *self, SsaCompilerContext *context) { /* TODO: Implement */ - Ast *ast; - Ast *ast_end; + Ast **ast; + Ast **ast_end; SsaRegister reg; ast = buffer_start(&self->args); ast_end = buffer_end(&self->args); for(; ast != ast_end; ++ast) { SsaRegister arg_reg; - arg_reg = ast_generate_ssa(ast, context); + arg_reg = ast_generate_ssa(*ast, context); throw_if_error(ssa_ins_push(&context->ssa, arg_reg)); } /* TODO: Use real func index */ @@ -287,10 +287,16 @@ static CHECK_RESULT SsaRegister structfield_generate_ssa(StructField *self, SsaC static CHECK_RESULT SsaRegister lhs_generate_ssa(LhsExpr *self, SsaCompilerContext *context) { /* TODO: Implement */ - SsaRegister rhs_reg; - rhs_reg = ast_generate_ssa(&self->rhs_expr, context); - /* TODO: Is this correct? */ - return rhs_reg; + SsaRegister reg; + throw_if_error(ssa_get_unique_reg(&context->ssa, ®)); + if(self->rhs_expr) { + SsaRegister rhs_reg; + rhs_reg = ast_generate_ssa(self->rhs_expr, context); + throw_if_error(ssa_ins_assign_reg(&context->ssa, reg, rhs_reg)); + } else { + /* TODO: assign default value to reg depending on LhsExpr type */ + } + return reg; } static CHECK_RESULT SsaRegister string_generate_ssa(String *self, SsaCompilerContext *context) { @@ -328,17 +334,21 @@ static CHECK_RESULT SsaRegister binop_generate_ssa(Binop *self, SsaCompilerConte SsaRegister lhs_reg; SsaRegister rhs_reg; SsaRegister reg; - lhs_reg = ast_generate_ssa(&self->lhs, context); - rhs_reg = ast_generate_ssa(&self->rhs, context); + lhs_reg = ast_generate_ssa(self->lhs, context); + rhs_reg = ast_generate_ssa(self->rhs, context); throw_if_error(ssa_ins_binop(&context->ssa, binop_type_to_ssa_type(self->type), lhs_reg, rhs_reg, ®)); return reg; } CHECK_RESULT SsaRegister ast_generate_ssa(Ast *self, SsaCompilerContext *context) { - assert(self->resolve_status == AST_RESOLVED); + assert(self); + #ifdef DEBUG + if(self->resolve_data.status != AST_RESOLVED) { + amal_log_error("Ast type not resolved: %d", self->type); + assert(bool_false); + } + #endif switch(self->type) { - case AST_NONE: - return 0; case AST_NUMBER: return number_generate_ssa(self->value.number, context); case AST_FUNCTION_DECL: @@ -365,11 +375,11 @@ CHECK_RESULT SsaRegister ast_generate_ssa(Ast *self, SsaCompilerContext *context } void scope_generate_ssa(Scope *self, SsaCompilerContext *context) { - Ast *ast; - Ast *ast_end; + Ast **ast; + Ast **ast_end; ast = buffer_start(&self->ast_objects); ast_end = buffer_end(&self->ast_objects); for(; ast != ast_end; ++ast) { - ignore_result_int(ast_generate_ssa(ast, context)); + ignore_result_int(ast_generate_ssa(*ast, context)); } } |