mojoshader_assembler.c
changeset 1285 1952246ec6cd
parent 1284 0ed38e8899a3
child 1287 c5a53296dbd5
equal deleted inserted replaced
1284:0ed38e8899a3 1285:1952246ec6cd
   694     uint32 relative = 0;
   694     uint32 relative = 0;
   695     if (nexttoken(ctx) != ((Token) '['))
   695     if (nexttoken(ctx) != ((Token) '['))
   696         pushback(ctx);  // not relative addressing?
   696         pushback(ctx);  // not relative addressing?
   697     else
   697     else
   698     {
   698     {
   699         if (!relok)
   699         // quick hack here to make "c[5]" convert to "c5". This will also
   700             fail(ctx, "Relative addressing not permitted here.");
   700         //  work with "c0[5]" but that's possibly illegal...?
   701         else
   701         int skip_relative_parsing = 0;
   702             retval++;
   702         if ((regtype == REG_TYPE_CONST) && (regnum == 0))
   703 
   703         {
   704         parse_source_token_maybe_relative(ctx, 0);
       
   705         relative = 1;
       
   706 
       
   707         if (nexttoken(ctx) != ((Token) '+'))
       
   708             pushback(ctx);
       
   709         else
       
   710         {
       
   711             // !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ?
       
   712             if (regnum != 0)
       
   713                 fail(ctx, "Relative addressing with explicit register number.");
       
   714 
       
   715             uint32 ui32 = 0;
   704             uint32 ui32 = 0;
   716             if ( (nexttoken(ctx) != TOKEN_INT_LITERAL) ||
   705             if (nexttoken(ctx) != TOKEN_INT_LITERAL)
   717                  (!ui32fromtoken(ctx, &ui32)) ||
   706                 pushback(ctx);
   718                  (ctx->tokenlen != 0) )
   707             else if (!ui32fromtoken(ctx, &ui32))
       
   708                 pushback(ctx);
       
   709             else
   719             {
   710             {
   720                 fail(ctx, "Invalid relative addressing offset");
   711                 regnum = ui32;
   721             } // if
   712                 skip_relative_parsing = 1;
   722             regnum += (int) ui32;
   713             } // else
   723         } // else
   714         } // if
       
   715 
       
   716         if (!skip_relative_parsing)
       
   717         {
       
   718             if (!relok)
       
   719                 fail(ctx, "Relative addressing not permitted here.");
       
   720             else
       
   721                 retval++;
       
   722 
       
   723             parse_source_token_maybe_relative(ctx, 0);
       
   724             relative = 1;
       
   725 
       
   726             if (nexttoken(ctx) != ((Token) '+'))
       
   727                 pushback(ctx);
       
   728             else
       
   729             {
       
   730                 // !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ?
       
   731                 if (regnum != 0)
       
   732                     fail(ctx, "Relative addressing with explicit register number.");
       
   733 
       
   734                 uint32 ui32 = 0;
       
   735                 if ( (nexttoken(ctx) != TOKEN_INT_LITERAL) ||
       
   736                      (!ui32fromtoken(ctx, &ui32)) ||
       
   737                      (ctx->tokenlen != 0) )
       
   738                 {
       
   739                     fail(ctx, "Invalid relative addressing offset");
       
   740                 } // if
       
   741                 regnum += (int) ui32;
       
   742             } // else
       
   743         } // if
   724 
   744 
   725         if (nexttoken(ctx) != ((Token) ']'))
   745         if (nexttoken(ctx) != ((Token) ']'))
   726             fail(ctx, "Expected ']'");
   746             fail(ctx, "Expected ']'");
   727     } // else
   747     } // else
   728 
   748