gemstone/src/main.c

79 lines
1.2 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <sys/log.h>
2024-05-07 11:04:22 +00:00
#include <yacc/parser.tab.h>
#include <ast/ast.h>
2024-02-04 15:23:32 +00:00
#define LOG_LEVEL LOG_LEVEL_DEBUG
2024-04-26 14:21:54 +00:00
extern FILE* yyin;
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
*/
void notify_exit(void)
{
DEBUG("Exiting gemstone...");
}
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-04-26 14:21:54 +00:00
void close_file(void)
2024-04-23 13:27:11 +00:00
{
2024-04-26 14:21:54 +00:00
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
*/
void setup(void)
{
2024-04-12 15:29:39 +00:00
// setup preample
log_init();
DEBUG("starting gemstone...");
2024-05-07 11:04:22 +00:00
#if LOG_LEVEL <= LOG_LEVEL_DEBUG
atexit(&notify_exit);
2024-05-07 11:04:22 +00:00
#endif
2024-04-12 15:29:39 +00:00
// actual setup
2024-05-07 11:04:22 +00:00
AST_init();
DEBUG("finished starting up gemstone...");
}
int main(int argc, char *argv[]) {
setup();
2024-04-26 14:21:54 +00:00
atexit(close_file);
2024-05-07 11:04:22 +00:00
// Check for file input as argument
if (2 != argc)
{
2024-04-23 13:27:11 +00:00
INFO("Usage: %s <filename>\n", argv[0]);
PANIC("No File could be found");
}
2024-05-07 11:04:22 +00:00
// filename as first argument
char *filename = argv[1];
2024-04-26 14:21:54 +00:00
FILE *file = fopen(filename, "r");
2024-05-07 11:04:22 +00:00
if (NULL == file)
{
PANIC("File couldn't be opened!");
}
yyin = file;
2024-05-07 11:04:22 +00:00
yyparse();
2024-02-04 15:23:32 +00:00
return 0;
2024-05-07 11:04:22 +00:00
}