diff options
Diffstat (limited to 'source/slang/slang-serialize-ir.h')
| -rw-r--r-- | source/slang/slang-serialize-ir.h | 127 |
1 files changed, 15 insertions, 112 deletions
diff --git a/source/slang/slang-serialize-ir.h b/source/slang/slang-serialize-ir.h index f6ab7e9ad..0ac188df7 100644 --- a/source/slang/slang-serialize-ir.h +++ b/source/slang/slang-serialize-ir.h @@ -1,121 +1,24 @@ -// slang-serialize-ir.h -#ifndef SLANG_SERIALIZE_IR_H_INCLUDED -#define SLANG_SERIALIZE_IR_H_INCLUDED +#pragma once -#include "../core/slang-riff.h" -#include "slang-ir.h" -#include "slang-serialize-ir-types.h" -#include "slang-serialize-source-loc.h" - -// For TranslationUnitRequest -// and FrontEndCompileRequest::ExtraEntryPointInfo -#include "slang-compiler.h" +#include "core/slang-riff.h" namespace Slang { -struct IRModuleChunk : RIFF::ListChunk -{ -}; - -struct IRSerialWriter -{ - typedef IRSerialData Ser; - typedef IRSerialBinary Bin; - - Result write( - IRModule* module, - SerialSourceLocWriter* sourceLocWriter, - IRSerialData* serialData); - - /// Write to a container - static Result writeTo(const IRSerialData& data, RIFF::BuildCursor& cursor); - - /// Get an instruction index from an instruction - Ser::InstIndex getInstIndex(IRInst* inst) const - { - return inst ? Ser::InstIndex(m_instMap.getValue(inst)) : Ser::InstIndex(0); - } - - /// Get a slice from an index - UnownedStringSlice getStringSlice(Ser::StringIndex index) const - { - return m_stringSlicePool.getSlice(StringSlicePool::Handle(index)); - } - /// Get index from string representations - Ser::StringIndex getStringIndex(StringRepresentation* string) - { - return Ser::StringIndex(m_stringSlicePool.add(string)); - } - Ser::StringIndex getStringIndex(const UnownedStringSlice& slice) - { - return Ser::StringIndex(m_stringSlicePool.add(slice)); - } - Ser::StringIndex getStringIndex(Name* name) - { - return name ? getStringIndex(name->text) : SerialStringData::kNullStringIndex; - } - Ser::StringIndex getStringIndex(const char* chars) - { - return Ser::StringIndex(m_stringSlicePool.add(chars)); - } - Ser::StringIndex getStringIndex(const String& string) - { - return Ser::StringIndex(m_stringSlicePool.add(string.getUnownedSlice())); - } - - StringSlicePool& getStringPool() { return m_stringSlicePool; } - - IRSerialWriter() - : m_serialData(nullptr), m_stringSlicePool(StringSlicePool::Style::Default) - { - } - - /// Produces an instruction list which is in same order as written through IRSerialWriter - static void calcInstructionList(IRModule* module, List<IRInst*>& instsOut); -protected: - void _addInstruction(IRInst* inst); - Result _calcDebugInfo(SerialSourceLocWriter* sourceLocWriter); +struct IRModule; +class Session; +class SerialSourceLocReader; +class SerialSourceLocWriter; - List<IRInst*> m_insts; ///< Instructions in same order as stored in the +void writeSerializedModuleIR( + RIFF::BuildCursor& cursor, + IRModule* moduleDecl, + SerialSourceLocWriter* sourceLocWriter); - List<IRDecoration*> - m_decorations; ///< Holds all decorations in order of the instructions as found - List<IRInst*> m_instWithFirstDecoration; ///< All decorations are held in this order after all - ///< the regular instructions - - Dictionary<IRInst*, Ser::InstIndex> m_instMap; ///< Map an instruction to an instruction index - - StringSlicePool m_stringSlicePool; - IRSerialData* m_serialData; ///< Where the data is stored -}; - -struct IRSerialReader -{ - typedef IRSerialData Ser; - - /// Read a stream to fill in dataOut IRSerialData - static Result readFrom(IRModuleChunk const* irModuleChunk, IRSerialData* outData); - - /// Read a module from serial data - Result read( - const IRSerialData& data, - Session* session, - SerialSourceLocReader* sourceLocReader, - RefPtr<IRModule>& outModule); - - IRSerialReader() - : m_serialData(nullptr), m_module(nullptr), m_stringTable(StringSlicePool::Style::Default) - { - } - -protected: - StringSlicePool m_stringTable; - - const IRSerialData* m_serialData; - IRModule* m_module; -}; +void readSerializedModuleIR( + RIFF::Chunk const* chunk, + Session* session, + SerialSourceLocReader* sourceLocReader, + RefPtr<IRModule>& outIRModule); } // namespace Slang - -#endif |
