From b9cddcb9c718f986ee5e4f7c6189ee2ebea4ace1 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 17 Sep 2020 16:47:57 -0400 Subject: 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 --- source/slang/slang-serialize-container.h | 107 +++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 source/slang/slang-serialize-container.h (limited to 'source/slang/slang-serialize-container.h') diff --git a/source/slang/slang-serialize-container.h b/source/slang/slang-serialize-container.h new file mode 100644 index 000000000..2f2f509b8 --- /dev/null +++ b/source/slang/slang-serialize-container.h @@ -0,0 +1,107 @@ +// slang-serialize-container.h +#ifndef SLANG_SERIALIZE_CONTAINER_H +#define SLANG_SERIALIZE_CONTAINER_H + +#include "../core/slang-riff.h" +#include "slang-serialize-types.h" +#include "slang-ir-insts.h" +#include "slang-profile.h" + +namespace Slang { + +class EndToEndCompileRequest; + +/* The binary representation actually held in riff/file format*/ +struct SerialContainerBinary +{ + struct Target + { + uint32_t target; + uint32_t flags; + uint32_t profile; + uint32_t floatingPointMode; + }; + + struct EntryPoint + { + uint32_t name; + uint32_t profile; + uint32_t mangledName; + }; +}; + +/* Struct that holds all the data that can be held in a 'container' */ +struct SerialContainerData +{ + struct Target + { + CodeGenTarget codeGenTarget = CodeGenTarget::Unknown; + SlangTargetFlags flags = 0; + Profile profile; + FloatingPointMode floatingPointMode = FloatingPointMode::Default; + }; + + struct TargetModule + { + // IR module for a specific compilation target + Target target; + RefPtr irModule; + }; + + struct TranslationUnit + { + RefPtr irModule; + RefPtr astBuilder; + NodeBase* astRootNode = nullptr; + }; + + struct EntryPoint + { + Name* name = nullptr; + Profile profile; + String mangledName; + }; + + void clear() + { + entryPoints.clear(); + translationUnits.clear(); + targetModules.clear(); + } + + List translationUnits; + List targetModules; + List entryPoints; +}; + +struct SerialContainerUtil +{ + struct WriteOptions + { + SerialCompressionType compressionType = SerialCompressionType::VariableByteLite; + SerialOptionFlags optionFlags = 0; + SourceManager* sourceManager = nullptr; + }; + + struct ReadOptions + { + Session* session = nullptr; + SourceManager* sourceManager = nullptr; + NamePool* namePool = nullptr; + SharedASTBuilder* sharedASTBuilder = nullptr; + }; + + /// Get the serializable contents of the request as data + static SlangResult requestToData(EndToEndCompileRequest* request, const WriteOptions& options, SerialContainerData& outData); + + static SlangResult write(const SerialContainerData& data, const WriteOptions& options, RiffContainer* container); + + static SlangResult read(RiffContainer* container, const ReadOptions& options, SerialContainerData& out); + + /// Verify IR serialization + static SlangResult verifyIRSerialize(IRModule* module, Session* session, const WriteOptions& options); +}; + +} // namespace Slang + +#endif -- cgit v1.2.3