mojoshader_assembler.c
changeset 690 4710df464f13
parent 658 22695d3d6b98
child 694 dad8a4180a61
equal deleted inserted replaced
689:5872092cbf95 690:4710df464f13
   195     #endif
   195     #endif
   196     assert(!ctx->pushedback);
   196     assert(!ctx->pushedback);
   197     ctx->pushedback = 1;
   197     ctx->pushedback = 1;
   198 } // pushback
   198 } // pushback
   199 
   199 
   200 static Token _nexttoken(Context *ctx)
   200 
   201 {
   201 static Token nexttoken(Context *ctx)
   202     while (1)
   202 {
   203     {
   203     if (ctx->pushedback)
   204         ctx->token = preprocessor_nexttoken(ctx->preprocessor, &ctx->tokenlen,
   204         ctx->pushedback = 0;
   205                                             &ctx->tokenval);
   205     else
   206 
   206     {
   207         if (preprocessor_outofmemory(ctx->preprocessor))
   207         while (1)
   208         {
   208         {
   209             out_of_memory(ctx);
   209             ctx->token = preprocessor_nexttoken(ctx->preprocessor,
   210             ctx->tokenval = TOKEN_EOI;
   210                                                 &ctx->tokenlen,
   211             ctx->token = NULL;
   211                                                 &ctx->tokenval);
   212             ctx->tokenlen = 0;
   212 
       
   213             if (preprocessor_outofmemory(ctx->preprocessor))
       
   214             {
       
   215                 out_of_memory(ctx);
       
   216                 ctx->tokenval = TOKEN_EOI;
       
   217                 ctx->token = NULL;
       
   218                 ctx->tokenlen = 0;
       
   219                 break;
       
   220             } // if
       
   221 
       
   222             else if (ctx->tokenval == TOKEN_PREPROCESSING_ERROR)
       
   223             {
       
   224                 fail(ctx, ctx->token);
       
   225                 continue;
       
   226             } // else if
       
   227 
   213             break;
   228             break;
   214         } // if
   229         } // while
   215 
   230     } // else
   216         if (ctx->tokenval == TOKEN_PREPROCESSING_ERROR)
   231 
   217         {
   232     print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval);
   218             fail(ctx, ctx->token);
       
   219             continue;
       
   220         } // else
       
   221 
       
   222         break;
       
   223     } // while
       
   224 
       
   225     return ctx->tokenval;
   233     return ctx->tokenval;
   226 } // _nexttoken
       
   227 
       
   228 
       
   229 static Token nexttoken(Context *ctx)
       
   230 {
       
   231     if (ctx->pushedback)
       
   232     {
       
   233         print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval);
       
   234         ctx->pushedback = 0;
       
   235         return ctx->tokenval;
       
   236     } // if
       
   237 
       
   238     Token token = _nexttoken(ctx);
       
   239 
       
   240     while (token == ((Token) '\n'))
       
   241         token = _nexttoken(ctx);  // skip endlines.
       
   242 
       
   243     if (token == ((Token) ';'))  // single line comment in assembler.
       
   244     {
       
   245         do
       
   246         {
       
   247             token = _nexttoken(ctx);
       
   248         } while ((token != ((Token) '\n')) && (token != TOKEN_EOI));
       
   249 
       
   250         while (token == ((Token) '\n'))
       
   251             token = _nexttoken(ctx);  // skip endlines.
       
   252     } // if
       
   253 
       
   254     print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval);
       
   255     return token;
       
   256 } // nexttoken
   234 } // nexttoken
   257 
   235 
   258 
   236 
   259 static inline void add_token_sourcepos(Context *ctx, const size_t idx)
   237 static inline void add_token_sourcepos(Context *ctx, const size_t idx)
   260 {
   238 {
  1425     ctx->free = f;
  1403     ctx->free = f;
  1426     ctx->malloc_data = d;
  1404     ctx->malloc_data = d;
  1427     ctx->parse_phase = MOJOSHADER_PARSEPHASE_NOTSTARTED;
  1405     ctx->parse_phase = MOJOSHADER_PARSEPHASE_NOTSTARTED;
  1428     ctx->preprocessor = preprocessor_start(filename, source, sourcelen,
  1406     ctx->preprocessor = preprocessor_start(filename, source, sourcelen,
  1429                                            include_open, include_close,
  1407                                            include_open, include_close,
  1430                                            defines, define_count, m, f, d);
  1408                                            defines, define_count, 1, m, f, d);
  1431 
  1409 
  1432     if (ctx->preprocessor == NULL)
  1410     if (ctx->preprocessor == NULL)
  1433     {
  1411     {
  1434         f(ctx, d);
  1412         f(ctx, d);
  1435         return NULL;
  1413         return NULL;