stage1 实现部分ast2ir内容并重构stage0 引入并重构ir2vm 构建系统修改部分
This commit is contained in:
1 parent
3d57260f3f
commit
34df303b56
17 files changed
+636
-1800
No files matched your search
+34
-18
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "spl_ast.h"
|
||||
#include "spl_ast2ir.h"
|
||||
// #include "spl_ir2vm.h"
|
||||
#include "spl_ir2vm.h"
|
||||
#include "spl_lexer.h"
|
||||
#include "spl_sema.h"
|
||||
#include "spl_tok.h"
|
||||
@@ -23,6 +23,7 @@ typedef enum {
|
||||
DUMP_AST,
|
||||
DUMP_SEMA,
|
||||
DUMP_IR,
|
||||
DUMP_VM,
|
||||
} dump_t;
|
||||
|
||||
static char *read_file(const char *path, long *out_len) {
|
||||
@@ -68,6 +69,8 @@ static void dump_tokens(spl_tok_vec_t toks) {
|
||||
|
||||
static int compile_spl(const char *src, const char *fname, const char *outpath, int gen_debug,
|
||||
dump_t dump) {
|
||||
(void)gen_debug;
|
||||
|
||||
spl_tok_vec_t toks = spl_lex(src, fname);
|
||||
if (dump == DUMP_TOKEN) {
|
||||
dump_tokens(toks);
|
||||
@@ -126,16 +129,25 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// spl_ir2vm_t ir2vm;
|
||||
// spl_ir2vm_init(&ir2vm, &a2ir.ir, &sema.type);
|
||||
// int rc = spl_ir2vm_run(&ir2vm, outpath);
|
||||
// if (gen_debug && rc == 0)
|
||||
// gen_debug_map(outpath, &ast, &a2ir.ir, &ir2vm);
|
||||
// spl_ir2vm_drop(&ir2vm);
|
||||
// spl_ast2ir_drop(&a2ir);
|
||||
// spl_sema_drop(&sema);
|
||||
// spl_ast_drop(&ast);
|
||||
// return rc ? 1 : 0;
|
||||
spl_ir2vm_t ir2vm;
|
||||
spl_ir2vm_init(&ir2vm, &a2ir.ir->ir, sema.type);
|
||||
int rc = spl_ir2vm_run(&ir2vm);
|
||||
if (rc != 0) {
|
||||
printf("ir2vm error %d", rc);
|
||||
return rc;
|
||||
}
|
||||
if (dump == DUMP_VM) {
|
||||
spl_prog_dump(&ir2vm.prog);
|
||||
// memory leak
|
||||
return 0;
|
||||
}
|
||||
|
||||
spl_prog_store_to_file(outpath, &ir2vm.prog);
|
||||
|
||||
spl_ir2vm_drop(&ir2vm);
|
||||
spl_ast2ir_drop(&a2ir);
|
||||
spl_sema_drop(&sema);
|
||||
spl_ast_drop(&ast);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -146,7 +158,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
|
||||
LOG_INFO("splc0 <in> <out> compile (.spl -> .sir, stage B)");
|
||||
LOG_INFO("splc0 --dump <flags> <file> dump: lex,ast,sema,ir");
|
||||
LOG_INFO("splc0 --dump <flags> <file> dump: lex,ast,sema,ir,vm,none");
|
||||
return 0;
|
||||
}
|
||||
int argi = 1;
|
||||
@@ -165,15 +177,19 @@ int main(int argc, char **argv) {
|
||||
const char *flags = argv[argi + 1];
|
||||
if (strstr(flags, "lex") != NULL) {
|
||||
dump = DUMP_TOKEN;
|
||||
}
|
||||
if (strstr(flags, "ast") != NULL) {
|
||||
} else if (strstr(flags, "ast") != NULL) {
|
||||
dump = DUMP_AST;
|
||||
}
|
||||
if (strstr(flags, "sema") != NULL) {
|
||||
} else if (strstr(flags, "sema") != NULL) {
|
||||
dump = DUMP_SEMA;
|
||||
}
|
||||
if (strstr(flags, "ir") != NULL) {
|
||||
} else if (strstr(flags, "ir") != NULL) {
|
||||
dump = DUMP_IR;
|
||||
} else if (strstr(flags, "vm") != NULL) {
|
||||
dump = DUMP_VM;
|
||||
} else if (strstr(flags, "none") != NULL) {
|
||||
dump = DUMP_NONE;
|
||||
} else {
|
||||
Panic("--dump unknown flags");
|
||||
return 1;
|
||||
}
|
||||
argi += 2;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user