summaryrefslogtreecommitdiff
path: root/source/core/slang-riff.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-09-17 16:47:57 -0400
committerGitHub <noreply@github.com>2020-09-17 13:47:57 -0700
commitb9cddcb9c718f986ee5e4f7c6189ee2ebea4ace1 (patch)
treed4537f98e8ec93459f13d2d271d621b80f797a59 /source/core/slang-riff.h
parentbbf492a0b78ce8b96372a736b7d591cdc71d5b65 (diff)
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 <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/core/slang-riff.h')
-rw-r--r--source/core/slang-riff.h38
1 files changed, 29 insertions, 9 deletions
diff --git a/source/core/slang-riff.h b/source/core/slang-riff.h
index 9bdbcfdeb..43c5e285d 100644
--- a/source/core/slang-riff.h
+++ b/source/core/slang-riff.h
@@ -177,6 +177,14 @@ need to be recalculated, before serialization.
class RiffContainer
{
public:
+ enum
+ {
+ // This alignment is only made for arena based allocations.
+ // For external blocks it's client code to have appropriate alignment.
+ // This is needed because when reading a RiffContainer, all allocation is arena based, and
+ // if the payload contains 8 byte aligned data, the overall payload needs to be 8 byte aligned.
+ PAYLOAD_MIN_ALIGNMENT = 8,
+ };
enum class Ownership
{
@@ -186,10 +194,6 @@ public:
Owned, ///< It's owned, but wasn't allocated on the arena
};
- struct ListChunk;
- struct DataChunk;
-
-
struct Data
{
/// Get the payload
@@ -214,8 +218,11 @@ public:
};
struct Chunk;
- typedef SlangResult(*VisitorCallback)(Chunk* chunk, void* data);
+ struct ListChunk;
+ struct DataChunk;
+ typedef SlangResult(*VisitorCallback)(Chunk* chunk, void* data);
+
class Visitor;
struct Chunk
{
@@ -270,6 +277,8 @@ public:
void* findContainedData(FourCC type, size_t minSize) const;
+ ListChunk* findContainedList(FourCC type);
+
/// Finds the contained data. NOTE! Assumes that there is only as single data block, and will return nullptr if there is not
Data* findContainedData(FourCC type) const;
@@ -291,6 +300,9 @@ public:
/// Get the sub type
FourCC getSubType() const { return m_fourCC; }
+ /// A singly linked list of contained chunks directly contained in this chunk
+ Chunk* getFirstContainedChunk() const { return m_containedChunks; }
+
Chunk* m_containedChunks; ///< The contained chunks
Chunk* m_endChunk; ///< The last chunk (only set when pushed, and used when popped)
};
@@ -416,9 +428,14 @@ protected:
template <typename T>
T* as(RiffContainer::Chunk* chunk)
{
- return T::isType(chunk) ? static_cast<T*>(chunk) : nullptr;
+ return chunk && T::isType(chunk) ? static_cast<T*>(chunk) : nullptr;
+}
+// -----------------------------------------------------------------------------
+template <typename T>
+T* as(RiffContainer::Chunk* chunk, FourCC fourCC)
+{
+ return chunk && chunk->m_fourCC == fourCC && T::isType(chunk) ? static_cast<T*>(chunk) : nullptr;
}
-
struct RiffUtil
{
@@ -449,8 +466,11 @@ struct RiffUtil
/// Get the size taking into account padding
static size_t getPadSize(size_t in) { return (in + kRiffPadMask) & ~size_t(kRiffPadMask); }
- /// Write a container and contents to a stream
- static SlangResult write(ListChunk* container, bool isRoot, Stream* stream);
+ /// Write a chunk list and contents to a stream
+ static SlangResult write(ListChunk* listChunk, bool isRoot, Stream* stream);
+ /// Write a container to the stream
+ static SlangResult write(RiffContainer* container, Stream* stream);
+
/// Read the stream into the container
static SlangResult read(Stream* stream, RiffContainer& outContainer);
};