Mercurial > hg-old > index.cgi
changeset 38:9bd584bb6296
Added debugging message infrastructure
author | lost |
---|---|
date | Sat, 03 Jan 2009 04:53:49 +0000 |
parents | 538e15927776 |
children | efa19ec69df9 |
files | src/lwasm.c src/lwasm.h src/main.c src/parse.c |
diffstat | 4 files changed, 26 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lwasm.c Sat Jan 03 04:20:49 2009 +0000 +++ b/src/lwasm.c Sat Jan 03 04:53:49 2009 +0000 @@ -31,6 +31,8 @@ #include "util.h" #include "expr.h" +int debug_level = 0; + int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...) { lwasm_error_t *e; @@ -179,5 +181,21 @@ st.as = as; st.l = l; + debug_message(2, "Evaluate expression: %s", inp); + return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st)); } + +void debug_message(int level, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (debug_level >= level) + { + fprintf(stderr, "DEBUG %d: ", level); + vfprintf(stderr, fmt, args); + fputc('\n', stderr); + } + va_end(args); +}
--- a/src/lwasm.h Sat Jan 03 04:20:49 2009 +0000 +++ b/src/lwasm.h Sat Jan 03 04:53:49 2009 +0000 @@ -82,7 +82,6 @@ const char *infile; // input file const char *outfile; // output file const char *listfile; // output listing file - int debug; // debug mode int outformat; // output format type char **filelist; // files that have been read int filelistlen; // number of files in the list @@ -96,7 +95,10 @@ #define __lwasm_E__ #endif +__lwasm_E__ int debug_level; + __lwasm_E__ int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...); +__lwasm_E__ void debug_message(int level, const char *fmt, ...); __lwasm_E__ void lwasm_emit(asmstate_t *as, lwasm_line_t *l, int b); __lwasm_E__ void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o);
--- a/src/main.c Sat Jan 03 04:20:49 2009 +0000 +++ b/src/main.c Sat Jan 03 04:53:49 2009 +0000 @@ -58,7 +58,7 @@ case 'd': // debug - as -> debug++; + debug_level++; break; case 'l':
--- a/src/parse.c Sat Jan 03 04:20:49 2009 +0000 +++ b/src/parse.c Sat Jan 03 04:53:49 2009 +0000 @@ -62,13 +62,14 @@ l -> sym = sym; // have a symbol; now determine if it is valid and register it // at the current address of the line + debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr); if (lwasm_register_symbol(as, l, sym, as -> addr) < 0) l -> sym = NULL; } else { while (*p && isspace(*p)) - (*p)++; + p++; if (!*p) { as -> context += 1; @@ -95,6 +96,8 @@ memcpy(opc, p, p2 - p); opc[p2 - p] = '\0'; + debug_message(2, "Found operation code: '%s'", opc); + // skip intervening whitespace if present while (*p2 && isspace(*p2)) p2++;