aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..173c19b
--- /dev/null
+++ b/main.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "compiler.h"
+#include "node.h"
+
+
+extern FILE *yyin;
+extern int yyparse(void);
+extern struct node *root_node;
+
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <source.c>\n", argv[0]);
+ return 1;
+ }
+ yyin = fopen(argv[1], "r");
+ if (!yyin) {
+ fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+ return 1;
+ }
+
+ int result = yyparse();
+ if(!feof(yyin)) {
+ assert(false);
+ }
+
+ node_print(root_node, stdout, 0);
+ printf("\n");
+
+ struct ir *ir = compile(root_node);
+
+ type_cache_cleanup();
+
+ return result;
+}