mojoshader.c
changeset 475 ea119c8ce5cd
parent 470 7d84d3452125
child 476 def04fdc464a
equal deleted inserted replaced
474:c2d4e63efdd1 475:ea119c8ce5cd
   159 struct Context
   159 struct Context
   160 {
   160 {
   161     MOJOSHADER_malloc malloc;
   161     MOJOSHADER_malloc malloc;
   162     MOJOSHADER_free free;
   162     MOJOSHADER_free free;
   163     void *malloc_data;
   163     void *malloc_data;
       
   164     const uint32 *orig_tokens;
   164     const uint32 *tokens;
   165     const uint32 *tokens;
   165     uint32 tokencount;
   166     uint32 tokencount;
       
   167     int started_parsing;
   166     const MOJOSHADER_swizzle *swizzles;
   168     const MOJOSHADER_swizzle *swizzles;
   167     unsigned int swizzles_count;
   169     unsigned int swizzles_count;
   168     OutputList *output;
   170     OutputList *output;
   169     OutputList globals;
   171     OutputList globals;
   170     OutputList helpers;
   172     OutputList helpers;
   232 
   234 
   233 
   235 
   234 // Convenience functions for allocators...
   236 // Convenience functions for allocators...
   235 
   237 
   236 MOJOSHADER_parseData out_of_mem_data = {
   238 MOJOSHADER_parseData out_of_mem_data = {
   237     "Out of memory", 0, 0, 0, 0, MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0
   239     "Out of memory", -1, 0, 0, 0, 0, MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0
   238 };
   240 };
   239 
   241 
   240 const char *out_of_mem_str = "Out of memory";
   242 const char *out_of_mem_str = "Out of memory";
   241 static inline int out_of_memory(Context *ctx)
   243 static inline int out_of_memory(Context *ctx)
   242 {
   244 {
  6625     memset(ctx, '\0', sizeof (Context));
  6627     memset(ctx, '\0', sizeof (Context));
  6626     ctx->malloc = m;
  6628     ctx->malloc = m;
  6627     ctx->free = f;
  6629     ctx->free = f;
  6628     ctx->malloc_data = d;
  6630     ctx->malloc_data = d;
  6629     ctx->tokens = (const uint32 *) tokenbuf;
  6631     ctx->tokens = (const uint32 *) tokenbuf;
       
  6632     ctx->orig_tokens = (const uint32 *) tokenbuf;
  6630     ctx->tokencount = bufsize / sizeof (uint32);
  6633     ctx->tokencount = bufsize / sizeof (uint32);
  6631     ctx->swizzles = swiz;
  6634     ctx->swizzles = swiz;
  6632     ctx->swizzles_count = swizcount;
  6635     ctx->swizzles_count = swizcount;
  6633     ctx->endline = ENDLINE_STR;
  6636     ctx->endline = ENDLINE_STR;
  6634     ctx->endline_len = strlen(ctx->endline);
  6637     ctx->endline_len = strlen(ctx->endline);
  7081             for (i = 0; i < ctx->sampler_count; i++)
  7084             for (i = 0; i < ctx->sampler_count; i++)
  7082                 Free(ctx, (void *) samplers[i].name);
  7085                 Free(ctx, (void *) samplers[i].name);
  7083             Free(ctx, samplers);
  7086             Free(ctx, samplers);
  7084         } // if
  7087         } // if
  7085 
  7088 
       
  7089         if (ctx->started_parsing)
       
  7090             retval->error_position = (ctx->tokens - ctx->orig_tokens) * sizeof (uint32);
       
  7091         else
       
  7092             retval->error_position = -1;
  7086         retval->error = ctx->failstr;  // we recycle.  :)
  7093         retval->error = ctx->failstr;  // we recycle.  :)
  7087         ctx->failstr = NULL;  // don't let this get free()'d too soon.
  7094         ctx->failstr = NULL;  // don't let this get free()'d too soon.
  7088     } // if
  7095     } // if
  7089     else
  7096     else
  7090     {
  7097     {
       
  7098         retval->error_position = -2;
  7091         retval->profile = ctx->profile->name;
  7099         retval->profile = ctx->profile->name;
  7092         retval->output = output;
  7100         retval->output = output;
  7093         retval->output_len = ctx->output_len;
  7101         retval->output_len = ctx->output_len;
  7094         retval->instruction_count = ctx->instruction_count;
  7102         retval->instruction_count = ctx->instruction_count;
  7095         retval->shader_type = ctx->shader_type;
  7103         retval->shader_type = ctx->shader_type;
  7295 
  7303 
  7296     verify_swizzles(ctx);
  7304     verify_swizzles(ctx);
  7297 
  7305 
  7298     // Version token always comes first.
  7306     // Version token always comes first.
  7299     if (!isfail(ctx))
  7307     if (!isfail(ctx))
       
  7308     {
       
  7309         ctx->started_parsing = 1;
  7300         rc = parse_version_token(ctx, profile);
  7310         rc = parse_version_token(ctx, profile);
       
  7311     } // if
  7301 
  7312 
  7302     // parse out the rest of the tokens after the version token...
  7313     // parse out the rest of the tokens after the version token...
  7303     while ( (rc > 0) && (!isfail(ctx)) )
  7314     while ( (rc > 0) && (!isfail(ctx)) )
  7304     {
  7315     {
  7305         // reset for every token, and consider an error if it ever overflows!
  7316         // reset for every token, and consider an error if it ever overflows!