# HG changeset patch # User William Astle # Date 1407297863 21600 # Node ID 5d401d1eb3e922bd77206339f85fa1e227aff0ed # Parent 3b5a45c6ab9296d48a718daf8a0a10e5caa530ce Allow disabling debugging messages. Add test for LWASM_NODEBUG symbol to disable compiling the actual debug message handling code. Also, prevent building the debug message arguments if the debug level is not going to display the message anyway. This comes at the possible expense of larger code due to wrapping the debug_mesage() function in a macro that tests the debug level directly. This should prevent calling expensive things like building a dump of an expression when it is not required. diff -r 3b5a45c6ab92 -r 5d401d1eb3e9 lwasm/debug.c --- a/lwasm/debug.c Sat Aug 02 10:08:01 2014 -0600 +++ b/lwasm/debug.c Tue Aug 05 22:04:23 2014 -0600 @@ -19,6 +19,8 @@ this program. If not, see . */ +#ifndef LWASM_NODEBUG + #include #include #include @@ -72,7 +74,7 @@ } } -void debug_message(asmstate_t *as, int level, const char *fmt, ...) +void real_debug_message(asmstate_t *as, int level, const char *fmt, ...) { va_list args; @@ -90,3 +92,5 @@ va_end(args); } + +#endif diff -r 3b5a45c6ab92 -r 5d401d1eb3e9 lwasm/lwasm.h --- a/lwasm/lwasm.h Sat Aug 02 10:08:01 2014 -0600 +++ b/lwasm/lwasm.h Tue Aug 05 22:04:23 2014 -0600 @@ -358,9 +358,15 @@ #endif -extern void debug_message(asmstate_t *as, int level, const char *fmt, ...); +#ifdef LWASM_NODEBUG +#define debug_message(...) +#define dump_state(...) +#else +extern void real_debug_message(asmstate_t *as, int level, const char *fmt, ...); extern void dump_state(asmstate_t *as); +#define debug_message(as,level,...) do { asmstate_t *ras = (as); int rlevel = (level); if (ras->debug_level >= rlevel) { real_debug_message(ras, rlevel, __VA_ARGS__); } } while (0) +#endif #define OPLEN(op) (((op)>0xFF)?2:1) #define CURPRAGMA(l,p) (((l) && ((l)->pragmas & (p))) ? 1 : 0) diff -r 3b5a45c6ab92 -r 5d401d1eb3e9 lwasm/main.c --- a/lwasm/main.c Sat Aug 02 10:08:01 2014 -0600 +++ b/lwasm/main.c Tue Aug 05 22:04:23 2014 -0600 @@ -102,10 +102,14 @@ break; case 'd': +#ifdef LWASM_NODEBUG + fprintf(stderr, "This binary has been built without debugging message support\n"); +#else if (!arg) as -> debug_level = 50; else as -> debug_level = atoi(arg); +#endif break; case 'l':