mojoshader_compiler.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Mar 2009 22:58:21 -0500
changeset 724 e96f140736f0
parent 721 82d1aec6b549
child 730 d4fe68d04624
permissions -rw-r--r--
Initial work on parsing sampler declarations.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
709
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
     1
#define __MOJOSHADER_INTERNAL__ 1
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
     2
#include "mojoshader_internal.h"
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
709
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
     4
typedef struct Context
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
{
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
    Preprocessor *preprocessor;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
    const char *token;      // assembler token!
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
    unsigned int tokenlen;  // assembler token!
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
    Token tokenval;         // assembler token!
709
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
    10
} Context;
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
    11
716
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    12
#if DEBUG_COMPILER_PARSER
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    13
#define LEMON_SUPPORT_TRACING 1
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    14
#endif
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
    15
709
6fbd0e20b40f Removed some ANSI C things from the HLSL grammar that shaders don't do.
Ryan C. Gordon <icculus@icculus.org>
parents: 706
diff changeset
    16
#define __MOJOSHADER_HLSL_COMPILER__ 1
714
e8ed66bfff18 Make parser generate a header, to avoid external project build confusion.
Ryan C. Gordon <icculus@icculus.org>
parents: 713
diff changeset
    17
#include "mojoshader_parser_hlsl.h"
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
static int ConvertToLemonToken(const Context *ctx)
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
{
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
    switch (ctx->tokenval)
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    {
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
        case ((Token) ','): return TOKEN_HLSL_COMMA;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
        case ((Token) '='): return TOKEN_HLSL_ASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
        case ((Token) TOKEN_ADDASSIGN): return TOKEN_HLSL_ADDASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
        case ((Token) TOKEN_SUBASSIGN): return TOKEN_HLSL_SUBASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
        case ((Token) TOKEN_MULTASSIGN): return TOKEN_HLSL_MULASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
        case ((Token) TOKEN_DIVASSIGN): return TOKEN_HLSL_DIVASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
        case ((Token) TOKEN_MODASSIGN): return TOKEN_HLSL_MODASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
        case ((Token) TOKEN_LSHIFTASSIGN): return TOKEN_HLSL_LSHIFTASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
        case ((Token) TOKEN_RSHIFTASSIGN): return TOKEN_HLSL_RSHIFTASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
        case ((Token) TOKEN_ANDASSIGN): return TOKEN_HLSL_ANDASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
        case ((Token) TOKEN_ORASSIGN): return TOKEN_HLSL_ORASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
        case ((Token) TOKEN_XORASSIGN): return TOKEN_HLSL_XORASSIGN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
        case ((Token) '?'): return TOKEN_HLSL_QUESTION;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
        case ((Token) TOKEN_OROR): return TOKEN_HLSL_OROR;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
        case ((Token) TOKEN_ANDAND): return TOKEN_HLSL_ANDAND;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
        case ((Token) '|'): return TOKEN_HLSL_OR;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        case ((Token) '^'): return TOKEN_HLSL_XOR;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        case ((Token) '&'): return TOKEN_HLSL_AND;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        case ((Token) TOKEN_EQL): return TOKEN_HLSL_EQL;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
        case ((Token) TOKEN_NEQ): return TOKEN_HLSL_NEQ;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        case ((Token) '<'): return TOKEN_HLSL_LT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        case ((Token) TOKEN_LEQ): return TOKEN_HLSL_LEQ;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        case ((Token) '>'): return TOKEN_HLSL_GT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        case ((Token) TOKEN_GEQ): return TOKEN_HLSL_GEQ;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        case ((Token) TOKEN_LSHIFT): return TOKEN_HLSL_LSHIFT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        case ((Token) TOKEN_RSHIFT): return TOKEN_HLSL_RSHIFT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        case ((Token) '+'): return TOKEN_HLSL_PLUS;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        case ((Token) '-'): return TOKEN_HLSL_MINUS;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        case ((Token) '*'): return TOKEN_HLSL_STAR;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        case ((Token) '/'): return TOKEN_HLSL_SLASH;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        case ((Token) '%'): return TOKEN_HLSL_PERCENT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
        case ((Token) '!'): return TOKEN_HLSL_EXCLAMATION;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        case ((Token) '~'): return TOKEN_HLSL_COMPLEMENT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        case ((Token) TOKEN_DECREMENT): return TOKEN_HLSL_MINUSMINUS;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        case ((Token) TOKEN_INCREMENT): return TOKEN_HLSL_PLUSPLUS;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
        case ((Token) '.'): return TOKEN_HLSL_DOT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        case ((Token) '['): return TOKEN_HLSL_LBRACKET;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        case ((Token) ']'): return TOKEN_HLSL_RBRACKET;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        case ((Token) '('): return TOKEN_HLSL_LPAREN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
        case ((Token) ')'): return TOKEN_HLSL_RPAREN;
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    63
        case ((Token) TOKEN_INT_LITERAL): return TOKEN_HLSL_INT_CONSTANT;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    64
        case ((Token) TOKEN_FLOAT_LITERAL): return TOKEN_HLSL_FLOAT_CONSTANT;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        case ((Token) TOKEN_STRING_LITERAL): return TOKEN_HLSL_STRING_LITERAL;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        case ((Token) ':'): return TOKEN_HLSL_COLON;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        case ((Token) ';'): return TOKEN_HLSL_SEMICOLON;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
        case ((Token) '{'): return TOKEN_HLSL_LBRACE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        case ((Token) '}'): return TOKEN_HLSL_RBRACE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        case ((Token) TOKEN_IDENTIFIER):
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
            #define tokencmp(t) ((ctx->tokenlen == strlen(t)) && (memcmp(ctx->token, t, ctx->tokenlen) == 0))
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
            //case ((Token) ''): return TOKEN_HLSL_TYPECAST
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
            //if (tokencmp("")) return TOKEN_HLSL_TYPE_NAME
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            //if (tokencmp("...")) return TOKEN_HLSL_ELIPSIS
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            if (tokencmp("else")) return TOKEN_HLSL_ELSE;
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    77
            if (tokencmp("inline")) return TOKEN_HLSL_INLINE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    78
            if (tokencmp("void")) return TOKEN_HLSL_VOID;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    79
            if (tokencmp("in")) return TOKEN_HLSL_IN;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    80
            if (tokencmp("inout")) return TOKEN_HLSL_INOUT;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    81
            if (tokencmp("out")) return TOKEN_HLSL_OUT;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    82
            if (tokencmp("uniform")) return TOKEN_HLSL_UNIFORM;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    83
            if (tokencmp("linear")) return TOKEN_HLSL_LINEAR;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    84
            if (tokencmp("centroid")) return TOKEN_HLSL_CENTROID;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    85
            if (tokencmp("nointerpolation")) return TOKEN_HLSL_NOINTERPOLATION;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    86
            if (tokencmp("noperspective")) return TOKEN_HLSL_NOPERSPECTIVE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    87
            if (tokencmp("sample")) return TOKEN_HLSL_SAMPLE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    88
            if (tokencmp("struct")) return TOKEN_HLSL_STRUCT;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
            if (tokencmp("typedef")) return TOKEN_HLSL_TYPEDEF;
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    90
            if (tokencmp("const")) return TOKEN_HLSL_CONST;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    91
            if (tokencmp("packoffset")) return TOKEN_HLSL_PACKOFFSET;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
            if (tokencmp("register")) return TOKEN_HLSL_REGISTER;
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    93
            if (tokencmp("extern")) return TOKEN_HLSL_EXTERN;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    94
            if (tokencmp("shared")) return TOKEN_HLSL_SHARED;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    95
            if (tokencmp("static")) return TOKEN_HLSL_STATIC;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    96
            if (tokencmp("volatile")) return TOKEN_HLSL_VOLATILE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    97
            if (tokencmp("row_major")) return TOKEN_HLSL_ROWMAJOR;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    98
            if (tokencmp("column_major")) return TOKEN_HLSL_COLUMNMAJOR;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
    99
            if (tokencmp("bool")) return TOKEN_HLSL_BOOL;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
            if (tokencmp("int")) return TOKEN_HLSL_INT;
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   101
            if (tokencmp("uint")) return TOKEN_HLSL_UINT;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   102
            if (tokencmp("half")) return TOKEN_HLSL_HALF;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
            if (tokencmp("float")) return TOKEN_HLSL_FLOAT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
            if (tokencmp("double")) return TOKEN_HLSL_DOUBLE;
721
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   105
            if (tokencmp("string")) return TOKEN_HLSL_STRING;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   106
            if (tokencmp("snorm")) return TOKEN_HLSL_SNORM;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   107
            if (tokencmp("unorm")) return TOKEN_HLSL_UNORM;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   108
            if (tokencmp("buffer")) return TOKEN_HLSL_BUFFER;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   109
            if (tokencmp("vector")) return TOKEN_HLSL_VECTOR;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   110
            if (tokencmp("bool1")) return TOKEN_HLSL_BOOL1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   111
            if (tokencmp("bool2")) return TOKEN_HLSL_BOOL2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   112
            if (tokencmp("bool3")) return TOKEN_HLSL_BOOL3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   113
            if (tokencmp("bool4")) return TOKEN_HLSL_BOOL4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   114
            if (tokencmp("int1")) return TOKEN_HLSL_INT1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   115
            if (tokencmp("int2")) return TOKEN_HLSL_INT2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   116
            if (tokencmp("int3")) return TOKEN_HLSL_INT3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   117
            if (tokencmp("int4")) return TOKEN_HLSL_INT4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   118
            if (tokencmp("uint1")) return TOKEN_HLSL_UINT1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   119
            if (tokencmp("uint2")) return TOKEN_HLSL_UINT2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   120
            if (tokencmp("uint3")) return TOKEN_HLSL_UINT3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   121
            if (tokencmp("uint4")) return TOKEN_HLSL_UINT4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   122
            if (tokencmp("half1")) return TOKEN_HLSL_HALF1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   123
            if (tokencmp("half2")) return TOKEN_HLSL_HALF2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   124
            if (tokencmp("half3")) return TOKEN_HLSL_HALF3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   125
            if (tokencmp("half4")) return TOKEN_HLSL_HALF4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   126
            if (tokencmp("float1")) return TOKEN_HLSL_FLOAT1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   127
            if (tokencmp("float2")) return TOKEN_HLSL_FLOAT2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   128
            if (tokencmp("float3")) return TOKEN_HLSL_FLOAT3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   129
            if (tokencmp("float4")) return TOKEN_HLSL_FLOAT4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   130
            if (tokencmp("double1")) return TOKEN_HLSL_DOUBLE1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   131
            if (tokencmp("double2")) return TOKEN_HLSL_DOUBLE2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   132
            if (tokencmp("double3")) return TOKEN_HLSL_DOUBLE3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   133
            if (tokencmp("double4")) return TOKEN_HLSL_DOUBLE4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   134
            if (tokencmp("matrix")) return TOKEN_HLSL_MATRIX;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   135
            if (tokencmp("bool1x1")) return TOKEN_HLSL_BOOL1X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   136
            if (tokencmp("bool1x2")) return TOKEN_HLSL_BOOL1X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   137
            if (tokencmp("bool1x3")) return TOKEN_HLSL_BOOL1X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   138
            if (tokencmp("bool1x4")) return TOKEN_HLSL_BOOL1X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   139
            if (tokencmp("bool2x1")) return TOKEN_HLSL_BOOL2X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   140
            if (tokencmp("bool2x2")) return TOKEN_HLSL_BOOL2X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   141
            if (tokencmp("bool2x3")) return TOKEN_HLSL_BOOL2X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   142
            if (tokencmp("bool2x4")) return TOKEN_HLSL_BOOL2X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   143
            if (tokencmp("bool3x1")) return TOKEN_HLSL_BOOL3X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   144
            if (tokencmp("bool3x2")) return TOKEN_HLSL_BOOL3X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   145
            if (tokencmp("bool3x3")) return TOKEN_HLSL_BOOL3X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   146
            if (tokencmp("bool3x4")) return TOKEN_HLSL_BOOL3X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   147
            if (tokencmp("bool4x1")) return TOKEN_HLSL_BOOL4X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   148
            if (tokencmp("bool4x2")) return TOKEN_HLSL_BOOL4X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   149
            if (tokencmp("bool4x3")) return TOKEN_HLSL_BOOL4X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   150
            if (tokencmp("bool4x4")) return TOKEN_HLSL_BOOL4X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   151
            if (tokencmp("int1x1")) return TOKEN_HLSL_INT1X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   152
            if (tokencmp("int1x2")) return TOKEN_HLSL_INT1X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   153
            if (tokencmp("int1x3")) return TOKEN_HLSL_INT1X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   154
            if (tokencmp("int1x4")) return TOKEN_HLSL_INT1X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   155
            if (tokencmp("int2x1")) return TOKEN_HLSL_INT2X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   156
            if (tokencmp("int2x2")) return TOKEN_HLSL_INT2X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   157
            if (tokencmp("int2x3")) return TOKEN_HLSL_INT2X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   158
            if (tokencmp("int2x4")) return TOKEN_HLSL_INT2X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   159
            if (tokencmp("int3x1")) return TOKEN_HLSL_INT3X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   160
            if (tokencmp("int3x2")) return TOKEN_HLSL_INT3X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   161
            if (tokencmp("int3x3")) return TOKEN_HLSL_INT3X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   162
            if (tokencmp("int3x4")) return TOKEN_HLSL_INT3X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   163
            if (tokencmp("int4x1")) return TOKEN_HLSL_INT4X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   164
            if (tokencmp("int4x2")) return TOKEN_HLSL_INT4X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   165
            if (tokencmp("int4x3")) return TOKEN_HLSL_INT4X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   166
            if (tokencmp("int4x4")) return TOKEN_HLSL_INT4X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   167
            if (tokencmp("uint1x1")) return TOKEN_HLSL_UINT1X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   168
            if (tokencmp("uint1x2")) return TOKEN_HLSL_UINT1X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   169
            if (tokencmp("uint1x3")) return TOKEN_HLSL_UINT1X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   170
            if (tokencmp("uint1x4")) return TOKEN_HLSL_UINT1X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   171
            if (tokencmp("uint2x1")) return TOKEN_HLSL_UINT2X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   172
            if (tokencmp("uint2x2")) return TOKEN_HLSL_UINT2X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   173
            if (tokencmp("uint2x3")) return TOKEN_HLSL_UINT2X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   174
            if (tokencmp("uint2x4")) return TOKEN_HLSL_UINT2X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   175
            if (tokencmp("uint3x1")) return TOKEN_HLSL_UINT3X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   176
            if (tokencmp("uint3x2")) return TOKEN_HLSL_UINT3X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   177
            if (tokencmp("uint3x3")) return TOKEN_HLSL_UINT3X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   178
            if (tokencmp("uint3x4")) return TOKEN_HLSL_UINT3X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   179
            if (tokencmp("uint4x1")) return TOKEN_HLSL_UINT4X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   180
            if (tokencmp("uint4x2")) return TOKEN_HLSL_UINT4X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   181
            if (tokencmp("uint4x3")) return TOKEN_HLSL_UINT4X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   182
            if (tokencmp("uint4x4")) return TOKEN_HLSL_UINT4X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   183
            if (tokencmp("half1x1")) return TOKEN_HLSL_HALF1X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   184
            if (tokencmp("half1x2")) return TOKEN_HLSL_HALF1X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   185
            if (tokencmp("half1x3")) return TOKEN_HLSL_HALF1X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   186
            if (tokencmp("half1x4")) return TOKEN_HLSL_HALF1X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   187
            if (tokencmp("half2x1")) return TOKEN_HLSL_HALF2X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   188
            if (tokencmp("half2x2")) return TOKEN_HLSL_HALF2X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   189
            if (tokencmp("half2x3")) return TOKEN_HLSL_HALF2X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   190
            if (tokencmp("half2x4")) return TOKEN_HLSL_HALF2X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   191
            if (tokencmp("half3x1")) return TOKEN_HLSL_HALF3X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   192
            if (tokencmp("half3x2")) return TOKEN_HLSL_HALF3X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   193
            if (tokencmp("half3x3")) return TOKEN_HLSL_HALF3X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   194
            if (tokencmp("half3x4")) return TOKEN_HLSL_HALF3X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   195
            if (tokencmp("half4x1")) return TOKEN_HLSL_HALF4X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   196
            if (tokencmp("half4x2")) return TOKEN_HLSL_HALF4X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   197
            if (tokencmp("half4x3")) return TOKEN_HLSL_HALF4X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   198
            if (tokencmp("half4x4")) return TOKEN_HLSL_HALF4X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   199
            if (tokencmp("float1x1")) return TOKEN_HLSL_FLOAT1X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   200
            if (tokencmp("float1x2")) return TOKEN_HLSL_FLOAT1X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   201
            if (tokencmp("float1x3")) return TOKEN_HLSL_FLOAT1X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   202
            if (tokencmp("float1x4")) return TOKEN_HLSL_FLOAT1X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   203
            if (tokencmp("float2x1")) return TOKEN_HLSL_FLOAT2X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   204
            if (tokencmp("float2x2")) return TOKEN_HLSL_FLOAT2X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   205
            if (tokencmp("float2x3")) return TOKEN_HLSL_FLOAT2X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   206
            if (tokencmp("float2x4")) return TOKEN_HLSL_FLOAT2X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   207
            if (tokencmp("float3x1")) return TOKEN_HLSL_FLOAT3X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   208
            if (tokencmp("float3x2")) return TOKEN_HLSL_FLOAT3X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   209
            if (tokencmp("float3x3")) return TOKEN_HLSL_FLOAT3X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   210
            if (tokencmp("float3x4")) return TOKEN_HLSL_FLOAT3X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   211
            if (tokencmp("float4x1")) return TOKEN_HLSL_FLOAT4X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   212
            if (tokencmp("float4x2")) return TOKEN_HLSL_FLOAT4X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   213
            if (tokencmp("float4x3")) return TOKEN_HLSL_FLOAT4X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   214
            if (tokencmp("float4x4")) return TOKEN_HLSL_FLOAT4X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   215
            if (tokencmp("double1x1")) return TOKEN_HLSL_DOUBLE1X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   216
            if (tokencmp("double1x2")) return TOKEN_HLSL_DOUBLE1X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   217
            if (tokencmp("double1x3")) return TOKEN_HLSL_DOUBLE1X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   218
            if (tokencmp("double1x4")) return TOKEN_HLSL_DOUBLE1X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   219
            if (tokencmp("double2x1")) return TOKEN_HLSL_DOUBLE2X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   220
            if (tokencmp("double2x2")) return TOKEN_HLSL_DOUBLE2X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   221
            if (tokencmp("double2x3")) return TOKEN_HLSL_DOUBLE2X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   222
            if (tokencmp("double2x4")) return TOKEN_HLSL_DOUBLE2X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   223
            if (tokencmp("double3x1")) return TOKEN_HLSL_DOUBLE3X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   224
            if (tokencmp("double3x2")) return TOKEN_HLSL_DOUBLE3X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   225
            if (tokencmp("double3x3")) return TOKEN_HLSL_DOUBLE3X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   226
            if (tokencmp("double3x4")) return TOKEN_HLSL_DOUBLE3X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   227
            if (tokencmp("double4x1")) return TOKEN_HLSL_DOUBLE4X1;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   228
            if (tokencmp("double4x2")) return TOKEN_HLSL_DOUBLE4X2;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   229
            if (tokencmp("double4x3")) return TOKEN_HLSL_DOUBLE4X3;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   230
            if (tokencmp("double4x4")) return TOKEN_HLSL_DOUBLE4X4;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   231
            if (tokencmp("break")) return TOKEN_HLSL_BREAK;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   232
            if (tokencmp("continue")) return TOKEN_HLSL_CONTINUE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   233
            if (tokencmp("discard")) return TOKEN_HLSL_DISCARD;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   234
            if (tokencmp("return")) return TOKEN_HLSL_RETURN;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   235
            if (tokencmp("while")) return TOKEN_HLSL_WHILE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   236
            if (tokencmp("for")) return TOKEN_HLSL_FOR;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   237
            if (tokencmp("unroll")) return TOKEN_HLSL_UNROLL;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   238
            if (tokencmp("loop")) return TOKEN_HLSL_LOOP;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   239
            if (tokencmp("do")) return TOKEN_HLSL_DO;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   240
            if (tokencmp("if")) return TOKEN_HLSL_IF;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   241
            if (tokencmp("branch")) return TOKEN_HLSL_BRANCH;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   242
            if (tokencmp("flatten")) return TOKEN_HLSL_FLATTEN;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   243
            if (tokencmp("switch")) return TOKEN_HLSL_SWITCH;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   244
            if (tokencmp("forcecase")) return TOKEN_HLSL_FORCECASE;
82d1aec6b549 Rewrote HLSL grammar, mostly from scratch.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   245
            if (tokencmp("call")) return TOKEN_HLSL_CALL;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
            if (tokencmp("case")) return TOKEN_HLSL_CASE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
            if (tokencmp("default")) return TOKEN_HLSL_DEFAULT;
724
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   248
            if (tokencmp("sampler")) return TOKEN_HLSL_SAMPLER;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   249
            if (tokencmp("sampler1D")) return TOKEN_HLSL_SAMPLER1D;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   250
            if (tokencmp("sampler2D")) return TOKEN_HLSL_SAMPLER2D;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   251
            if (tokencmp("sampler3D")) return TOKEN_HLSL_SAMPLER3D;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   252
            if (tokencmp("samplerCUBE")) return TOKEN_HLSL_SAMPLERCUBE;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   253
            if (tokencmp("sampler_state")) return TOKEN_HLSL_SAMPLER_STATE;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   254
            if (tokencmp("SamplerState")) return TOKEN_HLSL_SAMPLERSTATE;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   255
            if (tokencmp("SamplerComparisonState")) return TOKEN_HLSL_SAMPLERCOMPARISONSTATE;
e96f140736f0 Initial work on parsing sampler declarations.
Ryan C. Gordon <icculus@icculus.org>
parents: 721
diff changeset
   256
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
            #undef tokencmp
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
            return TOKEN_HLSL_IDENTIFIER;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
        case TOKEN_EOI: return 0;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
        case TOKEN_BAD_CHARS: printf("bad chars from lexer\n"); return 0;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
        case TOKEN_PREPROCESSING_ERROR: printf("error from lexer\n"); return 0;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
        default: assert(0 && "unexpected token from lexer\n"); return 0;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    } // switch
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    return 0;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
}
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
void MOJOSHADER_compile(const char *filename,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
                             const char *source, unsigned int sourcelen,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
                             const MOJOSHADER_preprocessorDefine *defines,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
                             unsigned int define_count,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
                             MOJOSHADER_includeOpen include_open,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
                             MOJOSHADER_includeClose include_close,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
                             MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
{
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
    Context ctx;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    if (m == NULL) m = MOJOSHADER_internal_malloc;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    if (f == NULL) f = MOJOSHADER_internal_free;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
    
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
    ctx.preprocessor = preprocessor_start(filename, source, sourcelen,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
                                           include_open, include_close,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
                                           defines, define_count, 0, m, f, d);
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    void *pParser = ParseHLSLAlloc(m, d);
716
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   287
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   288
    #if DEBUG_COMPILER_PARSER
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   289
    ParseHLSLTrace(stdout, "COMPILER: ");
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   290
    #endif
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    do {
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
        ctx.token = preprocessor_nexttoken(ctx.preprocessor,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
                                                &ctx.tokenlen,
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
                                                &ctx.tokenval);
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
        ParseHLSL(pParser, ConvertToLemonToken(&ctx), 0, 0);
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    } while (ctx.tokenval != TOKEN_EOI);
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
    ParseHLSLFree(pParser, f, d);
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
}
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300