Skip to content

Commit

Permalink
Fixed semantic name parsing in HLSL grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 4, 2009
1 parent a9bde80 commit 807fb25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
38 changes: 38 additions & 0 deletions mojoshader_compiler.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions mojoshader_parser_hlsl.lemon
Expand Up @@ -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.
Expand Down

0 comments on commit 807fb25

Please sign in to comment.