From 0a2506e2fce7d754489066c51f51574bdd428bc0 Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 28 Oct 2025 19:45:29 -0700 Subject: non-exported public labels get namespaced now --- source/slang/slang-ir-util.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'source/slang/slang-ir-util.cpp') 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 +#include + 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 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(type)) -- cgit v1.2.3