summaryrefslogtreecommitdiff
path: root/source/slang/slang-serialize-container.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-09-18 11:02:06 -0400
committerGitHub <noreply@github.com>2020-09-18 11:02:06 -0400
commit9a6eec6192a373d8c14073f63f68e160d762ee50 (patch)
tree3be256501344c159237db426f518ea0d0901c832 /source/slang/slang-serialize-container.cpp
parent2ddca33686c08e1833c0d82a420fb2b27cde4e37 (diff)
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.
Diffstat (limited to 'source/slang/slang-serialize-container.cpp')
-rw-r--r--source/slang/slang-serialize-container.cpp35
1 files changed, 19 insertions, 16 deletions
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<DebugSerialWriter> 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<ASTSerialClasses> astClasses = new ASTSerialClasses;
+ RefPtr<ASTSerialClasses> 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<ModuleDecl>(translationUnit.astRootNode))
+ if (options.optionFlags & SerialOptionFlag::ASTModule)
{
- ModuleASTSerialFilter filter(moduleDecl);
- ASTSerialWriter writer(astClasses, &filter, debugWriter);
+ if (ModuleDecl* moduleDecl = as<ModuleDecl>(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`...