mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-27 08:10:07 +08:00
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>
This commit is contained in:
parent
82667ff5d3
commit
fc0c1281db
@ -42,6 +42,11 @@ FIND = find
|
||||
O = @OBJEXT@
|
||||
X = @EXEEXT@
|
||||
|
||||
# Debug stuff
|
||||
ifeq ($(TRACE),1)
|
||||
CFLAGS += -DNASM_TRACE
|
||||
endif
|
||||
|
||||
.SUFFIXES: .c .i .s .$(O) .1 .man
|
||||
|
||||
.PHONY: all doc rdf install clean distclean cleaner spotless install_rdf test
|
||||
|
51
preproc.c
51
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user