summaryrefslogtreecommitdiffstats
path: root/source/core
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
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')
-rw-r--r--source/core/slang-riff.cpp25
-rw-r--r--source/core/slang-riff.h38
2 files changed, 51 insertions, 12 deletions
diff --git a/source/core/slang-riff.cpp b/source/core/slang-riff.cpp
index 9fc23fbc8..2162c40be 100644
--- a/source/core/slang-riff.cpp
+++ b/source/core/slang-riff.cpp
@@ -313,6 +313,11 @@ struct DumpVisitor : public RiffContainer::Visitor
return SLANG_OK;
}
+/* static */SlangResult RiffUtil::write(RiffContainer* container, Stream* stream)
+{
+ return write(container->getRoot(), true, stream);
+}
+
/* static */SlangResult RiffUtil::read(Stream* stream, RiffContainer& outContainer)
{
typedef RiffContainer::ScopeChunk ScopeChunk;
@@ -561,6 +566,20 @@ void RiffContainer::ListChunk::findContained(FourCC type, List<DataChunk*>& out)
}
}
+RiffContainer::ListChunk* RiffContainer::ListChunk::findContainedList(FourCC type)
+{
+ Chunk* chunk = m_containedChunks;
+ while (chunk)
+ {
+ if (chunk->m_fourCC == type && chunk->m_kind == Chunk::Kind::List)
+ {
+ return static_cast<ListChunk*>(chunk);
+ }
+ chunk = chunk->m_next;
+ }
+ return nullptr;
+}
+
RiffContainer::Data* RiffContainer::ListChunk::findContainedData(FourCC type) const
{
Chunk* found = findContained(type);
@@ -841,11 +860,11 @@ void RiffContainer::setPayload(Data* data, const void* payload, size_t size)
// Add current chunks data
m_dataChunk->m_payloadSize += size;
-
+
data->m_ownership = Ownership::Arena;
data->m_size = size;
- data->m_payload = m_arena.allocate(size);
+ data->m_payload = m_arena.allocateAligned(size, PAYLOAD_MIN_ALIGNMENT);
if (payload)
{
@@ -922,7 +941,7 @@ RiffContainer::Data* RiffContainer::makeSingleData(DataChunk* dataChunk)
// Okay lets combine all into one block
const size_t payloadSize = dataChunk->calcPayloadSize();
- void* dst = m_arena.allocate(payloadSize);
+ void* dst = m_arena.allocateAligned(payloadSize, PAYLOAD_MIN_ALIGNMENT);
dataChunk->getPayload(dst);
// Remove other datas
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);
};