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.
--- a/mojoshader_assembler.c Mon Jul 20 14:52:00 2020 -0400
+++ b/mojoshader_assembler.c Mon Jul 20 14:54:14 2020 -0400
@@ -696,31 +696,51 @@
pushback(ctx); // not relative addressing?
else
{
- if (!relok)
- fail(ctx, "Relative addressing not permitted here.");
- else
- retval++;
+ // 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
- parse_source_token_maybe_relative(ctx, 0);
- relative = 1;
-
- 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++;
+
+ parse_source_token_maybe_relative(ctx, 0);
+ relative = 1;
- uint32 ui32 = 0;
- if ( (nexttoken(ctx) != TOKEN_INT_LITERAL) ||
- (!ui32fromtoken(ctx, &ui32)) ||
- (ctx->tokenlen != 0) )
+ 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 ']'");