Fixed semantic name parsing in HLSL grammar.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 04 Apr 2009 02:09:48 -0400
changeset 730 d4fe68d04624
parent 729 92cc053fbf75
child 731 a3ce99bdc376
Fixed semantic name parsing in HLSL grammar.
mojoshader_compiler.c
mojoshader_parser_hlsl.lemon
--- a/mojoshader_compiler.c	Sun Mar 29 22:27:07 2009 -0400
+++ b/mojoshader_compiler.c	Sat Apr 04 02:09:48 2009 -0400
@@ -16,6 +16,40 @@
 #define __MOJOSHADER_HLSL_COMPILER__ 1
 #include "mojoshader_parser_hlsl.h"
 
+// This does not check correctness (POSITIONT993842 passes, etc).
+static int is_semantic(const Context *ctx)
+{
+    static const char *names[] = {
+        "BINORMAL", "BLENDINDICES", "BLENDWEIGHT",
+        "COLOR", "NORMAL", "POSITION", "POSITIONT", "PSIZE", "TANGENT",
+        "TEXCOORD", "FOG", "TESSFACTOR", "TEXCOORD", "VFACE", "VPOS", NULL
+    };
+
+    // !!! FIXME: DX10 has SV_* ("System Value Semantics").
+    const char **i;
+    for (i = names; *i; i++)
+    {
+        const char *name = *i;
+        const size_t namelen = strlen(name);
+        if (ctx->tokenlen < namelen)
+            continue;
+        else if (memcmp(ctx->token, name, namelen) != 0)
+            continue;
+
+        for (name += namelen; *name; name++)
+        {
+            if ((*name < '0') || (*name > '9'))
+                break;
+        } // for
+
+        if (*name == '\0')
+            return 1;
+    } // for
+
+    return 0;
+} // is_semantic
+
+
 static int ConvertToLemonToken(const Context *ctx)
 {
     switch (ctx->tokenval)
@@ -255,6 +289,10 @@
             if (tokencmp("SamplerComparisonState")) return TOKEN_HLSL_SAMPLERCOMPARISONSTATE;
 
             #undef tokencmp
+
+            if (is_semantic(ctx))
+                return TOKEN_HLSL_SEMANTIC;
+
             return TOKEN_HLSL_IDENTIFIER;
 
         case TOKEN_EOI: return 0;
--- a/mojoshader_parser_hlsl.lemon	Sun Mar 29 22:27:07 2009 -0400
+++ b/mojoshader_parser_hlsl.lemon	Sat Apr 04 02:09:48 2009 -0400
@@ -124,8 +124,7 @@
 input_modifier ::= OUT.
 input_modifier ::= UNIFORM.
 
-semantic ::= COLON semantic_name.
-semantic_name ::= identifier.  // !!! FIXME: list these here
+semantic ::= COLON SEMANTIC.
 
 // DX10 only?
 interpolation_mod ::= LINEAR.