stage1 重写进行代码设计并重构 提供diag替换老旧错误处理
This commit is contained in:
1 parent
7cbe2d2b9a
commit
e4347cc3ea
14 files changed
+983
-526
No files matched your search
+23
-8
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "spl_ast.h"
|
||||
#include "spl_ast2ir.h"
|
||||
#include "spl_diag.h"
|
||||
#include "spl_ir2vm.h"
|
||||
#include "spl_lexer.h"
|
||||
#include "spl_sema.h"
|
||||
@@ -77,11 +78,17 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
|
||||
// memory leak
|
||||
return 0;
|
||||
}
|
||||
|
||||
spl_diag_t diag;
|
||||
spl_diag_init(&diag, stderr);
|
||||
|
||||
spl_ast_t ast;
|
||||
spl_ast_init(&ast, &toks);
|
||||
spl_diag_set_stage(&diag, SPL_STAGE_PARSE);
|
||||
ast.diag = &diag;
|
||||
spl_ast_parse(&ast);
|
||||
if (ast.parsed < 0) {
|
||||
printf("parse failed, no output\n");
|
||||
if (spl_diag_has_error(&diag) || spl_diag_has_fatal(&diag)) {
|
||||
spl_diag_summary(&diag);
|
||||
// memory leak
|
||||
return 1;
|
||||
}
|
||||
@@ -101,10 +108,12 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
|
||||
spl_scope_init(&scope);
|
||||
spl_sema_init(&sema, &ast, &type, &scope, &attr);
|
||||
sema.ast = *
|
||||
spl_diag_set_stage(&diag, SPL_STAGE_SEMA);
|
||||
sema.diag = &diag;
|
||||
spl_sema_run(&sema);
|
||||
if (sema.error_count) {
|
||||
printf("sema errors=%d, no output\n", sema.error_count);
|
||||
if (spl_diag_has_error(&diag) || spl_diag_has_fatal(&diag)) {
|
||||
// memory leak
|
||||
spl_diag_summary(&diag);
|
||||
return 1;
|
||||
}
|
||||
if (dump == DUMP_SEMA) {
|
||||
@@ -118,9 +127,12 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
|
||||
spl_ir_builder_t ir_builder;
|
||||
spl_ir_builder_init(&ir_builder);
|
||||
spl_ast2ir_init(&a2ir, &ir_builder, &sema);
|
||||
spl_diag_set_stage(&diag, SPL_STAGE_AST2IR);
|
||||
a2ir.diag = &diag;
|
||||
spl_ast2ir_run(&a2ir);
|
||||
if (a2ir.err_count) {
|
||||
printf("ast2ir errors=%d, no output\n", a2ir.err_count);
|
||||
if (spl_diag_has_error(&diag) || spl_diag_has_fatal(&diag)) {
|
||||
spl_diag_summary(&diag);
|
||||
// memory leak
|
||||
spl_ast2ir_drop(&a2ir);
|
||||
spl_sema_drop(&sema);
|
||||
spl_ast_drop(&ast);
|
||||
@@ -134,9 +146,12 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
|
||||
|
||||
spl_ir2vm_t ir2vm;
|
||||
spl_ir2vm_init(&ir2vm, &a2ir.ir->ir, &type, &attr);
|
||||
// ir2vm.diag = &diag;
|
||||
spl_diag_set_stage(&diag, SPL_STAGE_IR2VM);
|
||||
ir2vm.diag = &diag;
|
||||
int rc = spl_ir2vm_run(&ir2vm);
|
||||
if (rc != 0) {
|
||||
printf("ir2vm error %d", rc);
|
||||
if (spl_diag_has_error(&diag) || spl_diag_has_fatal(&diag)) {
|
||||
spl_diag_summary(&diag);
|
||||
return rc;
|
||||
}
|
||||
if (dump == DUMP_VM) {
|
||||
|
||||
Reference in new issue
Block a user