Navigation Menu

Skip to content

Commit

Permalink
Cleaned up HLSL parser tracing.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 28, 2009
1 parent 5e5c7be commit b2b145a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
42 changes: 23 additions & 19 deletions misc/lempar.c
Expand Up @@ -6,6 +6,10 @@
#define __MOJOSHADER__ 1
#endif

#if !__MOJOSHADER__
#define LEMON_SUPPORT_TRACING (!defined(NDEBUG))
#endif

/* Driver template for the LEMON parser generator.
** The author disclaims copyright to this source code.
*/
Expand Down Expand Up @@ -178,14 +182,14 @@ struct yyParser {
};
typedef struct yyParser yyParser;

#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
#include <stdio.h>
static FILE *yyTraceFILE = 0;
static char *yyTracePrompt = 0;
#endif /* NDEBUG */

#ifndef NDEBUG
/*
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
/*
** Turn parser tracing on by giving a stream to which to write the trace
** and a prompt to preface each trace message. Tracing is turned off
** by making either argument NULL
Expand Down Expand Up @@ -213,15 +217,15 @@ void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
}
#endif /* NDEBUG */

#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
/* For tracing shifts, the names of all terminals and nonterminals
** are required. The following table supplies these names */
static const char *const yyTokenName[] = {
%%
};
#endif /* NDEBUG */

#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
/* For tracing reduce actions, the names of all rules are required.
*/
static const char *const yyRuleName[] = {
Expand All @@ -243,7 +247,7 @@ static void yyGrowStack(yyParser *p){
if( pNew ){
p->yystack = pNew;
p->yystksz = newSize;
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
yyTracePrompt, p->yystksz);
Expand Down Expand Up @@ -328,7 +332,7 @@ static int yy_pop_parser_stack(yyParser *pParser){
yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];

if( pParser->yyidx<0 ) return 0;
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE && pParser->yyidx>=0 ){
fprintf(yyTraceFILE,"%sPopping %s\n",
yyTracePrompt,
Expand Down Expand Up @@ -414,7 +418,7 @@ static int yy_find_shift_action(
YYCODETYPE iFallback; /* Fallback token */
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
&& (iFallback = yyFallback[iLookAhead])!=0 ){
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
Expand All @@ -427,7 +431,7 @@ static int yy_find_shift_action(
{
int j = i - iLookAhead + YYWILDCARD;
if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
Expand Down Expand Up @@ -485,7 +489,7 @@ static int yy_find_reduce_action(
static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
ParseARG_FETCH;
yypParser->yyidx--;
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
}
Expand Down Expand Up @@ -531,7 +535,7 @@ static void yy_shift(
yytos->stateno = (YYACTIONTYPE)yyNewState;
yytos->major = (YYCODETYPE)yyMajor;
yytos->minor = *yypMinor;
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE && yypParser->yyidx>0 ){
int i;
fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
Expand Down Expand Up @@ -570,8 +574,8 @@ static void yy_reduce(
int yysize; /* Amount to pop the stack */
ParseARG_FETCH;
yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
if( yyTraceFILE && yyruleno>=0
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE && yyruleno>=0
&& yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
yyRuleName[yyruleno]);
Expand Down Expand Up @@ -612,7 +616,7 @@ static void yy_reduce(
yypParser->yyidx -= yysize;
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
if( yyact < YYNSTATE ){
#ifdef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
/* If we are not debugging and the reduce action popped at least
** one element off the stack, then we can push the new element back
** onto the stack here, and skip the stack overflow test in yy_shift().
Expand Down Expand Up @@ -641,7 +645,7 @@ static void yy_parse_failed(
yyParser *yypParser /* The parser */
){
ParseARG_FETCH;
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
}
Expand Down Expand Up @@ -674,7 +678,7 @@ static void yy_accept(
yyParser *yypParser /* The parser */
){
ParseARG_FETCH;
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
}
Expand Down Expand Up @@ -742,7 +746,7 @@ void Parse(
yyendofinput = (yymajor==0);
ParseARG_STORE;

#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
}
Expand All @@ -762,7 +766,7 @@ void Parse(
#ifdef YYERRORSYMBOL
int yymx;
#endif
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
}
Expand Down Expand Up @@ -792,7 +796,7 @@ void Parse(
}
yymx = yypParser->yystack[yypParser->yyidx].major;
if( yymx==YYERRORSYMBOL || yyerrorhit ){
#ifndef NDEBUG
#if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sDiscard input token %s\n",
yyTracePrompt,yyTokenName[yymajor]);
Expand Down
4 changes: 2 additions & 2 deletions mojoshader_assembler.c
Expand Up @@ -13,7 +13,7 @@
#define __MOJOSHADER_INTERNAL__ 1
#include "mojoshader_internal.h"

#if DEBUG_ASSEMBLY_PARSER
#if DEBUG_ASSEMBLER_PARSER
#define print_debug_token(token, len, val) \
MOJOSHADER_print_debug_token("ASSEMBLER", token, len, val)
#else
Expand Down Expand Up @@ -193,7 +193,7 @@ static inline int shader_is_vertex(const Context *ctx)

static inline void pushback(Context *ctx)
{
#if DEBUG_ASSEMBLY_PARSER
#if DEBUG_ASSEMBLER_PARSER
printf("ASSEMBLER PUSHBACK\n");
#endif
assert(!ctx->pushedback);
Expand Down
9 changes: 8 additions & 1 deletion mojoshader_compiler.c
Expand Up @@ -9,6 +9,10 @@ typedef struct Context
Token tokenval; // assembler token!
} Context;

#if DEBUG_COMPILER_PARSER
#define LEMON_SUPPORT_TRACING 1
#endif

#define __MOJOSHADER_HLSL_COMPILER__ 1
#include "mojoshader_parser_hlsl.h"

Expand Down Expand Up @@ -130,7 +134,10 @@ void MOJOSHADER_compile(const char *filename,
defines, define_count, 0, m, f, d);

void *pParser = ParseHLSLAlloc(m, d);
ParseHLSLTrace(stdout, "TRACE: ");

#if DEBUG_COMPILER_PARSER
ParseHLSLTrace(stdout, "COMPILER: ");
#endif

do {
ctx.token = preprocessor_nexttoken(ctx.preprocessor,
Expand Down
5 changes: 3 additions & 2 deletions mojoshader_internal.h
Expand Up @@ -18,9 +18,10 @@

#define DEBUG_LEXER 0
#define DEBUG_PREPROCESSOR 0
#define DEBUG_ASSEMBLY_PARSER 0
#define DEBUG_ASSEMBLER_PARSER 0
#define DEBUG_COMPILER_PARSER 0
#define DEBUG_TOKENIZER \
(DEBUG_PREPROCESSOR || DEBUG_ASSEMBLY_PARSER || DEBUG_LEXER)
(DEBUG_PREPROCESSOR || DEBUG_ASSEMBLER_PARSER || DEBUG_LEXER)

#if (defined(__APPLE__) && defined(__MACH__))
#define PLATFORM_MACOSX 1
Expand Down

0 comments on commit b2b145a

Please sign in to comment.