aboutsummaryrefslogtreecommitdiff
path: root/src/ssa
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-18 23:47:45 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit2323ca6c9ec3c8ee76b9acf13745b80b92952a6a (patch)
tree93013237dbcb0fa96ceb5f3c026fd040aff464cf /src/ssa
parent5a93c32a59775cd1be4b4f450e8230016b434366 (diff)
Add struct, import caching, binop ops etc
Diffstat (limited to 'src/ssa')
-rw-r--r--src/ssa/ssa.c30
1 files changed, 29 insertions, 1 deletions
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: