summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-07 03:09:38 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-07 03:11:03 +0800
commitcbc11e44f08cfa48f199bc79377c45839d39f96b (patch)
tree40dd49ec47561144e401d1fba47f564ff1d722c9
parent52ddbb128bba155818a75741b48615c5793b59c3 (diff)
downloadcompiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.tar
compiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.tar.gz
compiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.tar.bz2
compiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.tar.lz
compiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.tar.xz
compiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.tar.zst
compiler2015-cbc11e44f08cfa48f199bc79377c45839d39f96b.zip
Allow dumping symbol table via an environment variable
-rw-r--r--src/main.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 6af6c5e..36841a8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -71,7 +71,20 @@ int main (int argc, char **argv)
CcmmcSymbolTable table_struct;
state->table = &table_struct;
ccmmc_symbol_table_init(state->table);
- if (ccmmc_semantic_check(state->ast, state->table))
+
+ bool check_succeeded = ccmmc_semantic_check(state->ast, state->table);
+ const char *dump_symbol = getenv("CCMMC_DUMP_SYMBOL");
+ if (dump_symbol != NULL && *dump_symbol != '\0') {
+ CcmmcSymbolScope *scope = state->table->all;
+ for (unsigned int i = 0; scope != NULL; scope = scope->all_next, i++) {
+ if (i == 0)
+ puts(" * Global Scope *");
+ else
+ printf(" * Scope %u *\n", i);
+ ccmmc_draw_symbol_scope(stdout, scope);
+ }
+ }
+ if (check_succeeded)
puts("Parsing completed. No errors found.");
else
exit(1);