Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Assembler now accepts "c[5]" as equivalent to "c5".
This only accepts a constant integers, you can't currently do something like
"c[2+3]" even if the constants could be completely folded during assembly. I
don't know if Microsoft's tools allow that, will have to revisit later if so.
  • Loading branch information
icculus committed Jul 20, 2020
1 parent 5ef758a commit 13f5216
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions mojoshader_assembler.c
Expand Up @@ -696,31 +696,51 @@ static int parse_source_token_maybe_relative(Context *ctx, const int relok)
pushback(ctx); // not relative addressing?
else
{
if (!relok)
fail(ctx, "Relative addressing not permitted here.");
else
retval++;

parse_source_token_maybe_relative(ctx, 0);
relative = 1;
// quick hack here to make "c[5]" convert to "c5". This will also
// work with "c0[5]" but that's possibly illegal...?
int skip_relative_parsing = 0;
if ((regtype == REG_TYPE_CONST) && (regnum == 0))
{
uint32 ui32 = 0;
if (nexttoken(ctx) != TOKEN_INT_LITERAL)
pushback(ctx);
else if (!ui32fromtoken(ctx, &ui32))
pushback(ctx);
else
{
regnum = ui32;
skip_relative_parsing = 1;
} // else
} // if

if (nexttoken(ctx) != ((Token) '+'))
pushback(ctx);
else
if (!skip_relative_parsing)
{
// !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ?
if (regnum != 0)
fail(ctx, "Relative addressing with explicit register number.");
if (!relok)
fail(ctx, "Relative addressing not permitted here.");
else
retval++;

uint32 ui32 = 0;
if ( (nexttoken(ctx) != TOKEN_INT_LITERAL) ||
(!ui32fromtoken(ctx, &ui32)) ||
(ctx->tokenlen != 0) )
parse_source_token_maybe_relative(ctx, 0);
relative = 1;

if (nexttoken(ctx) != ((Token) '+'))
pushback(ctx);
else
{
fail(ctx, "Invalid relative addressing offset");
} // if
regnum += (int) ui32;
} // else
// !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ?
if (regnum != 0)
fail(ctx, "Relative addressing with explicit register number.");

uint32 ui32 = 0;
if ( (nexttoken(ctx) != TOKEN_INT_LITERAL) ||
(!ui32fromtoken(ctx, &ui32)) ||
(ctx->tokenlen != 0) )
{
fail(ctx, "Invalid relative addressing offset");
} // if
regnum += (int) ui32;
} // else
} // if

if (nexttoken(ctx) != ((Token) ']'))
fail(ctx, "Expected ']'");
Expand Down

0 comments on commit 13f5216

Please sign in to comment.