From 8f754f8b13e55e4bb92d72f105c5aaaba1754b7d Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 19 Nov 2023 18:41:55 +0200 Subject: start working on instruction lowering --- src/compiler.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/compiler.c') diff --git a/src/compiler.c b/src/compiler.c index 5ad67c3..8801c7f 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /** @@ -163,18 +164,40 @@ out: return res; } -int compile(const char *file) { +int compile(const char *input, const char *output) { int ret = -1; struct scope *root = NULL; - if (process_file(&root, 0, file)) { + if (process_file(&root, 0, input)) { destroy_scope(root); - error("compilation of %s stopped due to errors", file); + error("compilation of %s stopped due to errors", input); return ret; } ret = actualize_main(root); - /** @todo backend */ + if (ret) { + destroy_scope(root); + destroy_ast_nodes(); + error("compilation of %s stopped due to errors", input); + return ret; + } + + struct ops *ops = create_ops(); + ret = lower_ops(root, ops); destroy_scope(root); destroy_ast_nodes(); - return ret; + + if (ret) { + destroy_ops(ops); + error("compilation of %s stopped due to errors", input); + return ret; + } + + ret = analyze_lifetime(ops); + if (ret) { + destroy_ops(ops); + error("compilation of %s stopped due to errors", input); + return ret; + } + + return print_asm(ops, output); } -- cgit v1.3