Moved asm comment processing into the lexer.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 23 Feb 2009 23:07:06 -0500
changeset 690 4710df464f13
parent 689 5872092cbf95
child 691 47efe0f000ab
Moved asm comment processing into the lexer.
mojoshader_assembler.c
mojoshader_internal.h
mojoshader_lexer.re
mojoshader_preprocessor.c
--- a/mojoshader_assembler.c	Mon Feb 23 20:43:41 2009 -0500
+++ b/mojoshader_assembler.c	Mon Feb 23 23:07:06 2009 -0500
@@ -197,62 +197,40 @@
     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)
+        ctx->pushedback = 0;
+    else
     {
-        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.
+        while (1)
+        {
+            ctx->token = preprocessor_nexttoken(ctx->preprocessor,
+                                                &ctx->tokenlen,
+                                                &ctx->tokenval);
 
-    if (token == ((Token) ';'))  // single line comment in assembler.
-    {
-        do
-        {
-            token = _nexttoken(ctx);
-        } while ((token != ((Token) '\n')) && (token != TOKEN_EOI));
+            if (preprocessor_outofmemory(ctx->preprocessor))
+            {
+                out_of_memory(ctx);
+                ctx->tokenval = TOKEN_EOI;
+                ctx->token = NULL;
+                ctx->tokenlen = 0;
+                break;
+            } // if
 
-        while (token == ((Token) '\n'))
-            token = _nexttoken(ctx);  // skip endlines.
-    } // 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 @@
     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)
     {
--- a/mojoshader_internal.h	Mon Feb 23 20:43:41 2009 -0500
+++ b/mojoshader_internal.h	Mon Feb 23 23:07:06 2009 -0500
@@ -410,6 +410,7 @@
     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 @@
                             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);
--- a/mojoshader_lexer.re	Mon Feb 23 20:43:41 2009 -0500
+++ b/mojoshader_lexer.re	Mon Feb 23 23:07:06 2009 -0500
@@ -148,12 +148,13 @@
     "^"             { 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; }
--- a/mojoshader_preprocessor.c	Mon Feb 23 20:43:41 2009 -0500
+++ b/mojoshader_preprocessor.c	Mon Feb 23 23:07:06 2009 -0500
@@ -42,6 +42,7 @@
     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 @@
     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 @@
                             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 @@
     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 @@
 
     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;