From 181fd1f3c9c4b047c1947096e7b3f8e5bc2314c3 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 18 Apr 2023 12:36:06 -0400 Subject: On demand SourceMap JSON serialization (#2811) * #include an absolute path didn't work - because paths were taken to always be relative. * Moved JSON source map writing logic to JSONSourceMapUtil. * Use ArtifactHandler to read/write SourceMaps. Use ObjectCastableAdapter to hold SourceMap Only serialize SourceMap <-> JSON on demand. --- source/slang/slang-compiler.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'source/slang/slang-compiler.cpp') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index becd65596..907f39f48 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -15,8 +15,6 @@ #include "../compiler-core/slang-lexer.h" -#include "../compiler-core/slang-json-source-map-util.h" - // Artifact #include "../compiler-core/slang-artifact-desc-util.h" #include "../compiler-core/slang-artifact-representation-impl.h" @@ -1902,9 +1900,6 @@ namespace Slang auto frontEndReq = getFrontEndReq(); - auto sourceManager = frontEndReq->getSourceManager(); - auto sink = getSink(); - for (auto translationUnit : frontEndReq->translationUnits) { // Hmmm do I have to therefore add a map for all translation units(!) @@ -1915,29 +1910,14 @@ namespace Slang // If we have a source map *and* we want to generate them for output add to the container if (sourceMap && getLinkage()->m_generateSourceMap) { - // Write it out - String json; - { - RefPtr jsonContainer(new JSONContainer(sourceManager)); - - JSONValue jsonValue; - - SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::encode(sourceMap, jsonContainer, sink, jsonValue)); - - // Convert into a string - JSONWriter writer(JSONWriter::IndentationStyle::Allman); - jsonContainer->traverseRecursively(jsonValue, &writer); - - json = writer.getBuilder(); - } - - auto jsonSourceMapBlob = StringBlob::moveCreate(json); - auto artifactDesc = ArtifactDesc::make(ArtifactKind::Json, ArtifactPayload::SourceMap, ArtifactStyle::Obfuscated); // Create the source map artifact auto sourceMapArtifact = Artifact::create(artifactDesc, sourceMap->m_file.getUnownedSlice()); - sourceMapArtifact->addRepresentationUnknown(jsonSourceMapBlob); + + // Add the repesentation + ComPtr castableAdapter(new ObjectCastableAdapter(sourceMap)); + sourceMapArtifact->addRepresentation(castableAdapter); // Associate with the container m_containerArtifact->addAssociated(sourceMapArtifact); -- cgit v1.2.3