# HG changeset patch # User lost@l-w.ca # Date 1279169216 21600 # Node ID 027d7fbcdcfcf8cb651f9644f64e75a42870b8a7 # Parent fbb7bfed80768cd10ade41a57a1f1f4a44c1e15e Basic symbol table output; needs work for non-constant symbols diff -r fbb7bfed8076 -r 027d7fbcdcfc lwasm/list.c --- a/lwasm/list.c Wed Jul 14 22:33:55 2010 -0600 +++ b/lwasm/list.c Wed Jul 14 22:46:56 2010 -0600 @@ -30,6 +30,8 @@ #include "lwasm.h" #include "instab.h" +void list_symbols(asmstate_t *as, FILE *of); + /* Do listing */ @@ -132,4 +134,7 @@ fprintf(of, "\n"); } } + + if (as -> flags & FLAG_SYMBOLS) + list_symbols(as, of); } diff -r fbb7bfed8076 -r 027d7fbcdcfc lwasm/lwasm.h --- a/lwasm/lwasm.h Wed Jul 14 22:33:55 2010 -0600 +++ b/lwasm/lwasm.h Wed Jul 14 22:46:56 2010 -0600 @@ -62,9 +62,10 @@ enum lwasm_flags_e { - FLAG_NONE = 0, FLAG_LIST = 0x0001, - FLAG_DEPEND = 0x0002 + FLAG_DEPEND = 0x0002, + FLAG_SYMBOLS = 0x004, + FLAG_NONE = 0 }; enum lwasm_pragmas_e diff -r fbb7bfed8076 -r 027d7fbcdcfc lwasm/main.c --- a/lwasm/main.c Wed Jul 14 22:33:55 2010 -0600 +++ b/lwasm/main.c Wed Jul 14 22:46:56 2010 -0600 @@ -46,6 +46,7 @@ { "debug", 'd', "LEVEL", OPTION_ARG_OPTIONAL, "Set debug mode"}, { "format", 'f', "TYPE", 0, "Select output format: decb, raw, obj, os9"}, { "list", 'l', "FILE", OPTION_ARG_OPTIONAL, "Generate list [to FILE]"}, + { "symbols", 's', 0, OPTION_ARG_OPTIONAL, "Generate symbol list in listing, no effect without --list"}, { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"}, { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"}, { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" }, @@ -90,6 +91,10 @@ as -> list_file = lw_strdup(arg); as -> flags |= FLAG_LIST; break; + + case 's': + as -> flags |= FLAG_SYMBOLS; + break; case 'b': as -> output_format = OUTPUT_DECB; diff -r fbb7bfed8076 -r 027d7fbcdcfc lwasm/symbol.c --- a/lwasm/symbol.c Wed Jul 14 22:33:55 2010 -0600 +++ b/lwasm/symbol.c Wed Jul 14 22:46:56 2010 -0600 @@ -21,6 +21,7 @@ #include +#include #include #include @@ -166,3 +167,30 @@ return s; } + +void list_symbols(asmstate_t *as, FILE *of) +{ + struct symtabe *s; + + fprintf(of, "\nSymbol Table:\n"); + + for (s = as -> symtab.head; s; s = s -> next) + { + fputc('[', of); + if (s -> flags & symbol_flag_set) + fputc('S', of); + else + fputc(' ', of); + if (lw_expr_istype(s -> value, lw_expr_type_int)) + fputc('G', of); + else + fputc(' ', of); + fputc(']', of); + fputc(' ', of); + fprintf(of, "%-32s ", s -> symbol); + if (lw_expr_istype(s -> value, lw_expr_type_int)) + fprintf(of, "%04X\n", lw_expr_intval(s -> value)); + else + fprintf(of, "%s\n", lw_expr_print(s -> value)); + } +}