2023-08-27 19:48:06 +03:00
|
|
|
#include<errno.h>
|
|
|
|
#include<string.h>
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
#include"lexer.h"
|
|
|
|
#include"parse.h"
|
|
|
|
#include"ntc.h"
|
|
|
|
#include"reporting.h"
|
|
|
|
#include"cg.h"
|
2024-02-13 21:33:49 +02:00
|
|
|
#include"dumberdowner.h"
|
2023-08-27 19:48:06 +03:00
|
|
|
|
|
|
|
static int argc;
|
|
|
|
static char **argv;
|
|
|
|
|
|
|
|
const char* ntc_get_arg(const char *name) {
|
|
|
|
for(int i = 1; i < argc; i++) {
|
|
|
|
if(strstr(argv[i], name) == argv[i]) {
|
|
|
|
return argv[i] + strlen(name) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc_, char **argv_) {
|
|
|
|
argc = argc_;
|
|
|
|
argv = argv_;
|
|
|
|
|
|
|
|
const char *in = ntc_get_arg("in");
|
|
|
|
|
|
|
|
FILE *f = in ? fopen(in, "rb") : stdin;
|
|
|
|
|
|
|
|
Token *tokens = nct_lex(f);
|
|
|
|
|
|
|
|
if(in) fclose(f);
|
|
|
|
|
|
|
|
AST *chunk = nct_parse(tokens);
|
|
|
|
|
|
|
|
free(tokens);
|
|
|
|
|
2024-11-25 17:36:03 +02:00
|
|
|
fputs("/* === Original AST === */\n", stderr);
|
|
|
|
fputs(ast_dump(chunk), stderr);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
|
2024-02-13 21:33:49 +02:00
|
|
|
dumben_go(chunk);
|
|
|
|
|
2024-11-25 17:36:03 +02:00
|
|
|
fputs("\n/* === Dumbified === */\n", stderr);
|
|
|
|
fputs(ast_dump(chunk), stderr);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
|
|
|
|
while(!cg_go(chunk));
|
2023-08-27 19:48:06 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|