18 int yyerror(const char*);
24 static char _filename_to_del
[PATH_MAX
];
25 void kill_at_exit(void)
27 unlink(_filename_to_del
);
30 /// Preprocess a file and return a pointer to the preprocessed data
31 FILE* preprocess_file(const char* filename
)
35 char cmdline
[L_tmpnam
+strlen(filename
)+16];
40 throw runtime_error("unable to allocate temporary file");
42 strcpy(tmp2
, getenv("TEMP"));
46 sprintf(cmdline
, "cpp \"%s\" -o \"%s\"", filename
, ptr
);
47 LOG("running cpp: %s\n", cmdline
);
48 if (system(cmdline
) != 0)
49 throw runtime_error("unable to call cpp");
50 strcpy(_filename_to_del
, ptr
);
52 return fopen(ptr
, "r");
55 int main(int argc
, char** argv
)
59 throw runtime_error("bad command line, usage: bosc <filename>");
61 if (strcmp("--", argv
[1]) == 0)
64 FILE* test
= fopen(argv
[1], "r");
65 if (test
) fclose(test
);
66 else throw runtime_error("cannot open input file");
67 yyin
= preprocess_file(argv
[1]);
69 throw runtime_error("cannot run cpp");
74 } catch(const runtime_error
& e
) {
75 fprintf(stderr
, "runtime error: %s\n", e
.what());
79 int retval
= yyparse();
82 constant_expression_optimization(root
);
83 if (!tree_check_parents(root
)) {
84 EPRINTF("internal error: AST check failed\n");
85 printf("%s", root
->toString().c_str());
89 validate_tree(pi
, root
);
91 EPRINTF("%d error(s), compilation aborted\n", pi
.errors
);
94 printf("%s", root
->toString().c_str());