core: Introduce a logging macro AVR_LOG()
authorJakob Gruber <jakob.gruber@gmail.com>
Thu, 2 Aug 2012 07:49:34 +0000 (09:49 +0200)
committerJakob Gruber <jakob.gruber@gmail.com>
Sun, 5 Aug 2012 11:00:53 +0000 (13:00 +0200)
This works in conjunction with avr->log to tune out messages we are not
interested in. LOG_ERROR is the default level.

simavr/sim/sim_avr.h

index 737b3ce..db41e41 100644 (file)
@@ -61,6 +61,21 @@ enum {
 #define AVR_DATA_TO_IO(v) ((v) - 32)
 #define AVR_IO_TO_DATA(v) ((v) + 32)
 
+/**
+ * Logging macros and associated log levels.
+ * The current log level is kept in avr->log.
+ */
+enum {
+       LOG_ERROR = 1,
+       LOG_WARNING,
+       LOG_TRACE,
+};
+#define AVR_LOG(avr, level, ...) \
+       do { \
+               if (avr->log >= level) \
+                       fprintf(stdout, __VA_ARGS__); \
+       } while(0)
+
 /*
  * Core states.
  */