diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ast.c | 17 | ||||
-rw-r--r-- | src/compiler.c | 57 | ||||
-rw-r--r-- | src/ssa/ssa.c | 17 |
3 files changed, 54 insertions, 37 deletions
@@ -14,7 +14,6 @@ do { \ } while(0) static void ast_resolve(Ast *self, AstCompilerContext *context); -static void ast_generate_ssa(Ast *self, AstCompilerContext *context); Ast ast_none() { Ast ast; @@ -226,19 +225,3 @@ void ast_resolve(Ast *self, AstCompilerContext *context) { } /*self->resolve_status = AST_RESOLVED;*/ } - -void scope_generate_ssa(Scope *self, AstCompilerContext *context) { - Ast *ast; - Ast *ast_end; - ast = buffer_start(&self->ast_objects); - ast_end = buffer_end(&self->ast_objects); - for(; ast != ast_end; ++ast) { - ast_generate_ssa(ast, context); - } -} - -void ast_generate_ssa(Ast *self, AstCompilerContext *context) { - /* TODO: Implement */ - (void)self; - (void)context; -}
\ No newline at end of file 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)) diff --git a/src/ssa/ssa.c b/src/ssa/ssa.c index 3433e8d..f5187af 100644 --- a/src/ssa/ssa.c +++ b/src/ssa/ssa.c @@ -1,6 +1,7 @@ #include "../../include/ssa/ssa.h" #include "../../include/std/mem.h" #include "../../include/std/log.h" +#include "../../include/ast.h" #include <assert.h> static int compare_number(const void *a, const void *b) { @@ -163,3 +164,19 @@ int ssa_ins_call(Ssa *self, SsaFuncIndex func, SsaRegister *result) { amal_log_debug("r%u = CALL f%u", *result, func); return 0; } + +static void ast_generate_ssa(Ast *self, SsaCompilerContext *context) { + /* TODO: Implement */ + (void)self; + (void)context; +} + +void scope_generate_ssa(Scope *self, SsaCompilerContext *context) { + Ast *ast; + Ast *ast_end; + ast = buffer_start(&self->ast_objects); + ast_end = buffer_end(&self->ast_objects); + for(; ast != ast_end; ++ast) { + ast_generate_ssa(ast, context); + } +} |