Skip to content

Commit

Permalink
Recognize a new spirv header json grammar keyword "aliases" (#5367)
Browse files Browse the repository at this point in the history
* Recognize a JSON keyword "aliases" for SPIRV-header

This commit will handle the new JSON keyword "aliases" in SPIRV-Header grammar files.

"aliases" are used in two places: one for "opname" and another for "enumerants".

This commit itself wouldn't do anything until we integrate new commits from SPIRV-Header repo.
  • Loading branch information
jkwak-work authored Oct 22, 2024
1 parent 3e84726 commit ba77578
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/compiler-core/slang-spirv-core-grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct Enumerant
UnownedStringSlice enumerant;
JSONValue value;
List<UnownedStringSlice> capabilities;
List<UnownedStringSlice> aliases;
// List<Operand> parameters;
// UnownedStringSlice version;
// UnownedStringSlice lastVersion;
Expand All @@ -70,6 +71,7 @@ SLANG_MAKE_STRUCT_RTTI_INFO(
SLANG_RTTI_FIELD(enumerant),
SLANG_RTTI_FIELD(value),
SLANG_OPTIONAL_RTTI_FIELD(capabilities),
SLANG_OPTIONAL_RTTI_FIELD(aliases),
// SLANG_OPTIONAL_RTTI_FIELD(parameters),
// SLANG_OPTIONAL_RTTI_FIELD(version),
// SLANG_OPTIONAL_RTTI_FIELD(lastVersion),
Expand Down Expand Up @@ -152,6 +154,11 @@ static Dictionary<UnownedStringSlice, SpvWord> operandKindToDict(
);
}
dict.add(e.enumerant, valueInt);

for (auto alias : e.aliases)
{
dict.add(alias, valueInt);
}
}
return dict;
}
Expand Down
13 changes: 13 additions & 0 deletions tools/slang-lookup-generator/lookup-generator-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static List<String> extractOpNames(UnownedStringSlice& error, const JSONValue& v
// List<String> result = match(myJSONValue, "instructions", AsArray, "opname", AsString);
const auto instKey = container.findKey(UnownedStringSlice("instructions"));
const auto opnameKey = container.findKey(UnownedStringSlice("opname"));
const auto aliasesKey = container.findKey(UnownedStringSlice("aliases"));
if (!instKey)
{
error = UnownedStringSlice("JSON parsing failed, no \"instructions\" key\n");
Expand All @@ -64,6 +65,18 @@ static List<String> extractOpNames(UnownedStringSlice& error, const JSONValue& v
return {};
}
opnames.add(container.getString(opname));

if (aliasesKey)
{
auto aliases = container.findObjectValue(inst, aliasesKey);
if (aliases.isValid() && aliases.type == JSONValue::Type::Array)
{
for (auto& alias : container.getArray(aliases))
{
opnames.add(container.getString(alias));
}
}
}
}

return opnames;
Expand Down

0 comments on commit ba77578

Please sign in to comment.