mojoshader_compiler.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 28 Feb 2009 14:35:09 -0500
changeset 709 6fbd0e20b40f
parent 706 01a92f30b84f
child 713 df03861232ec
permissions -rw-r--r--
Removed some ANSI C things from the HLSL grammar that shaders don't do.
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
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
    12
#define __MOJOSHADER_HLSL_COMPILER__ 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
    13
#include "mojoshader_parser_hlsl.h"
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
    14
#include "mojoshader_parser_hlsl.c"
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
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
    17
{
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
    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
    19
    {
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
        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
    21
        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
    22
        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
    23
        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
    24
        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
    25
        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
    26
        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
    27
        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
    28
        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
    29
        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
    30
        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
    31
        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
    32
        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
    33
        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
    34
        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
    35
        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
    36
        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
    37
        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
    38
        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
    39
        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
    40
        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
    41
        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
    42
        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
    43
        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
    44
        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
    45
        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
    46
        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
    47
        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
    48
        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
    49
        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
    50
        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
    51
        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
    52
        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
    53
        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
    54
        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
    55
        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
    56
        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
    57
        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
    58
        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
    59
        case ((Token) ')'): return TOKEN_HLSL_RPAREN;
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) TOKEN_INT_LITERAL): return TOKEN_HLSL_CONSTANT;
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) TOKEN_FLOAT_LITERAL): return TOKEN_HLSL_CONSTANT;
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) 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
    63
        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
    64
        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
    65
        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
    66
        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
    67
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) 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
    69
            #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
    70
            //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
    71
            //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
    72
            //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
    73
            if (tokencmp("else")) return TOKEN_HLSL_ELSE;
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("sizeof")) return TOKEN_HLSL_SIZEOF;
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("typedef")) return TOKEN_HLSL_TYPEDEF;
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("extern")) return TOKEN_HLSL_EXTERN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
            if (tokencmp("static")) return TOKEN_HLSL_STATIC;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
            if (tokencmp("auto")) return TOKEN_HLSL_AUTO;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
            if (tokencmp("register")) return TOKEN_HLSL_REGISTER;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
            if (tokencmp("char")) return TOKEN_HLSL_CHAR;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
            if (tokencmp("short")) return TOKEN_HLSL_SHORT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
            if (tokencmp("int")) return TOKEN_HLSL_INT;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
            if (tokencmp("long")) return TOKEN_HLSL_LONG;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
            if (tokencmp("signed")) return TOKEN_HLSL_SIGNED;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
            if (tokencmp("unsigned")) return TOKEN_HLSL_UNSIGNED;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
            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
    87
            if (tokencmp("double")) return TOKEN_HLSL_DOUBLE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
            if (tokencmp("const")) return TOKEN_HLSL_CONST;
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("volatile")) return TOKEN_HLSL_VOLATILE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
            if (tokencmp("void")) return TOKEN_HLSL_VOID;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
            if (tokencmp("struct")) return TOKEN_HLSL_STRUCT;
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("union")) return TOKEN_HLSL_UNION;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
            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
    94
            if (tokencmp("default")) return TOKEN_HLSL_DEFAULT;
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
    95
            if (tokencmp("discard")) return TOKEN_HLSL_DISCARD;
706
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
            if (tokencmp("if")) return TOKEN_HLSL_IF;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
            if (tokencmp("switch")) return TOKEN_HLSL_SWITCH;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
            if (tokencmp("while")) return TOKEN_HLSL_WHILE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
            if (tokencmp("do")) return TOKEN_HLSL_DO;
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("for")) return TOKEN_HLSL_FOR;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
            if (tokencmp("continue")) return TOKEN_HLSL_CONTINUE;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
            if (tokencmp("break")) return TOKEN_HLSL_BREAK;
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("return")) return TOKEN_HLSL_RETURN;
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
            #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
   105
            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
   106
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
        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
   108
        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
   109
        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
   110
        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
   111
    } // switch
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
    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
   114
}
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
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
   118
                             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
   119
                             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
   120
                             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
   121
                             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
   122
                             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
   123
                             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
   124
{
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    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
   126
    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
   127
    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
   128
    
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    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
   130
                                           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
   131
                                           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
   132
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    void *pParser = ParseHLSLAlloc(m, d);
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    ParseHLSLTrace(stdout, "TRACE: ");
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    do {
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
        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
   138
                                                &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
   139
                                                &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
   140
        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
   141
    } 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
   142
    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
   143
}
01a92f30b84f Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144