summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-obfuscate-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-03-27 13:57:42 -0400
committerGitHub <noreply@github.com>2023-03-27 10:57:42 -0700
commitca1f93a916ce6b984cba402c8d3710988f2b618f (patch)
treef39b638210d38efdc7e2bb746c06b881323d0f53 /source/slang/slang-ir-obfuscate-loc.cpp
parent2179480e28bdd46c71cec269a8f55ba93aa54f53 (diff)
Using SourceMap for location output (#2736)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP using SourceMap with SourceManager. * Add a test to check obfuscation map is working. --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir-obfuscate-loc.cpp')
-rw-r--r--source/slang/slang-ir-obfuscate-loc.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/source/slang/slang-ir-obfuscate-loc.cpp b/source/slang/slang-ir-obfuscate-loc.cpp
index 79e855633..3ff2f3713 100644
--- a/source/slang/slang-ir-obfuscate-loc.cpp
+++ b/source/slang/slang-ir-obfuscate-loc.cpp
@@ -153,6 +153,8 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
// Create the view we are going to use from the obfusctated "file".
SourceView* obfuscatedView = sourceManager->createSourceView(obfuscatedFile, nullptr, SourceLoc());
+ const auto obfuscatedRange = obfuscatedView->getRange();
+
// Okay now we want to produce a map from these locs to a new source location
{
// Create a "bag" and put all of the indices in it.
@@ -160,13 +162,11 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
bag.setCount(uniqueLocCount);
- const SourceLoc baseLoc = obfuscatedView->getRange().begin;
-
{
SourceLoc* dst = bag.getBuffer();
for (Index i = 0; i < uniqueLocCount; ++i)
{
- dst[i] = baseLoc + i;
+ dst[i] = obfuscatedRange.begin + i;
}
}
@@ -227,7 +227,6 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
{
const auto& pair = locPairs[i];
-
// First find the view
if (curView == nullptr ||
!curView->getRange().contains(pair.originalLoc))
@@ -282,9 +281,11 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
entry.sourceFileIndex = sourceFileIndex;
- // i is the generated column
- entry.generatedColumn = i;
+ // Calculate the column offset, from the pair obfuscated loc
+ entry.generatedColumn = Index(obfuscatedRange.getOffset(pair.obfuscatedLoc));
+ // We need to subtract 1, because handleLoc locations are 1 indexed, but SourceMap
+ // entry is 0 indexed.
entry.sourceColumn = handleLoc.column - 1;
entry.sourceLine = handleLoc.line - 1;
@@ -293,6 +294,10 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager)
}
}
+ // Associate the sourceMap with the obfuscated file
+ obfuscatedFile->setObfuscatedSourceMap(sourceMap);
+
+ // Set the obfuscated map onto the module
module->setObfuscatedSourceMap(sourceMap);
return SLANG_OK;