From 5cbd84f9b46384ee08da255db816a0971fd5bf3f Mon Sep 17 00:00:00 2001 From: Richard Kistruck Date: Tue, 7 Aug 2007 19:09:43 +0100 Subject: Mps br/diagtag: diag.c: support tagging of diagnostics, and avoid having to say DIAG_STREAM every time, with new macros: DIAG_SINGLEF, DIAG_FIRSTF, DIAG_MOREF, DIAG_END. mpm.c: new WriteF_firstformat_v required by DIAG_MOREF. Copied from Perforce Change: 163059 ServerID: perforce.ravenbrook.com --- mps/code/mpm.h | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'mps/code/mpm.h') diff --git a/mps/code/mpm.h b/mps/code/mpm.h index 8c1a61617ca..02bb0659915 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -144,6 +144,8 @@ extern Shift SizeFloorLog2(Size size); extern Res WriteF(mps_lib_FILE *stream, ...); extern Res WriteF_v(mps_lib_FILE *stream, va_list args); +extern Res WriteF_firstformat_v(mps_lib_FILE *stream, + const char *firstformat, va_list args); /* Miscellaneous support -- see */ @@ -953,6 +955,18 @@ extern void StackProbe(Size depth); Bool DiagIsOn(void); mps_lib_FILE *DiagStream(void); + +/* Diag*F functions -- formatted diagnostic output + * + * Note: do not call these directly; use the DIAG_*F macros below. + */ + +extern void DiagSingleF(const char *tag, ...); +extern void DiagFirstF(const char *tag, ...); +extern void DiagMoreF(const char *format, ...); +extern void DiagEnd(const char *tag); + + #if defined(DIAG_WITH_STREAM_AND_WRITEF) /* Diagnostic Calculation and Output */ @@ -961,17 +975,36 @@ mps_lib_FILE *DiagStream(void); #define DIAG(s) BEGIN \ s \ END -/* - * Note the macro argument args should have parens around it (in the - * invocation); it is a variable number of arguments that we pass - * to another function. - * That makes this macro unclean in all sorts of ways. + + +/* DIAG_*F macros -- formatted diagnostic output + * + * Note: when invoking these macros, the value passed as macro + * argument "args" might contain commas; it must therefore be + * enclosed in parentheses. That makes these macros unclean in + * all sorts of ways. */ + #define DIAG_WRITEF(args) DIAG( \ if(DiagIsOn()) { \ WriteF args; \ } \ ) +#define DIAG_SINGLEF(args) DIAG( \ + DiagSingleF args; \ +) +#define DIAG_FIRSTF(args) DIAG( \ + DiagFirstF args; \ +) +#define DIAG_MOREF(args) DIAG( \ + DiagMoreF args; \ +) + +/* Note: extra parens *not* required when invoking DIAG_END */ +#define DIAG_END(tag) DIAG( \ + DiagEnd(tag); \ +) + #else @@ -980,6 +1013,12 @@ mps_lib_FILE *DiagStream(void); #define DIAG(s) BEGIN END #define DIAG_WRITEF(args) BEGIN END +/* DIAG_*F macros */ +#define DIAG_SINGLEF(args) BEGIN END +#define DIAG_FIRSTF(args) BEGIN END +#define DIAG_MOREF(args) BEGIN END +#define DIAG_END(tag) BEGIN END + #endif /* ------------ DIAG_WITH_PRINTF --------------- */ -- cgit v1.2.1