diff options
Diffstat (limited to 'src/compiler.c')
-rw-r--r-- | src/compiler.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/compiler.c b/src/compiler.c index fbdeb94..c50ffac 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -1,5 +1,6 @@ #include "../include/compiler.h" #include "../include/parser.h" +#include "../include/ssa/ssa.h" #include "../include/std/log.h" #include "../include/std/mem.h" #include "../include/std/alloc.h" @@ -150,39 +151,55 @@ static void* thread_callback_parse_file(void *userdata) { return result; } +static CHECK_RESULT int thread_resolve_ast(Parser *parser) { + AstCompilerContext compiler_context; + int result; + compiler_context.parser = parser; + result = setjmp(compiler_context.env); + if(result == 0) { + amal_log_debug("Resolving AST for file: %.*s", parser->tokenizer.code_name.size, parser->tokenizer.code_name.data); + scope_resolve(&parser->scope, &compiler_context); + } + return result; +} + +static CHECK_RESULT int thread_generate_ssa(Parser *parser) { + SsaCompilerContext compiler_context; + int result; + compiler_context.parser = parser; + result = setjmp(compiler_context.env); + if(result == 0) { + return_if_error(ssa_init(&compiler_context.ssa, parser->allocator)); + amal_log_debug("Generating SSA for file: %.*s", parser->tokenizer.code_name.size, parser->tokenizer.code_name.data); + scope_generate_ssa(&parser->scope, &compiler_context); + } + return result; +} + /* TODO: Handle errors (stop work in all other threads and report errors/warnings) */ static void* thread_callback_generic(void *userdata) { CompilerGenericThreadUserData compiler_userdata; Parser *parser; - AstCompilerContext compiler_context; void *result; assert(!amal_thread_is_main()); am_memcpy(&compiler_userdata, userdata, sizeof(compiler_userdata)); am_free(userdata); parser = compiler_userdata.parser; - compiler_context.parser = parser; result = (void*)AMAL_COMPILER_ERR; for(;;) { - int result; - result = setjmp(compiler_context.env); - if(result == 0) { - switch(compiler_userdata.work_type) { - case THREAD_WORK_PARSE: - assert(bool_false && "Thread work type can't ge 'parse' for generic work"); - break; - case THREAD_WORK_RESOLVE_AST: - amal_log_debug("Resolving AST for file: %.*s", parser->tokenizer.code_name.size, parser->tokenizer.code_name.data); - scope_resolve(&parser->scope, &compiler_context); - break; - case THREAD_WORK_GENERATE_SSA: - amal_log_debug("Generating SSA for file: %.*s", parser->tokenizer.code_name.size, parser->tokenizer.code_name.data); - scope_generate_ssa(&parser->scope, &compiler_context); - break; + /* TODO: stop work in all other threads on failure */ + switch(compiler_userdata.work_type) { + case THREAD_WORK_PARSE: { + assert(bool_false && "Thread work type can't ge 'parse' for generic work"); + break; } - } else { - /* TODO: stop work in all other threads */ - break; + case THREAD_WORK_RESOLVE_AST: + cleanup_if_error(thread_resolve_ast(parser)); + break; + case THREAD_WORK_GENERATE_SSA: + cleanup_if_error(thread_generate_ssa(parser)); + break; } cleanup_if_error(amal_mutex_lock(&compiler_userdata.compiler->mutex, "thread_callback_generic")); if(compiler_userdata.compiler->generic_work_object_index + 1 >= (int)buffer_get_size(&compiler_userdata.compiler->parsers, Parser)) |