diff options
| author | Yong He <yonghe@outlook.com> | 2024-01-18 16:46:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-18 16:46:00 -0800 |
| commit | c5c1a25ab6d0e509e893d737a679ac47949df2f6 (patch) | |
| tree | e60d4f96ae5105ef19c6b238a4d98467ff58975d /tools/slang-lookup-generator | |
| parent | 1a13842f7ece9f3c492a7017509b75eafa903bbf (diff) | |
Capability def parsing & codegen + disjoint sets (#3451)
* Capability def parsing & codegen + disjoint sets
This change adds a capability definition file, and a code generator
to produce C++ code that defines the capability enums and necessary
data structures around the capabilities.
Extends the existing CapabilitySet class to support expressing
disjoint sets of capabilities. This sets up for the next change
that will enhance our type checking with reasoning of capability
requirements.
* Fix cmake.
* Fix warning.
* Fix.
* Fix isBetterForTarget to prefer less specialized option.
* Fix.
* Fix premake.
* Fix intrinsic.
* Fix vs sln file.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/slang-lookup-generator')
| -rw-r--r-- | tools/slang-lookup-generator/lookup-generator-main.cpp | 76 |
1 files changed, 3 insertions, 73 deletions
diff --git a/tools/slang-lookup-generator/lookup-generator-main.cpp b/tools/slang-lookup-generator/lookup-generator-main.cpp index a6f43c102..b99cf0e53 100644 --- a/tools/slang-lookup-generator/lookup-generator-main.cpp +++ b/tools/slang-lookup-generator/lookup-generator-main.cpp @@ -4,7 +4,7 @@ #include "../../source/compiler-core/slang-json-parser.h" #include "../../source/compiler-core/slang-json-value.h" #include "../../source/compiler-core/slang-lexer.h" -#include "../../source/compiler-core/slang-perfect-hash.h" +#include "../../source/compiler-core/slang-perfect-hash-codegen.h" #include "../../source/core/slang-io.h" #include "../../source/core/slang-secure-crt.h" #include "../../source/core/slang-string-util.h" @@ -69,46 +69,6 @@ static List<String> extractOpNames(UnownedStringSlice& error, const JSONValue& v return opnames; } -void writeHashFile( - const char* const outCppPath, - const char* valueType, - const char* valuePrefix, - const List<String> includes, - const HashParams& hashParams, - const List<String> values) -{ - StringBuilder sb; - StringWriter writer(&sb, WriterFlags(0)); - WriterHelper w(&writer); - - w.print("// Hash function for %s\n", valueType); - w.print("//\n"); - w.print("// This file was thoughtfully generated by a machine,\n"); - w.print("// don't even think about modifying it yourself!\n"); - w.print("//\n"); - w.print("\n"); - for (const auto& i : includes) - { - w.print("#include \"%s\"\n", i.getBuffer()); - } - w.print("\n"); - w.print("\n"); - w.print("namespace Slang\n"); - w.print("{\n"); - w.print("\n"); - - w.put(perfectHashToEmbeddableCpp( - hashParams, - UnownedStringSlice(valueType), - (String("lookup") + valueType).getUnownedSlice(), - values - ).getBuffer()); - - w.print("}\n"); - - File::writeAllTextIfChanged(outCppPath, sb.getUnownedSlice()); -} - int main(int argc, const char* const* argv) { using namespace Slang; @@ -166,38 +126,8 @@ int main(int argc, const char* const* argv) opnames.add(w); } - HashParams hashParams; - auto r = minimalPerfectHash(opnames, hashParams); - switch (r) - { - case HashFindResult::UnavoidableHashCollision: - { - sink.diagnoseRaw( - Severity::Error, - "Unable to find a non-overlapping hash function.\n" - "The hash function probably has a unavoidable " - "collision for some input words\n"); - return 1; - } - case HashFindResult::NonUniqueKeys: - { - sink.diagnoseRaw(Severity::Error, "Input word list has duplicates\n"); - return 1; - } - case HashFindResult::Success:; - } - - List<String> values; - values.reserve (hashParams.destTable.getCount()); - for(const auto& v : hashParams.destTable) - values.add(enumerantPrefix + v); - writeHashFile( - outCppPath, - enumName, - enumerantPrefix, - { "../core/slang-common.h", "../core/slang-string.h", enumHeader }, - hashParams, - values); + if (SLANG_FAILED(writePerfectHashLookupCppFile(outCppPath, opnames, enumName, enumerantPrefix, enumHeader, &sink))) + return -1; return 0; } |
