#include #include "../lib/dropt/dropt.h" #include "parser.h" #include "compiler.h" int main(int argc, char *argv[]) { dropt_bool showHelp = 0; dropt_bool parseVerbose = 0; uint32_t optimizationLevel = 0; char *inputFilename; int exitCode = EXIT_SUCCESS; dropt_option options[] = { { 'h', "help", "Shows help.", NULL, dropt_handle_bool, &showHelp, dropt_attr_halt }, { 'v', "parse-verbose", "Shows verbose parser output.", NULL, dropt_handle_bool, &parseVerbose }, { 'O', "optimize", "Sets optimization level of the output IR. Must be a value between 0 and 3.", "number", dropt_handle_uint, &optimizationLevel }, { 0 } /* Required sentinel value. */ }; dropt_context *droptContext = dropt_new_context(options); if (droptContext == NULL) { exitCode = EXIT_FAILURE; } else if (argc == 0) { printf("Must supply an input file."); exitCode = EXIT_FAILURE; } else { char** rest = dropt_parse(droptContext, -1, &argv[1]); if (dropt_get_error(droptContext) != dropt_error_none) { fprintf(stderr, "wraith: %s\n", dropt_get_error_message(droptContext)); exitCode = EXIT_FAILURE; } else if (showHelp) { printf("Usage: wraith [options] [--] [input_file]\n\n" "Options:\n"); dropt_print_help(stdout, droptContext, NULL); } else { /* TODO: free AST after compilation */ inputFilename = *rest; if (inputFilename == NULL) { fprintf(stderr, "ERROR: Must provide an input file.\n"); exitCode = EXIT_FAILURE; } else { Node *rootNode; if (Parse(inputFilename, &rootNode, parseVerbose) != 0) { fprintf(stderr, "Parser error.\n"); exitCode = EXIT_FAILURE; } else { exitCode = Build(rootNode, optimizationLevel); } } } } return exitCode; }