summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-obfuscate-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-03-24 09:56:59 -0400
committerGitHub <noreply@github.com>2023-03-24 09:56:59 -0400
commite794de0d63e6de9be564c971fd40486ecf631293 (patch)
tree903bd4100fd9c259d68f2893c61a36880e182f14 /source/slang/slang-ir-obfuscate-loc.cpp
parent03c10833beb331e234554808c2a80d3cadecc7c0 (diff)
Obfuscated source map writing (#2727)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP produce obfuscated source map and write when container is specified. * Make the sourcemap generated name stable.
Diffstat (limited to 'source/slang/slang-ir-obfuscate-loc.cpp')
-rw-r--r--source/slang/slang-ir-obfuscate-loc.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/source/slang/slang-ir-obfuscate-loc.cpp b/source/slang/slang-ir-obfuscate-loc.cpp
index b3f5d5cd3..79e855633 100644
--- a/source/slang/slang-ir-obfuscate-loc.cpp
+++ b/source/slang/slang-ir-obfuscate-loc.cpp
@@ -72,13 +72,14 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
List<LocPair> locPairs;
+ // We want the hash to be stable. One problem is the source locs depend on their order of inclusion.
+ // To work around this we are going
{
+ SourceView* sourceView = nullptr;
+
SourceLoc curLoc;
for (const auto& instWithLoc : instWithLocs)
{
- hash = combineHash(hash, getHashCode(instWithLoc.inst));
- hash = combineHash(hash, getHashCode(instWithLoc.loc.getRaw()));
-
if (instWithLoc.loc != curLoc)
{
LocPair locPair;
@@ -87,6 +88,21 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
// This is the current loc
curLoc = instWithLoc.loc;
+
+ // If the loc isn't in the view, lookup the view it is in
+ if (sourceView == nullptr ||
+ !sourceView->getRange().contains(curLoc))
+ {
+ sourceView = sourceManager->findSourceViewRecursively(curLoc);
+ SLANG_ASSERT(sourceView);
+
+ // Combine the name
+ hash = combineHash(hash, getHashCode(sourceView->getViewPathInfo().getName().getUnownedSlice()));
+ }
+ SLANG_ASSERT(sourceView);
+
+ // We combine the *offset* which is stable
+ hash = combineHash(hash, getHashCode(sourceView->getRange().getOffset(curLoc)));
}
}
}
@@ -128,6 +144,12 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
SourceFile* obfuscatedFile = sourceManager->createSourceFileWithSize(obfusctatedPathInfo, uniqueLocCount);
+ // We have only one line for all locs, just set up that way...
+ {
+ const uint32_t offsets[2] = { 0, uint32_t(uniqueLocCount) };
+ obfuscatedFile->setLineBreakOffsets(offsets, SLANG_COUNT_OF(offsets));
+ }
+
// Create the view we are going to use from the obfusctated "file".
SourceView* obfuscatedView = sourceManager->createSourceView(obfuscatedFile, nullptr, SourceLoc());