diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-08-31 13:02:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-31 13:02:55 -0400 |
| commit | 69025ad82238a7402b18d9c566fac1574faef684 (patch) | |
| tree | ab01e4248071f9f597aa04f15742852a7662ed23 /source/slang/slang-ir-serialize.cpp | |
| parent | baa789e0c9109bcb1e717ce4a9953709e7345e55 (diff) | |
AST Serialization in Modules (#1524)
* First pass at filter for AST serial writing.
* Serialization of AST for modules.
* Removed some commented out source.
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-ir-serialize.cpp')
| -rw-r--r-- | source/slang/slang-ir-serialize.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/source/slang/slang-ir-serialize.cpp b/source/slang/slang-ir-serialize.cpp index 64316d457..1aa6b1d85 100644 --- a/source/slang/slang-ir-serialize.cpp +++ b/source/slang/slang-ir-serialize.cpp @@ -989,30 +989,22 @@ static int _calcFixSourceLoc(const IRSerialData::DebugSourceInfo& info, SourceVi return int(sourceView->getRange().begin.getRaw()) - int(info.m_startSourceLoc); } -// TODO: The following function isn't really part of the IR serialization system, but rather -// a layered "container" format, and as such probably belongs in a higher-level system that -// simply calls into the `IRSerialReader` rather than being part of it... -// -/* static */Result IRSerialReader::readStreamModules(Stream* stream, Session* session, SourceManager* sourceManager, List<RefPtr<IRModule>>& outModules, List<FrontEndCompileRequest::ExtraEntryPointInfo>& outEntryPoints) +/* static */Result IRSerialReader::readContainerModules(RiffContainer* container, Session* session, SourceManager* sourceManager, List<RefPtr<IRModule>>& outModules, List<FrontEndCompileRequest::ExtraEntryPointInfo>& outEntryPoints) { - // Load up the module - RiffContainer container; - SLANG_RETURN_ON_FAIL(RiffUtil::read(stream, container)); - List<RiffContainer::ListChunk*> moduleChunks; List<RiffContainer::DataChunk*> entryPointChunks; // First try to find a list { - RiffContainer::ListChunk* listChunk = container.getRoot()->findListRec(IRSerialBinary::kSlangModuleListFourCc); + RiffContainer::ListChunk* listChunk = container->getRoot()->findListRec(SerialBinary::kSlangModuleListFourCc); if (listChunk) { listChunk->findContained(IRSerialBinary::kSlangModuleFourCc, moduleChunks); - listChunk->findContained(IRSerialBinary::kEntryPointFourCc, entryPointChunks); + listChunk->findContained(SerialBinary::kEntryPointFourCc, entryPointChunks); } else { // Maybe its just a single module - RiffContainer::ListChunk* moduleChunk = container.getRoot()->findListRec(IRSerialBinary::kSlangModuleFourCc); + RiffContainer::ListChunk* moduleChunk = container->getRoot()->findListRec(IRSerialBinary::kSlangModuleFourCc); if (!moduleChunk) { // Couldn't find any modules @@ -1037,7 +1029,7 @@ static int _calcFixSourceLoc(const IRSerialData::DebugSourceInfo& info, SourceVi outModules.add(irModule); } - for( auto entryPointChunk : entryPointChunks ) + for (auto entryPointChunk : entryPointChunks) { auto reader = entryPointChunk->asReadHelper(); @@ -1046,8 +1038,8 @@ static int _calcFixSourceLoc(const IRSerialData::DebugSourceInfo& info, SourceVi uint32_t length = 0; reader.read(length); - char* begin = (char*) reader.getData(); - reader.skip(length+1); + char* begin = (char*)reader.getData(); + reader.skip(length + 1); return UnownedStringSlice(begin, begin + length); }; @@ -1064,6 +1056,21 @@ static int _calcFixSourceLoc(const IRSerialData::DebugSourceInfo& info, SourceVi return SLANG_OK; } + +// TODO: The following function isn't really part of the IR serialization system, but rather +// a layered "container" format, and as such probably belongs in a higher-level system that +// simply calls into the `IRSerialReader` rather than being part of it... +// +/* static */Result IRSerialReader::readStreamModules(Stream* stream, Session* session, SourceManager* sourceManager, List<RefPtr<IRModule>>& outModules, List<FrontEndCompileRequest::ExtraEntryPointInfo>& outEntryPoints) +{ + // Load up the module + RiffContainer container; + SLANG_RETURN_ON_FAIL(RiffUtil::read(stream, container)); + + SLANG_RETURN_ON_FAIL(readContainerModules(&container, session, sourceManager, outModules, outEntryPoints)); + return SLANG_OK; +} + /* static */Result IRSerialReader::read(const IRSerialData& data, Session* session, SourceManager* sourceManager, RefPtr<IRModule>& moduleOut) { typedef Ser::Inst::PayloadType PayloadType; |
