diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -19,6 +19,7 @@ #include <string.h> #include "ast.h" +#include "ast_pretty_printer.h" #include "gas_assembly_generator.h" #include "lexer.h" #include "parser.h" @@ -34,6 +35,14 @@ generate_gas_x86_64_linux(ast_node_t *func) } static void +pretty_print_ast(ast_node_t *ast) +{ + ast_pretty_printer_t printer; + ast_pretty_printer_init(&printer, stdout); + ast_pretty_printer_print_ast(&printer, ast); +} + +static void print_usage(void) { fputs("pipac <filename.pipa>\n", stderr); @@ -58,7 +67,20 @@ main(int argc, char **argv) return EXIT_FAILURE; } - char *filepath = argv[1]; + char *filepath; + bool should_dump_ast = false; + + // TODO: Handle command line arguments properly + if (argc < 3) { + filepath = argv[1]; + } else { + if (strcmp(argv[1], "--ast-dump") != 0) { + print_usage(); + return EXIT_FAILURE; + } + should_dump_ast = true; + filepath = argv[2]; + } lexer_t lexer; lexer_init(&lexer, filepath); @@ -74,7 +96,11 @@ main(int argc, char **argv) return EXIT_FAILURE; } - generate_gas_x86_64_linux(func); + if (should_dump_ast) { + pretty_print_ast(func); + } else { + generate_gas_x86_64_linux(func); + } scope_destroy(scope); ast_node_destroy(func); |