gemstone/src/main.c

68 lines
1.1 KiB
C
Raw Normal View History

2024-05-08 20:10:14 +00:00
#include <ast/ast.h>
#include <stdlib.h>
#include <sys/log.h>
2024-05-13 14:13:49 +00:00
#include <sys/col.h>
#include <lex/util.h>
2024-06-02 22:24:17 +00:00
#include <cfg/opt.h>
#include <compiler.h>
#include <llvm/parser.h>
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: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-06-02 22:24:17 +00:00
void setup(int argc, char *argv[]) {
// setup preample
2024-06-02 22:24:17 +00:00
parse_options(argc, argv);
2024-04-12 15:29:39 +00:00
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
// actual setup
AST_init();
2024-05-07 11:04:22 +00:00
col_init();
2024-05-13 14:13:49 +00:00
lex_init();
2024-05-13 14:13:49 +00:00
DEBUG("finished starting up gemstone...");
}
2024-05-31 19:25:37 +00:00
int main(int argc, char *argv[]) {
2024-06-02 22:24:17 +00:00
if (argc <= 1) {
print_help();
exit(1);
}
setup(argc, argv);
2024-05-31 19:25:37 +00:00
2024-06-03 08:14:25 +00:00
if (is_option_set("help")) {
print_help();
exit(0);
}
2024-06-03 09:08:25 +00:00
if (is_option_set("version")) {
printf("Running GSC version %s\n", GSC_VERSION);
exit(0);
}
if (is_option_set("list-targets")) {
list_available_targets();
exit(0);
}
2024-06-02 22:24:17 +00:00
run_compiler();
return 0;
2024-05-08 20:10:14 +00:00
}