Skip to content

Commit

Permalink
Export symbol information for preshaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jun 1, 2011
1 parent 61c0e29 commit f63af56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mojoshader.c
Expand Up @@ -7232,10 +7232,15 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
CtabData ctabdata = { 0, 0, 0 };
parse_constant_table(ctx, ctab.tokens - 1, ctab.tokcount * 4,
okay_version, 0, &ctabdata);

// preshader owns this now. Don't free it in this function.
preshader->symbol_count = ctabdata.symbol_count;
preshader->symbols = ctabdata.symbols;

if (!ctabdata.have_ctab)
{
fail(ctx, "Bogus preshader CTAB data");
goto parse_preshader_cleanup;
return;
} // if

// The FXLC block has the actual instructions...
Expand All @@ -7246,15 +7251,15 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
preshader->instructions = (MOJOSHADER_preshaderInstruction *)
Malloc(ctx, len);
if (preshader->instructions == NULL)
goto parse_preshader_cleanup;
return;
memset(preshader->instructions, '\0', len);

fxlc.tokens += 2;
fxlc.tokcount -= 2;
if (opcode_count > (fxlc.tokcount / 2))
{
fail(ctx, "Bogus preshader FXLC block.");
goto parse_preshader_cleanup;
return;
} // if

MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
Expand Down Expand Up @@ -7312,7 +7317,7 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
if ((operand_count * 3) > fxlc.tokcount)
{
fail(ctx, "Bogus preshader FXLC block.");
goto parse_preshader_cleanup;
return;
} // if

MOJOSHADER_preshaderOperand *operand = &inst->operands[1];
Expand Down Expand Up @@ -7396,10 +7401,6 @@ static void parse_preshader(Context *ctx, uint32 tokcount)

inst++;
} // while

parse_preshader_cleanup:
free_symbols(ctx->free, ctx->malloc_data,
ctabdata.symbols, ctabdata.symbol_count);
#endif
} // parse_preshader

Expand Down Expand Up @@ -7616,6 +7617,7 @@ static void free_preshader(MOJOSHADER_free f, void *d,
{
f((void *) preshader->literals, d);
f((void *) preshader->instructions, d);
free_symbols(f, d, preshader->symbols, preshader->symbol_count);
f((void *) preshader, d);
} // if
} // free_preshader
Expand Down
2 changes: 2 additions & 0 deletions mojoshader.h
Expand Up @@ -422,6 +422,8 @@ typedef struct MOJOSHADER_preshader
unsigned int literal_count;
double *literals;
unsigned int temp_count; /* scalar, not vector! */
unsigned int symbol_count;
MOJOSHADER_symbol *symbols;
unsigned int instruction_count;
MOJOSHADER_preshaderInstruction *instructions;
} MOJOSHADER_preshader;
Expand Down

0 comments on commit f63af56

Please sign in to comment.