From 807fb25b3a61ea480b261646d93276c8635f3567 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 4 Apr 2009 02:09:48 -0400 Subject: [PATCH] Fixed semantic name parsing in HLSL grammar. --- mojoshader_compiler.c | 38 ++++++++++++++++++++++++++++++++++++ mojoshader_parser_hlsl.lemon | 3 +-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/mojoshader_compiler.c b/mojoshader_compiler.c index 7dfb2287..9a5ba5ad 100644 --- a/mojoshader_compiler.c +++ b/mojoshader_compiler.c @@ -16,6 +16,40 @@ typedef struct Context #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 @@ static int ConvertToLemonToken(const Context *ctx) 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; diff --git a/mojoshader_parser_hlsl.lemon b/mojoshader_parser_hlsl.lemon index 84eefe76..bc305481 100644 --- a/mojoshader_parser_hlsl.lemon +++ b/mojoshader_parser_hlsl.lemon @@ -124,8 +124,7 @@ input_modifier ::= INOUT. 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.