From c9cb051fae190acfc36813e4a23759fb9b9c3df3 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 16 Nov 2020 12:48:44 +0100 Subject: Implement hierarchical evaluation (WIP) --- flowgraph/node.cpp | 16 ++++++++++++---- flowgraph/scope.cpp | 10 ++++------ flowgraph/scope.h | 4 ++-- flowgraph/storage.cpp | 10 ++++++++++ flowgraph/storage.h | 5 ++++- 5 files changed, 32 insertions(+), 13 deletions(-) (limited to 'flowgraph') diff --git a/flowgraph/node.cpp b/flowgraph/node.cpp index e0912dc..2d757f9 100644 --- a/flowgraph/node.cpp +++ b/flowgraph/node.cpp @@ -4,6 +4,8 @@ #include +#include + using namespace FlowGraph; FlowGraph::Data& Node::destination() @@ -19,22 +21,28 @@ Data FlowGraph::MakeConstantInt(int i) { std::vector value(size_t(4), uint8_t(0)); *(reinterpret_cast(value.data())) = boost::endian::native_to_little(static_cast(i)); - return Data(DataType::Int, std::make_shared(value)); + return Data{DataType::Int, std::make_shared(value)}; } Data FlowGraph::MakeLocalPointer(FlowGraph::LocalScope& scope, const std::string& name) { - return Data(DataType::Pointer, std::make_shared(scope, name)); + Data data{DataType::Pointer, std::make_shared(scope, name)}; + scope.push_back(std::make_shared(data)); + return data; } Data FlowGraph::MakeLocalSize(FlowGraph::LocalScope& scope, const std::string& name) { - return Data(DataType::Size, std::make_shared(scope, name)); + Data data{DataType::Size, std::make_shared(scope, name)}; + scope.push_back(std::make_shared(data)); + return data; } Data FlowGraph::MakeTemporaryInt(FlowGraph::LocalScope& scope) { - return Data(DataType::Int, std::make_shared(scope)); + Data data{DataType::Int, std::make_shared(scope)}; + scope.push_back(std::make_shared(data)); + return data; } LocalScope& CreateScopeOp::scope() diff --git a/flowgraph/scope.cpp b/flowgraph/scope.cpp index 6c2e30c..54a3cca 100644 --- a/flowgraph/scope.cpp +++ b/flowgraph/scope.cpp @@ -12,16 +12,14 @@ void FlowGraph::LocalScope::append(const FlowGraph::LocalScope& other) m_variables.insert(m_variables.end(), other.m_variables.begin(), other.m_variables.end()); } -index_t FlowGraph::LocalScope::indexOfStorage(const TemporaryStorage& storage) const +index_t FlowGraph::LocalScope::indexOfStorage(const Storage& storage) const { + std::cout << "DEBUG: " << m_variables.size() << std::endl; for (index_t i = 0; i < m_variables.size(); i++) { FlowGraph::Storage& i_storage {*(m_variables[i]->storage())}; - if (typeid(i_storage) == typeid(FlowGraph::TemporaryStorage)) { - FlowGraph::TemporaryStorage& temporaryStorage{dynamic_cast(i_storage)}; - if (&temporaryStorage == &storage) // compare addresses - return i; - } + if (&i_storage == &storage) // compare addresses + return i; } throw std::runtime_error("ICE: Storage not found"); diff --git a/flowgraph/scope.h b/flowgraph/scope.h index 50003f4..65898cf 100644 --- a/flowgraph/scope.h +++ b/flowgraph/scope.h @@ -10,7 +10,7 @@ namespace FlowGraph { - class TemporaryStorage; ///< Forward declaration + class Storage; ///< Forward declaration // Provide a context for local temporaries name generation class LocalScope @@ -20,7 +20,7 @@ namespace FlowGraph { void push_back(std::shared_ptr data); void append(const LocalScope& other); - index_t indexOfStorage(const TemporaryStorage& storage) const; + index_t indexOfStorage(const Storage& storage) const; private: std::vector> m_variables; diff --git a/flowgraph/storage.cpp b/flowgraph/storage.cpp index 7e502de..e9577d6 100644 --- a/flowgraph/storage.cpp +++ b/flowgraph/storage.cpp @@ -11,3 +11,13 @@ std::string FlowGraph::TemporaryStorage::name() const { return "__local_"s + std::to_string(m_scope.indexOfStorage(*this)); } + +index_t FlowGraph::TemporaryStorage::indexOfStorage() const +{ + return m_scope.indexOfStorage(*this); +} + +index_t FlowGraph::LocalStorage::indexOfStorage() const +{ + return m_scope.indexOfStorage(*this); +} diff --git a/flowgraph/storage.h b/flowgraph/storage.h index 7f648b0..27c201e 100644 --- a/flowgraph/storage.h +++ b/flowgraph/storage.h @@ -42,10 +42,12 @@ namespace FlowGraph { class LocalStorage : public Storage { public: - LocalStorage(LocalScope& scope, const std::string& name): m_name(name) {} + LocalStorage(LocalScope& scope, const std::string& name): m_name(name), m_scope(scope) {} const std::string& name() const { return m_name; } + index_t indexOfStorage() const; private: std::string m_name; + LocalScope& m_scope; }; // intermediate results, anonymous values @@ -55,6 +57,7 @@ namespace FlowGraph { public: TemporaryStorage(LocalScope& scope); std::string name() const; + index_t indexOfStorage() const; private: LocalScope& m_scope; }; -- cgit v1.2.3