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-emit.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index e2948561c..67a4c4610 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -82,7 +82,7 @@ #include "../compiler-core/slang-artifact-impl.h" #include "../compiler-core/slang-artifact-associated-impl.h" -#include "../compiler-core/slang-json-source-map-util.h" +#include "../core/slang-castable.h" #include @@ -1152,28 +1152,10 @@ SlangResult CodeGenContext::emitEntryPointsSourceFromIR(ComPtr& outAr if (sourceMap) { - SourceManager sourceMapSourceManager; - sourceMapSourceManager.initialize(nullptr, nullptr); - - // Create a sink - DiagnosticSink sourceMapSink(&sourceMapSourceManager, nullptr); - - // Turn into JSON - RefPtr jsonContainer(new JSONContainer(&sourceMapSourceManager)); - - JSONValue jsonValue; - SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::encode(sourceMap, jsonContainer, &sourceMapSink, jsonValue)); - - // Okay now convert this into a text file and then a blob - - // Convert into a string - JSONWriter writer(JSONWriter::IndentationStyle::KNR); - jsonContainer->traverseRecursively(jsonValue, &writer); - - auto sourceMapBlob = StringBlob::moveCreate(writer.getBuilder()); - auto sourceMapArtifact = ArtifactUtil::createArtifact(ArtifactDesc::make(ArtifactKind::Json, ArtifactPayload::SourceMap, ArtifactStyle::None)); - sourceMapArtifact->addRepresentationUnknown(sourceMapBlob); + + ComPtr castableAdapter(new ObjectCastableAdapter(sourceMap)); + sourceMapArtifact->addRepresentation(castableAdapter); artifact->addAssociated(sourceMapArtifact); } -- cgit v1.2.3