From ad3fd947005400c90f41baa4416a27d94b1bc157 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 22 Nov 2020 17:11:11 +0100 Subject: Clarify flowgraph types --- flowgraph/data.h | 32 +++++++++++++++++++++++--------- flowgraph/node.cpp | 8 ++++---- flowgraph/node.h | 2 +- flowgraph/storage.h | 17 ----------------- tests/test-flowgraph.cpp | 2 +- 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/flowgraph/data.h b/flowgraph/data.h index 2b92b2e..65bac8f 100644 --- a/flowgraph/data.h +++ b/flowgraph/data.h @@ -8,18 +8,32 @@ namespace FlowGraph { - // Explicitely not including size + // Data models: + // 64 bit Linux: LLP64 + // 64 bit Windows: LP64 + // + // Explicitely NOT defined here: + // * Size (same as Pointer, LongLong on Linux and Windows) + // * Bool (Byte) + // * Long (different on Linux (64 bit) and Windows (32 bit)) enum class DataType: int { - Size, - Int, + Char, // 8 bit + UChar, // 8 bit + + Short, // 16 bit on 64 bit Linux and Windows + UShort, + + Int, // 32 bit on 64 bit Linux and Windows UInt, - Pointer, - Bool, - Char, - UChar, - Short, - UShort + + LongLong, // 64 bit on 64 bit Linux and Windows + ULongLong, + + Pointer, // 64 bit on 64 bit Linux and Windows, size is same size + + Float, // 32 bit, IEEE 754 + Double // 64 bit, IEEE 754 }; class Storage; ///< forward declaration diff --git a/flowgraph/node.cpp b/flowgraph/node.cpp index d7ed939..cb7677a 100644 --- a/flowgraph/node.cpp +++ b/flowgraph/node.cpp @@ -22,16 +22,16 @@ Data FlowGraph::MakeConstantInt(int i) return Data{DataType::Int, std::make_shared(endian::to_little(uint32_t(i)))}; } -Data FlowGraph::MakeLocalPointer(std::shared_ptr scope, const std::string& name) +Data FlowGraph::MakeLocalInt(std::shared_ptr scope, const std::string& name) { - Data data{DataType::Pointer, std::make_shared(name)}; + Data data{DataType::Int, std::make_shared(name)}; scope->push_back(std::make_shared(data)); return data; } -Data FlowGraph::MakeLocalSize(std::shared_ptr scope, const std::string& name) +Data FlowGraph::MakeLocalPointer(std::shared_ptr scope, const std::string& name) { - Data data{DataType::Size, std::make_shared(name)}; + Data data{DataType::Pointer, std::make_shared(name)}; scope->push_back(std::make_shared(data)); return data; } diff --git a/flowgraph/node.h b/flowgraph/node.h index def3c04..34e937b 100644 --- a/flowgraph/node.h +++ b/flowgraph/node.h @@ -48,8 +48,8 @@ namespace FlowGraph { }; Data MakeConstantInt(int i); + Data MakeLocalInt(std::shared_ptr scope, const std::string& name); Data MakeLocalPointer(std::shared_ptr scope, const std::string& name); - Data MakeLocalSize(std::shared_ptr scope, const std::string& name); Data MakeTemporaryInt(std::shared_ptr scope); class MemCopy: public Node diff --git a/flowgraph/storage.h b/flowgraph/storage.h index 7b5c53b..9e95905 100644 --- a/flowgraph/storage.h +++ b/flowgraph/storage.h @@ -57,21 +57,4 @@ namespace FlowGraph { TemporaryStorage(); }; - // dereferenced pointer - class PointeeStorage : public Storage - { - public: - PointeeStorage(const Data& pointer, const Data& offset): m_pointer(pointer), m_offset(offset) { - if (pointer.type() != DataType::Pointer) - throw std::runtime_error("Pointer argument must be a DataType::Pointer"); - if (offset.type() != DataType::Size) - throw std::runtime_error("Offset argument must be a DataType::Size"); - } - Data pointer() { return m_pointer; } - Data offset() { return m_offset; } - private: - Data m_pointer; - Data m_offset; - }; - } diff --git a/tests/test-flowgraph.cpp b/tests/test-flowgraph.cpp index 469d816..b0daeae 100644 --- a/tests/test-flowgraph.cpp +++ b/tests/test-flowgraph.cpp @@ -44,7 +44,7 @@ TEST_F(FlowGraphTest, build_graph) { graph.push_back(createScope); Data pointer{ MakeLocalPointer(createScope->scope(), "malloc1") }; - Data size{ MakeLocalSize(createScope->scope(), "size1") }; + Data size{ MakeLocalInt(createScope->scope(), "size1") }; std::shared_ptr malloc1 {std::make_shared(pointer, size) }; graph.push_back(malloc1); -- cgit v1.2.3