Skip to content
Permalink
Browse files
Moved asm comment processing into the lexer.
  • Loading branch information
icculus committed Feb 24, 2009
1 parent c110621 commit e456e9175b187fcbf2900cadf919d2dd454fabe1
Showing with 34 additions and 51 deletions.
  1. +25 −47 mojoshader_assembler.c
  2. +2 −1 mojoshader_internal.h
  3. +2 −1 mojoshader_lexer.re
  4. +5 −2 mojoshader_preprocessor.c
@@ -197,62 +197,40 @@ static inline void pushback(Context *ctx)
ctx->pushedback = 1;
} // pushback

static Token _nexttoken(Context *ctx)
{
while (1)
{
ctx->token = preprocessor_nexttoken(ctx->preprocessor, &ctx->tokenlen,
&ctx->tokenval);

if (preprocessor_outofmemory(ctx->preprocessor))
{
out_of_memory(ctx);
ctx->tokenval = TOKEN_EOI;
ctx->token = NULL;
ctx->tokenlen = 0;
break;
} // if

if (ctx->tokenval == TOKEN_PREPROCESSING_ERROR)
{
fail(ctx, ctx->token);
continue;
} // else

break;
} // while

return ctx->tokenval;
} // _nexttoken


static Token nexttoken(Context *ctx)
{
if (ctx->pushedback)
{
print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval);
ctx->pushedback = 0;
return ctx->tokenval;
} // if

Token token = _nexttoken(ctx);

while (token == ((Token) '\n'))
token = _nexttoken(ctx); // skip endlines.

if (token == ((Token) ';')) // single line comment in assembler.
else
{
do
while (1)
{
token = _nexttoken(ctx);
} while ((token != ((Token) '\n')) && (token != TOKEN_EOI));
ctx->token = preprocessor_nexttoken(ctx->preprocessor,
&ctx->tokenlen,
&ctx->tokenval);

while (token == ((Token) '\n'))
token = _nexttoken(ctx); // skip endlines.
} // if
if (preprocessor_outofmemory(ctx->preprocessor))
{
out_of_memory(ctx);
ctx->tokenval = TOKEN_EOI;
ctx->token = NULL;
ctx->tokenlen = 0;
break;
} // if

else if (ctx->tokenval == TOKEN_PREPROCESSING_ERROR)
{
fail(ctx, ctx->token);
continue;
} // else if

break;
} // while
} // else

print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval);
return token;
return ctx->tokenval;
} // nexttoken


@@ -1427,7 +1405,7 @@ static Context *build_context(const char *filename,
ctx->parse_phase = MOJOSHADER_PARSEPHASE_NOTSTARTED;
ctx->preprocessor = preprocessor_start(filename, source, sourcelen,
include_open, include_close,
defines, define_count, m, f, d);
defines, define_count, 1, m, f, d);

if (ctx->preprocessor == NULL)
{
@@ -410,6 +410,7 @@ typedef struct IncludeState
int pushedback;
const unsigned char *lexer_marker;
int report_whitespace;
int asm_comments;
unsigned int orig_length;
unsigned int bytes_left;
unsigned int line;
@@ -428,7 +429,7 @@ Preprocessor *preprocessor_start(const char *fname, const char *source,
MOJOSHADER_includeOpen open_callback,
MOJOSHADER_includeClose close_callback,
const MOJOSHADER_preprocessorDefine *defines,
unsigned int define_count,
unsigned int define_count, int asm_comments,
MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);

void preprocessor_end(Preprocessor *pp);
@@ -148,12 +148,13 @@ scanner_loop:
"^" { RET('^'); }
"|" { RET('|'); }
":" { RET(':'); }
";" { RET(';'); }
"{" { RET('{'); }
"}" { RET('}'); }
"=" { RET('='); }
"?" { RET('?'); }
";" { if (s->asm_comments) goto singlelinecomment; RET(';'); }
"\000" { if (eoi) { RET(TOKEN_EOI); } goto bad_chars; }
WHITESPACE { if (s->report_whitespace) RET(' '); goto scanner_loop; }
@@ -42,6 +42,7 @@ typedef struct Context
int out_of_memory;
char failstr[256];
int recursion_count;
int asm_comments;
Conditional *conditional_pool;
IncludeState *include_stack;
IncludeState *include_pool;
@@ -552,6 +553,7 @@ static int push_source(Context *ctx, const char *fname, const char *source,
state->line = linenum;
state->defines = defs;
state->next = ctx->include_stack;
state->asm_comments = ctx->asm_comments;

ctx->include_stack = state;

@@ -609,7 +611,7 @@ Preprocessor *preprocessor_start(const char *fname, const char *source,
MOJOSHADER_includeOpen open_callback,
MOJOSHADER_includeClose close_callback,
const MOJOSHADER_preprocessorDefine *defines,
unsigned int define_count,
unsigned int define_count, int asm_comments,
MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
{
int okay = 1;
@@ -631,6 +633,7 @@ Preprocessor *preprocessor_start(const char *fname, const char *source,
ctx->malloc_data = d;
ctx->open_callback = open_callback;
ctx->close_callback = close_callback;
ctx->asm_comments = asm_comments;

// let the usual preprocessor parser sort these out.
char *define_include = NULL;
@@ -1919,7 +1922,7 @@ const MOJOSHADER_preprocessData *MOJOSHADER_preprocess(const char *filename,

Preprocessor *pp = preprocessor_start(filename, source, sourcelen,
include_open, include_close,
defines, define_count, m, f, d);
defines, define_count, 0, m, f, d);

if (pp == NULL)
return &out_of_mem_data_preprocessor;

0 comments on commit e456e91

Please sign in to comment.