From 9a6eec6192a373d8c14073f63f68e160d762ee50 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 18 Sep 2020 11:02:06 -0400 Subject: Control container serialization with SerialOptionFlags (#1550) * 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. * Add flags to control what is output in SerialContainer. Turn off AST output for obfuscated code. Lazily create astClasses when doing write container serialization. * Typo fix for Clang/Linux. --- source/slang/slang-serialize-container.cpp | 35 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'source/slang/slang-serialize-container.cpp') diff --git a/source/slang/slang-serialize-container.cpp b/source/slang/slang-serialize-container.cpp index 6f6438947..23aacc5d3 100644 --- a/source/slang/slang-serialize-container.cpp +++ b/source/slang/slang-serialize-container.cpp @@ -88,11 +88,6 @@ namespace Slang { /* static */SlangResult SerialContainerUtil::write(const SerialContainerData& data, const WriteOptions& options, RiffContainer* container) { - //auto linkage = request->getLinkage(); - //auto sink = request->getSink(); - //auto frontEndReq = request->getFrontEndReq(); - //SourceManager* sourceManager = frontEndReq->getSourceManager(); - RefPtr debugWriter; // The string pool used across the whole of the container @@ -110,7 +105,7 @@ namespace Slang { container->write(&containerHeader, sizeof(containerHeader)); } - if (data.translationUnits.getCount()) + if (data.translationUnits.getCount() && (options.optionFlags & (SerialOptionFlag::IRModule | SerialOptionFlag::ASTModule))) { // Module list RiffContainer::ScopeChunk moduleListScope(container, RiffContainer::Chunk::Kind::List, SerialBinary::kTranslationUnitListFourCc); @@ -120,7 +115,7 @@ namespace Slang { debugWriter = new DebugSerialWriter(options.sourceManager); } - RefPtr astClasses = new ASTSerialClasses; + RefPtr astClasses; for (const auto& translationUnit : data.translationUnits) { @@ -128,7 +123,7 @@ namespace Slang { // We currently don't serialize it's name..., but support for that could be added. // Write the IR information - if (translationUnit.irModule) + if ((options.optionFlags & SerialOptionFlag::IRModule) && translationUnit.irModule) { IRSerialData serialData; IRSerialWriter writer; @@ -138,20 +133,28 @@ namespace Slang { // Write the AST information - if (ModuleDecl* moduleDecl = as(translationUnit.astRootNode)) + if (options.optionFlags & SerialOptionFlag::ASTModule) { - ModuleASTSerialFilter filter(moduleDecl); - ASTSerialWriter writer(astClasses, &filter, debugWriter); + if (ModuleDecl* moduleDecl = as(translationUnit.astRootNode)) + { + if (!astClasses) + { + astClasses = new ASTSerialClasses; + } - // Add the module and everything that isn't filtered out in the filter. - writer.addPointer(moduleDecl); + ModuleASTSerialFilter filter(moduleDecl); + ASTSerialWriter writer(astClasses, &filter, debugWriter); - // We can now serialize it into the riff container. - SLANG_RETURN_ON_FAIL(writer.writeIntoContainer(container)); + // Add the module and everything that isn't filtered out in the filter. + writer.addPointer(moduleDecl); + + // We can now serialize it into the riff container. + SLANG_RETURN_ON_FAIL(writer.writeIntoContainer(container)); + } } } - if (data.targetModules.getCount()) + if (data.targetModules.getCount() && (options.optionFlags & SerialOptionFlag::IRModule)) { // TODO: in the case where we have specialization, we might need // to serialize IR related to `program`... -- cgit v1.2.3