From 9653dcc2c9d5d20d3d0e8918aaf1d5b09e963060 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 3 Dec 2019 09:58:59 -0500 Subject: getStringHash on string literals (#1140) * WIP getStringHash * Have a use. * Add slang-string-hash.h/.cpp * Use StringSlicePool for holding strings for StringHash. Add outputBuffer to string-literal-hash.slang so value can be tested. Ignore the GlobalHashedStringLiterals instruction on emit. * Add all the hashed string literals to ProgramLayout. * Add reflection support for hashed string literals to reflection test. * Fix string literal hash test. * Small fixes to pass test suite. * Fix issue in serialization where IRUse is not correctly initialized. * Fix problem initializing IRUse for string hash pass. Remove hack from slang-ir-specialize - specially handling if user is not null. * * Use shared builder when replacing getStringHash * Comments for functions in slang-ir-string-hash * Do not allow zero length string literals. Could be allowed, but doing so would require StringSlicePool to have a special case (or some other mechanism) --- slang.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'slang.h') diff --git a/slang.h b/slang.h index 7b2de6bd9..d11c4b7f2 100644 --- a/slang.h +++ b/slang.h @@ -2098,6 +2098,21 @@ extern "C" SlangReflectionType* const* specializationArgs, ISlangBlob** outDiagnostics); + /// Get the number of hashed strings + SLANG_API SlangUInt spReflection_getHashedStringCount( + SlangReflection* reflection); + + /// Get a hashed string. The number of chars is writtent in outCount. Note the count does *NOT* including terminating 0, + /// and the returned pointer will not generally have a terminating zero. + SLANG_API const char* spReflection_getHashedString( + SlangReflection* reflection, + SlangUInt index, + size_t* outCount); + + /// Calculate a string hash. + // Count should *NOT* include terminating zero. + SLANG_API int spCalcStringHash(const char* chars, size_t count); + #ifdef __cplusplus } @@ -2735,6 +2750,13 @@ namespace slang (SlangReflectionType* const*) specializationArgs, outDiagnostics); } + + SlangUInt getHashedStringCount() const { return spReflection_getHashedStringCount((SlangReflection*)this); } + + const char* getHashedString(SlangUInt index, size_t* outCount) const + { + return spReflection_getHashedString((SlangReflection*)this, index, outCount); + } }; typedef ISlangBlob IBlob; -- cgit v1.2.3