From 653fe976af88fcf86162ca5bb1b46d4378864572 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 19 Sep 2018 15:27:50 -0400 Subject: Support for IRStringLit (#645) * * Added support for strings in IR with IRStringLit - with storage of chars after it * Added kIRDecorationOp_Transitory - can be used for detecting instructions constructed on stack * Made IRConstant hashing work off type * Fix comment that is out of date about how an instruction is determines to hold a transitory string. --- source/core/hash.h | 11 ++++++++++- source/core/slang-string.h | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'source/core') diff --git a/source/core/hash.h b/source/core/hash.h index 26450029d..ca6172fc7 100644 --- a/source/core/hash.h +++ b/source/core/hash.h @@ -34,7 +34,16 @@ namespace Slang { return GetHashCode(const_cast(buffer)); } - + inline int GetHashCode(const char * buffer, size_t numChars) + { + int hash = 0; + for (size_t i = 0; i < numChars; ++i) + { + hash = int(buffer[i]) + (hash << 6) + (hash << 16) - hash; + } + return hash; + } + template class Hash { diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 2609b37ab..df1055795 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -717,6 +717,11 @@ namespace Slang { return Slang::GetHashCode((const char*)begin()); } + + UnownedStringSlice getUnownedSlice() const + { + return StringRepresentation::asSlice(buffer); + } }; class StringBuilder : public String -- cgit v1.2.3