diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-09-17 16:47:57 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-17 13:47:57 -0700 |
| commit | b9cddcb9c718f986ee5e4f7c6189ee2ebea4ace1 (patch) | |
| tree | d4537f98e8ec93459f13d2d271d621b80f797a59 /source/slang/slang.cpp | |
| parent | bbf492a0b78ce8b96372a736b7d591cdc71d5b65 (diff) | |
Share debug information between AST and IR (#1547)
* Test if blob is returned.
* Rename serialize files so can be grouped.
* StringRepresentationCache -> SerialStringTable
* Split out SerialStringTable from slang-serialize-ir
* First pass at reorganizing serialization/containers. Remain some issues about debug info.
* Fix bug in calculating sourceloc.
* Improve calcFixSourceLoc
* Make allocations for payload RiffContainer align to at least 8 bytes. This is important for read, if the payload can contain 8 byte aligned data. Note this has no effect on Riff file format alignment rules.
* Improve comments around RiffContainer and alignment.
* Remove SerialStringTable, can just use StringSlicePool instead.
* Typo fix for Clang/Linux.
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 4c83095c2..c9dccbdbf 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -14,9 +14,6 @@ #include "slang-reflection.h" #include "slang-type-layout.h" -#include "slang-ast-dump.h" -#include "slang-ast-serialize.h" - #include "slang-repro.h" #include "slang-file-system.h" @@ -25,7 +22,11 @@ #include "slang-source-loc.h" -#include "slang-ir-serialize.h" +#include "slang-ast-dump.h" + +#include "slang-serialize-ast.h" +#include "slang-serialize-ir.h" +#include "slang-serialize-container.h" #include "slang-check-impl.h" @@ -1074,20 +1075,25 @@ void FrontEndCompileRequest::generateIR() if (verifyDebugSerialization) { + SerialContainerUtil::WriteOptions options; + options.compressionType = SerialCompressionType::None; + options.sourceManager = getSourceManager(); + options.optionFlags = SerialOptionFlag::DebugInfo; + // Verify debug information - if (SLANG_FAILED(IRSerialUtil::verifySerialize(irModule, getSession(), getSourceManager(), IRSerialBinary::CompressionType::None, IRSerialWriter::OptionFlag::DebugInfo))) + if (SLANG_FAILED(SerialContainerUtil::verifyIRSerialize(irModule, getSession(), options))) { getSink()->diagnose(irModule->moduleInst->sourceLoc, Diagnostics::serialDebugVerificationFailed); } } if (useSerialIRBottleneck) - { + { IRSerialData serialData; { // Write IR out to serialData - copying over SourceLoc information directly IRSerialWriter writer; - writer.write(irModule, getSourceManager(), IRSerialWriter::OptionFlag::RawSourceLocation, &serialData); + writer.write(irModule, nullptr, SerialOptionFlag::RawSourceLocation, &serialData); // Destroy irModule such that memory can be used for newly constructed read irReadModule irModule = nullptr; @@ -3013,33 +3019,47 @@ namespace Slang SlangResult _addLibraryReference(EndToEndCompileRequest* req, Stream* stream) { // Load up the module - RiffContainer container; - SLANG_RETURN_ON_FAIL(RiffUtil::read(stream, container)); + RiffContainer riffContainer; + SLANG_RETURN_ON_FAIL(RiffUtil::read(stream, riffContainer)); + + auto linkage = req->getLinkage(); - List<RefPtr<Module>> modules; + // TODO(JS): May be better to have a ITypeComponent that encapsulates a collection of modules + // For now just add to the linkage - if (SLANG_FAILED(ASTSerialReader::readContainerModules(&container, req->getLinkage(), modules))) { - req->getSink()->diagnose(SourceLoc(), Diagnostics::unableToAddReferenceToModuleContainer); - return SLANG_FAIL; - } + SerialContainerData containerData; - // Read all of the contained modules - List<RefPtr<IRModule>> irModules; - List<FrontEndCompileRequest::ExtraEntryPointInfo> entryPointMangledNames; + SerialContainerUtil::ReadOptions options; + options.namePool = req->getNamePool(); + options.session = req->getSession(); + options.sharedASTBuilder = linkage->getASTBuilder()->getSharedASTBuilder(); + options.sourceManager = linkage->getSourceManager(); - if (SLANG_FAILED(IRSerialReader::readContainerModules(&container, req->getSession(), req->getFrontEndReq()->getSourceManager(), irModules, entryPointMangledNames))) - { - req->getSink()->diagnose(SourceLoc(), Diagnostics::unableToAddReferenceToModuleContainer); - return SLANG_FAIL; - } + SLANG_RETURN_ON_FAIL(SerialContainerUtil::read(&riffContainer, options, containerData)); - // TODO(JS): May be better to have a ITypeComponent that encapsulates a collection of modules - // For now just add to the linkage - auto linkage = req->getLinkage(); - linkage->m_libModules.addRange(irModules); + for (const auto& translationUnit : containerData.translationUnits) + { + // If the irModule is set, add it + if (translationUnit.irModule) + { + linkage->m_libModules.add(translationUnit.irModule); + } + } + + FrontEndCompileRequest* frontEndRequest = req->getFrontEndReq(); + + for (const auto& entryPoint : containerData.entryPoints) + { + FrontEndCompileRequest::ExtraEntryPointInfo dst; + dst.mangledName = entryPoint.mangledName; + dst.name = entryPoint.name; + dst.profile = entryPoint.profile; - req->getFrontEndReq()->m_extraEntryPoints.addRange(entryPointMangledNames); + // Add entry point + frontEndRequest->m_extraEntryPoints.add(dst); + } + } return SLANG_OK; } |
