aboutsummaryrefslogtreecommitdiff
path: root/src/ssa
diff options
context:
space:
mode:
Diffstat (limited to 'src/ssa')
-rw-r--r--src/ssa/ssa.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/ssa/ssa.c b/src/ssa/ssa.c
index 9955d9d..d875ea4 100644
--- a/src/ssa/ssa.c
+++ b/src/ssa/ssa.c
@@ -81,7 +81,7 @@ int ssa_init(Ssa *self, Parser *parser) {
static CHECK_RESULT int ssa_get_unique_reg(Ssa *self, SsaRegister *result) {
assert(result);
/* Overflow */
- if((u16)self->reg_counter + self->param_counter + 1 > INT16_MAX) {
+ if((u16)self->reg_counter + 1 > INT16_MAX) {
amal_log_error("Ssa too many registers!");
return -1;
}
@@ -90,6 +90,18 @@ static CHECK_RESULT int ssa_get_unique_reg(Ssa *self, SsaRegister *result) {
return 0;
}
+static CHECK_RESULT int ssa_get_unique_param_reg(Ssa *self, SsaRegister *result) {
+ assert(result);
+ /* Overflow */
+ if((u16)self->param_counter + 1 > INT16_MAX) {
+ amal_log_error("Ssa too many param registers!");
+ return -1;
+ }
+ assert(self->param_counter <= INT8_MAX && "TODO: Implement usage of reg higher than 128");
+ *result = self->param_counter++ | REG_FLAG_PARAM;
+ return 0;
+}
+
SsaNumber ssa_get_intermediate(Ssa *self, SsaIntermediateIndex index) {
SsaNumber result;
assert(index < buffer_get_size(&self->intermediates, SsaNumber));
@@ -239,6 +251,7 @@ static const char* binop_type_to_string(SsaInstruction binop_type) {
case SSA_MUL: return "*";
case SSA_DIV: return "/";
case SSA_EQUALS: return "==";
+ case SSA_AND: return "&&";
default: return "";
}
}
@@ -274,7 +287,7 @@ static CHECK_RESULT int ssa_ins_assign_reg(Ssa *self, SsaRegister dest, SsaRegis
}
static CHECK_RESULT int ssa_ins_binop(Ssa *self, SsaInstruction binop_type, SsaRegister lhs, SsaRegister rhs, SsaRegister *result) {
- assert(binop_type >= SSA_ADD && binop_type <= SSA_EQUALS);
+ assert(binop_type >= SSA_ADD && binop_type <= SSA_AND);
return ssa_add_ins_form2(self, binop_type, lhs, rhs, result);
}
@@ -577,14 +590,7 @@ static CHECK_RESULT SsaRegister function_parameter_generate_ssa(FunctionParamete
if(self->resolve_data.status == AST_SSA_RESOLVED)
return self->resolve_data.ssa_reg;
- throw_if_error(ssa_get_unique_reg(context->ssa, &reg));
- /* Parameters start at -1 and decrement */
- if((u16)reg - 1 >= (u16)reg) {
- amal_log_error("Ssa too many parameters!");
- throw(-1);
- }
- reg = -1 - reg;
- assert(reg >= INT8_MIN && "TODO: Implement more than 128 params");
+ throw_if_error(ssa_get_unique_param_reg(context->ssa, &reg));
self->resolve_data.status = AST_SSA_RESOLVED;
self->resolve_data.ssa_reg = reg;
return reg;
@@ -614,6 +620,7 @@ static CHECK_RESULT SsaRegister funcdecl_generate_ssa(FunctionDecl *self, SsaCom
usize func_metadata_index;
u8 func_flags = 0;
context->ssa->reg_counter = 0;
+ context->ssa->param_counter = 0;
context->ssa->label_counter = 0;
/*
@@ -621,8 +628,6 @@ static CHECK_RESULT SsaRegister funcdecl_generate_ssa(FunctionDecl *self, SsaCom
This way we can know if a register access is for a parameter or not by checking the number
*/
function_signature_generate_params_ssa(self->signature, context);
- context->ssa->param_counter = context->ssa->reg_counter;
- context->ssa->reg_counter = 0;
amal_log_debug("SSA funcdecl %p", self);
/* Anonymous closure doesn't have lhs_expr, and neither can it have any flags (extern, export etc) */
@@ -754,6 +759,8 @@ static SsaInstruction binop_type_to_ssa_type(BinopType binop_type, amal_default_
return 0;
case BINOP_EQUALS:
return SSA_EQUALS;
+ case BINOP_AND:
+ return SSA_AND;
}
return 0;
}