summaryrefslogtreecommitdiff
path: root/preproc.c
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2011-06-25 19:51:44 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2011-06-25 19:51:44 +0400
commitfc0c1281dbd87b4e7b84ee31b1229466f982a927 (patch)
treefcd86e581b7db8e3b7899f98704294ca850f5fb3 /preproc.c
parent82667ff5d309667082415c1c6f8b9096021985d8 (diff)
downloadnasm-fc0c1281dbd87b4e7b84ee31b1229466f982a927.tar.gz
nasm-fc0c1281dbd87b4e7b84ee31b1229466f982a927.tar.bz2
nasm-fc0c1281dbd87b4e7b84ee31b1229466f982a927.zip
preproc: Add tokenization tracing
It's a bit more than that, also TRACE=1 make flag added to run this facility on and off at compiling time. Debug feature only, doesn't affect regular users. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'preproc.c')
-rw-r--r--preproc.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/preproc.c b/preproc.c
index 42c248d..0614400 100644
--- a/preproc.c
+++ b/preproc.c
@@ -501,20 +501,58 @@ static ExpInv *new_ExpInv(int exp_type, ExpDef *ed);
#ifdef NASM_TRACE
-#define dump_token(t) raw_dump_token(t, __FILE__, __LINE__, __func__);
-static void raw_dump_token(Token *token, const char *file, int line, const char *func)
+#define stringify(x) #x
+
+#define nasm_trace(msg, ...) printf("(%s:%d): " msg "\n", __func__, __LINE__, __VA_ARGS__)
+#define nasm_dump_token(t) nasm_raw_dump_token(t, __FILE__, __LINE__, __func__);
+
+/* FIXME: we really need some compound type here instead of inplace code */
+static const char *nasm_get_tok_type_str(enum pp_token_type type)
+{
+#define SWITCH_TOK_NAME(type) \
+ case (type): \
+ return stringify(type)
+
+ switch (type) {
+ SWITCH_TOK_NAME(TOK_NONE);
+ SWITCH_TOK_NAME(TOK_WHITESPACE);
+ SWITCH_TOK_NAME(TOK_COMMENT);
+ SWITCH_TOK_NAME(TOK_ID);
+ SWITCH_TOK_NAME(TOK_PREPROC_ID);
+ SWITCH_TOK_NAME(TOK_STRING);
+ SWITCH_TOK_NAME(TOK_NUMBER);
+ SWITCH_TOK_NAME(TOK_FLOAT);
+ SWITCH_TOK_NAME(TOK_SMAC_END);
+ SWITCH_TOK_NAME(TOK_OTHER);
+ SWITCH_TOK_NAME(TOK_INTERNAL_STRING);
+ SWITCH_TOK_NAME(TOK_PREPROC_Q);
+ SWITCH_TOK_NAME(TOK_PREPROC_QQ);
+ SWITCH_TOK_NAME(TOK_PASTE);
+ SWITCH_TOK_NAME(TOK_INDIRECT);
+ SWITCH_TOK_NAME(TOK_SMAC_PARAM);
+ SWITCH_TOK_NAME(TOK_MAX);
+ }
+
+ return NULL;
+}
+
+static void nasm_raw_dump_token(Token *token, const char *file, int line, const char *func)
{
printf("---[%s (%s:%d): %p]---\n", func, file, line, (void *)token);
if (token) {
Token *t;
list_for_each(t, token) {
if (t->text)
- printf("'%s' ", t->text);
+ printf("'%s'(%s) ", t->text,
+ nasm_get_tok_type_str(t->type));
}
- printf("\n");
+ printf("\n\n");
}
}
+#else
+#define nasm_trace(msg, ...)
+#define nasm_dump_token(t)
#endif
/*
@@ -947,6 +985,8 @@ static Token *tokenize(char *line)
Token *t, **tail = &list;
bool verbose = true;
+ nasm_trace("Tokenize for '%s'", line);
+
if ((defining != NULL) && (defining->ignoring == true)) {
verbose = false;
}
@@ -1190,6 +1230,9 @@ static Token *tokenize(char *line)
}
line = p;
}
+
+ nasm_dump_token(list);
+
return list;
}