2024-05-08 20:10:14 +00:00
|
|
|
#include <ast/ast.h>
|
2024-04-12 15:28:20 +00:00
|
|
|
#include <stdlib.h>
|
2024-04-12 15:24:12 +00:00
|
|
|
#include <sys/log.h>
|
2024-05-07 11:04:22 +00:00
|
|
|
#include <yacc/parser.tab.h>
|
2024-05-13 14:13:49 +00:00
|
|
|
#include <sys/col.h>
|
|
|
|
#include <lex/util.h>
|
2024-02-04 15:23:32 +00:00
|
|
|
|
2024-04-12 15:24:12 +00:00
|
|
|
#define LOG_LEVEL LOG_LEVEL_DEBUG
|
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
extern FILE *yyin;
|
2024-05-14 12:03:45 +00:00
|
|
|
AST_NODE_PTR root;
|
2024-04-26 14:21:54 +00:00
|
|
|
|
2024-04-12 15:29:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Log a debug message to inform about beginning exit procedures
|
2024-05-07 11:04:22 +00:00
|
|
|
*
|
2024-04-12 15:29:39 +00:00
|
|
|
*/
|
2024-05-08 20:10:14 +00:00
|
|
|
void notify_exit(void) { DEBUG("Exiting gemstone..."); }
|
2024-04-12 15:28:20 +00:00
|
|
|
|
2024-04-23 13:27:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Closes File after compiling.
|
2024-05-07 11:04:22 +00:00
|
|
|
*
|
2024-04-23 13:27:11 +00:00
|
|
|
*/
|
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
void close_file(void) {
|
|
|
|
if (NULL != yyin) {
|
|
|
|
fclose(yyin);
|
|
|
|
}
|
2024-04-23 13:27:11 +00:00
|
|
|
}
|
|
|
|
|
2024-04-12 15:29:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Run compiler setup here
|
2024-05-07 11:04:22 +00:00
|
|
|
*
|
2024-04-12 15:29:39 +00:00
|
|
|
*/
|
2024-05-08 20:10:14 +00:00
|
|
|
void setup(void) {
|
|
|
|
// setup preample
|
2024-04-12 15:29:39 +00:00
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
log_init();
|
|
|
|
DEBUG("starting gemstone...");
|
2024-04-12 15:24:12 +00:00
|
|
|
|
2024-05-07 11:04:22 +00:00
|
|
|
#if LOG_LEVEL <= LOG_LEVEL_DEBUG
|
2024-05-08 20:10:14 +00:00
|
|
|
atexit(¬ify_exit);
|
2024-05-07 11:04:22 +00:00
|
|
|
#endif
|
2024-04-12 15:28:20 +00:00
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
// actual setup
|
|
|
|
AST_init();
|
2024-05-07 11:04:22 +00:00
|
|
|
|
2024-05-13 14:13:49 +00:00
|
|
|
col_init();
|
|
|
|
|
|
|
|
lex_init();
|
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
DEBUG("finished starting up gemstone...");
|
2024-04-22 11:41:37 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 12:25:49 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
setup();
|
|
|
|
atexit(close_file);
|
2024-05-07 11:04:22 +00:00
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
// Check for file input as argument
|
|
|
|
if (2 != argc) {
|
|
|
|
INFO("Usage: %s <filename>\n", argv[0]);
|
|
|
|
PANIC("No File could be found");
|
|
|
|
}
|
2024-05-07 11:04:22 +00:00
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
// filename as first argument
|
|
|
|
char *filename = argv[1];
|
2024-04-23 12:25:49 +00:00
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
FILE *file = fopen(filename, "r");
|
2024-04-26 14:21:54 +00:00
|
|
|
|
2024-05-08 20:10:14 +00:00
|
|
|
if (NULL == file) {
|
|
|
|
PANIC("File couldn't be opened!");
|
|
|
|
}
|
|
|
|
yyin = file;
|
2024-04-30 12:01:00 +00:00
|
|
|
|
2024-05-14 12:03:45 +00:00
|
|
|
root = AST_new_node(AST_Module, NULL);
|
2024-05-08 20:10:14 +00:00
|
|
|
yyparse();
|
2024-04-22 10:53:48 +00:00
|
|
|
|
2024-05-14 12:03:45 +00:00
|
|
|
FILE *output = fopen("test.txt", "w");
|
2024-05-14 12:57:15 +00:00
|
|
|
AST_fprint_graphviz(output, root);
|
2024-05-14 12:03:45 +00:00
|
|
|
fclose(output);
|
2024-05-15 15:03:18 +00:00
|
|
|
AST_delete_node(root);
|
2024-05-08 20:10:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|