aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-04-19 10:41:32 -0300
committerBad Diode <bd@badd10de.dev>2022-04-19 10:41:32 -0300
commitc69929cc501203829082b810bafe75a22947e00c (patch)
tree46dceba9e657a424626ab97f510b49d3b2b889cf /src/main.c
parent7cf1451ab52586ed9c4eeae1b1ec3b4ebaa83393 (diff)
downloadbdl-c69929cc501203829082b810bafe75a22947e00c.tar.gz
bdl-c69929cc501203829082b810bafe75a22947e00c.zip
Add viz for symbol tables
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 56c36d7..fc991d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,6 +17,7 @@ typedef enum ExecMode {
17 PRINT_LEX, 17 PRINT_LEX,
18 PRINT_PARSE, 18 PRINT_PARSE,
19 PRINT_SEMANTIC, 19 PRINT_SEMANTIC,
20 PRINT_SYMTABLES,
20} ExecMode; 21} ExecMode;
21 22
22static ExecMode mode = RUN_NORMAL; 23static ExecMode mode = RUN_NORMAL;
@@ -46,12 +47,18 @@ process_source(const StringView *source, const char *file_name) {
46 check_errors(file_name); 47 check_errors(file_name);
47 if (mode == PRINT_PARSE) { 48 if (mode == PRINT_PARSE) {
48 viz_ast(roots); 49 viz_ast(roots);
50 return;
49 } 51 }
50 52
51 // Symbol table generation and type checking. 53 // Symbol table generation and type checking.
52 ParseTree *parse_tree = semantic_analysis(roots); 54 ParseTree *parse_tree = semantic_analysis(roots);
53 if (mode == PRINT_SEMANTIC) { 55 if (mode == PRINT_SEMANTIC) {
54 viz_ast(parse_tree->roots); 56 viz_ast(parse_tree->roots);
57 return;
58 }
59 if (mode == PRINT_SYMTABLES) {
60 viz_symtables(parse_tree->scopes);
61 return;
55 } 62 }
56} 63}
57 64
@@ -116,7 +123,7 @@ print_usage(void) {
116 printf("Usage: %s [options] <filename filename ...>\n", BIN_NAME); 123 printf("Usage: %s [options] <filename filename ...>\n", BIN_NAME);
117 printf("\n"); 124 printf("\n");
118 printf("\t-h \t\tShow usage.\n"); 125 printf("\t-h \t\tShow usage.\n");
119 printf("\t-p [l | p | s]\tPrint mode for [l]exing, [p]arsing or [s]emantic analysis\n"); 126 printf("\t-p [l|p|s|t]\tPrint mode for [l]exing, [p]arsing, [s]emantic analysis, symbol [t]ables\n");
120 printf("\n"); 127 printf("\n");
121} 128}
122 129
@@ -138,6 +145,8 @@ main(int argc, char *argv[]) {
138 mode = PRINT_PARSE; 145 mode = PRINT_PARSE;
139 } else if (optarg[0] == 's' && optarg[1] == '\0') { 146 } else if (optarg[0] == 's' && optarg[1] == '\0') {
140 mode = PRINT_SEMANTIC; 147 mode = PRINT_SEMANTIC;
148 } else if (optarg[0] == 't' && optarg[1] == '\0') {
149 mode = PRINT_SYMTABLES;
141 } else { 150 } else {
142 print_usage(); 151 print_usage();
143 return EXIT_FAILURE; 152 return EXIT_FAILURE;