Skip to content
Permalink
Browse files
Cleaned up HLSL parser tracing.
  • Loading branch information
icculus committed Feb 28, 2009
1 parent 5e5c7be commit b2b145ae8bc2a504c2e0f0d4ab31655cd6f5c220
Showing with 36 additions and 24 deletions.
  1. +23 −19 misc/lempar.c
  2. +2 −2 mojoshader_assembler.c
  3. +8 −1 mojoshader_compiler.c
  4. +3 −2 mojoshader_internal.h
@@ -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.
*/
@@ -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
@@ -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[] = {
@@ -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);
@@ -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,
@@ -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]);
@@ -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]);
@@ -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);
}
@@ -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);
@@ -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]);
@@ -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().
@@ -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);
}
@@ -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);
}
@@ -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]);
}
@@ -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);
}
@@ -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]);
@@ -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
@@ -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);
@@ -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"

@@ -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,
@@ -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

0 comments on commit b2b145a

Please sign in to comment.