From d680309ff1440333f2ab1537c63cb46f02e0b8a0 Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 31 Oct 2025 15:33:07 -0700 Subject: meow --- source/slang/slang-ir-util.cpp | 55 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) (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 1e00fcaf6..4c897063f 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -6,6 +6,7 @@ #include "slang-ir-insts.h" #include +#include #include namespace Slang @@ -14,15 +15,12 @@ namespace Slang static String _generateRandomSuffix() { std::random_device rd; - uint32_t value = rd(); - if (value == 0) - { - value = 0x4AE33F2Eu; // arbitrary non-zero fallback - } + uint32_t seed = rd(); + std::cout << "seed: " << seed << std::endl; const char kHexDigits[] = "0123456789abcdef"; char buffer[9]; - uint32_t temp = value; + uint32_t temp = seed; for (int i = 7; i >= 0; --i) { buffer[i] = kHexDigits[temp & 0xF]; @@ -36,22 +34,59 @@ static String _generateRandomSuffix() return sb.produceString(); } -String getOrCreateModuleNonPublicSuffix(IRModuleInst* moduleInst) +String getOrCreateModuleNonPublicSuffix(IRModuleInst* irmInst) { static Dictionary map; - if (!moduleInst) + if (!irmInst) return String(); String suffix; - if (map.tryGetValue(moduleInst, suffix)) + if (map.tryGetValue(irmInst, suffix)) return suffix; suffix = _generateRandomSuffix(); - map[moduleInst] = suffix; + map[irmInst] = suffix; + std::cout << "generated suffix " << suffix.getBuffer() << std::endl; return suffix; } +bool hasExplicitExportedLinkage(IRInst* inst) +{ + if (!inst) + return false; + + return inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration() || + inst->findDecoration(); +} + +bool shouldApplyModuleNonPublicSuffix(IRInst* inst) +{ + if (!inst) + return false; + + if (hasExplicitExportedLinkage(inst)) + return false; + + if (as(inst) || as(inst) || as(inst) || + as(inst)) + { + return true; + } + + return false; +} + bool isPointerOfType(IRInst* type, IROp opCode) { if (auto ptrType = as(type)) -- cgit v1.2.3