diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-04-18 12:36:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-18 12:36:06 -0400 |
| commit | 181fd1f3c9c4b047c1947096e7b3f8e5bc2314c3 (patch) | |
| tree | 308cbadae2f68d43ca20f92755b08db08e8b2283 /source/slang/slang-compiler.cpp | |
| parent | 90a9f43573ec0777c2ae4fa20c8fdc51a4ae7b3a (diff) | |
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.
Diffstat (limited to 'source/slang/slang-compiler.cpp')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 28 |
1 files changed, 4 insertions, 24 deletions
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> 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<IObjectCastableAdapter> castableAdapter(new ObjectCastableAdapter(sourceMap)); + sourceMapArtifact->addRepresentation(castableAdapter); // Associate with the container m_containerArtifact->addAssociated(sourceMapArtifact); |
