comparison lwasm/debug.c @ 338:5d401d1eb3e9

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.
author William Astle <lost@l-w.ca>
date Tue, 05 Aug 2014 22:04:23 -0600
parents 3132b1742eca
children
comparison
equal deleted inserted replaced
337:3b5a45c6ab92 338:5d401d1eb3e9
16 more details. 16 more details.
17 17
18 You should have received a copy of the GNU General Public License along with 18 You should have received a copy of the GNU General Public License along with
19 this program. If not, see <http://www.gnu.org/licenses/>. 19 this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21
22 #ifndef LWASM_NODEBUG
21 23
22 #include <stdio.h> 24 #include <stdio.h>
23 #include <string.h> 25 #include <string.h>
24 #include <stdarg.h> 26 #include <stdarg.h>
25 #include <time.h> 27 #include <time.h>
70 debug_message(as, 100, " WARN: %s", e -> mess); 72 debug_message(as, 100, " WARN: %s", e -> mess);
71 } 73 }
72 } 74 }
73 } 75 }
74 76
75 void debug_message(asmstate_t *as, int level, const char *fmt, ...) 77 void real_debug_message(asmstate_t *as, int level, const char *fmt, ...)
76 { 78 {
77 va_list args; 79 va_list args;
78 80
79 if (as -> debug_level < level) 81 if (as -> debug_level < level)
80 return; 82 return;
88 vfprintf(as -> debug_file, fmt, args); 90 vfprintf(as -> debug_file, fmt, args);
89 fputc('\n', as -> debug_file); 91 fputc('\n', as -> debug_file);
90 92
91 va_end(args); 93 va_end(args);
92 } 94 }
95
96 #endif