From 85c654a102701958d3748e82ecac9c1bc4dbbcba Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 16 Jul 2019 00:27:53 +0200 Subject: Start on real bytecode & doc parsing --- src/ssa/ssa.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/ssa') diff --git a/src/ssa/ssa.c b/src/ssa/ssa.c index 91ba185..34e3e3e 100644 --- a/src/ssa/ssa.c +++ b/src/ssa/ssa.c @@ -16,6 +16,9 @@ do { \ throw(return_if_result); \ } while(0) +/* Max length of a string that fits in u16 */ +#define MAX_STRING_LENGTH ((2 << 16) - 1) + static int compare_number(const void *a, const void *b) { const SsaNumber *lhs; const SsaNumber *rhs; @@ -125,6 +128,11 @@ static CHECK_RESULT int ssa_try_add_string(Ssa *self, BufferView str, SsaStringI /* Overflow */ if(self->string_counter + 1 < self->string_counter) return -1; + + if(str.size > MAX_STRING_LENGTH) { + amal_log_error("String \"%.*s\" is longer than %d\n", str.size, str.data, MAX_STRING_LENGTH); + return -2; + } *result_index = self->string_counter; ++self->string_counter; @@ -386,6 +394,10 @@ in any order. */ static CHECK_RESULT SsaRegister funcdecl_generate_ssa(FunctionDecl *self, SsaCompilerContext *context) { /* TODO: Implement */ + /* + Reset reg counter in each function, because each function has a separate register context + that is reset after function end + */ SsaRegister prev_reg_counter; prev_reg_counter = context->ssa->reg_counter; context->ssa->reg_counter = 0; -- cgit v1.2.3