diff options
| author | yum <yum.food.vr@gmail.com> | 2025-10-28 19:45:29 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-10-28 19:45:29 -0700 |
| commit | 0a2506e2fce7d754489066c51f51574bdd428bc0 (patch) | |
| tree | eb0f896a1655e2861bed8a1d8eed06ab7dc67758 /source/slang/slang-ir-util.cpp | |
| parent | 72ea1c81cafa23ea2398071b5f170b5ceba41f14 (diff) | |
non-exported public labels get namespaced now
Diffstat (limited to 'source/slang/slang-ir-util.cpp')
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index 4fb4d61ae..1e00fcaf6 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -5,9 +5,53 @@ #include "slang-ir-dominators.h" #include "slang-ir-insts.h" +#include <cstdint> +#include <random> + namespace Slang { +static String _generateRandomSuffix() +{ + std::random_device rd; + uint32_t value = rd(); + if (value == 0) + { + value = 0x4AE33F2Eu; // arbitrary non-zero fallback + } + + const char kHexDigits[] = "0123456789abcdef"; + char buffer[9]; + uint32_t temp = value; + for (int i = 7; i >= 0; --i) + { + buffer[i] = kHexDigits[temp & 0xF]; + temp >>= 4; + } + buffer[8] = 0; + + StringBuilder sb; + sb.append("_"); + sb.append(buffer); + return sb.produceString(); +} + +String getOrCreateModuleNonPublicSuffix(IRModuleInst* moduleInst) +{ + static Dictionary<IRModuleInst*, String> map; + + if (!moduleInst) + return String(); + + String suffix; + if (map.tryGetValue(moduleInst, suffix)) + return suffix; + + suffix = _generateRandomSuffix(); + map[moduleInst] = suffix; + return suffix; +} + bool isPointerOfType(IRInst* type, IROp opCode) { if (auto ptrType = as<IRPtrTypeBase>(type)) |
