diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-11-17 12:38:40 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-11-17 12:38:40 +0100 | 
| commit | 927eb99e75325164a541c2638e1e607294019381 (patch) | |
| tree | 5b5476456f0f957fc7492465ff08ace54e1a9e48 /flowgraph | |
| parent | c9cb051fae190acfc36813e4a23759fb9b9c3df3 (diff) | |
Complete hierarchical evaluation (unittest and systemtest fixed)
Diffstat (limited to 'flowgraph')
| -rw-r--r-- | flowgraph/data.cpp | 20 | ||||
| -rw-r--r-- | flowgraph/data.h | 7 | ||||
| -rw-r--r-- | flowgraph/graph.cpp | 8 | ||||
| -rw-r--r-- | flowgraph/graph.h | 2 | ||||
| -rw-r--r-- | flowgraph/node.cpp | 34 | ||||
| -rw-r--r-- | flowgraph/node.h | 18 | ||||
| -rw-r--r-- | flowgraph/scope.cpp | 24 | ||||
| -rw-r--r-- | flowgraph/scope.h | 7 | ||||
| -rw-r--r-- | flowgraph/storage.cpp | 16 | ||||
| -rw-r--r-- | flowgraph/storage.h | 13 | 
10 files changed, 92 insertions, 57 deletions
| diff --git a/flowgraph/data.cpp b/flowgraph/data.cpp index 9dd6ef8..8568e0c 100644 --- a/flowgraph/data.cpp +++ b/flowgraph/data.cpp @@ -1 +1,21 @@  #include "data.h" + +FlowGraph::Data::Data(FlowGraph::DataType type, std::shared_ptr<FlowGraph::Storage> storage): + m_type(type), m_storage(storage) +{ +} + +FlowGraph::DataType FlowGraph::Data::type() const +{ + return m_type; +} + +std::shared_ptr<FlowGraph::Storage> FlowGraph::Data::storage() const +{ + return m_storage; +} + +bool FlowGraph::Data::operator==(const FlowGraph::Data& other) const +{ + return m_type == other.m_type && m_storage == other.m_storage; +} diff --git a/flowgraph/data.h b/flowgraph/data.h index d1c2588..e2def93 100644 --- a/flowgraph/data.h +++ b/flowgraph/data.h @@ -27,9 +27,10 @@ namespace FlowGraph {   class Data   {   public: -  Data(DataType type, std::shared_ptr<Storage> storage): m_type(type), m_storage(storage) {} -  DataType type() const { return m_type; } -  std::shared_ptr<Storage> storage() { return m_storage; } +  Data(DataType type, std::shared_ptr<Storage> storage); +  DataType type() const; +  std::shared_ptr<Storage> storage() const; +  bool operator==(const Data& other) const;   private:    const DataType m_type;    std::shared_ptr<Storage> m_storage; diff --git a/flowgraph/graph.cpp b/flowgraph/graph.cpp index 6398c68..229ded8 100644 --- a/flowgraph/graph.cpp +++ b/flowgraph/graph.cpp @@ -25,7 +25,7 @@ FlowGraph::Graph::~Graph()  }  // Assume first node of graph to be CreateScopeOp -FlowGraph::LocalScope& FlowGraph::Graph::scope() const +std::shared_ptr<FlowGraph::LocalScope> FlowGraph::Graph::scope() const  {   if (this->empty())    throw std::runtime_error("ICE: FlowGraph expected to be non-empty!"); @@ -42,12 +42,14 @@ FlowGraph::LocalScope& FlowGraph::Graph::scope() const  void FlowGraph::Graph::append(const FlowGraph::Graph& other)  { + // move graph nodes   this->insert(this->end() - 1, other.begin() + 1, other.end() - 1); - this->scope().append(other.scope()); + // move scope nodes to new scope + this->scope()->append(*other.scope());  } -void FlowGraph::Graph::append(std::shared_ptr<Node> node) +void FlowGraph::Graph::append(std::shared_ptr<FlowGraph::Node> node)  {   this->insert(this->end() - 1, node);  } diff --git a/flowgraph/graph.h b/flowgraph/graph.h index 15c6aef..c0ab847 100644 --- a/flowgraph/graph.h +++ b/flowgraph/graph.h @@ -20,7 +20,7 @@ namespace FlowGraph {    Graph& operator= (const Graph&) = default;    // returns the outermost scope inside this graph -  LocalScope& scope() const; +  std::shared_ptr<LocalScope> scope() const;    // append other graph by joining the respective outermost scopes    void append(const Graph& other); diff --git a/flowgraph/node.cpp b/flowgraph/node.cpp index 2d757f9..8e8b5eb 100644 --- a/flowgraph/node.cpp +++ b/flowgraph/node.cpp @@ -1,6 +1,7 @@  #include "node.h"  #include "data.h" +#include "minicc.h"  #include <boost/endian/conversion.hpp> @@ -19,33 +20,40 @@ FlowGraph::Data& Node::destination()  // 4 byte for now  Data FlowGraph::MakeConstantInt(int i)  { - std::vector<uint8_t> value(size_t(4), uint8_t(0)); - *(reinterpret_cast<int32_t*>(value.data())) = boost::endian::native_to_little(static_cast<int32_t>(i)); - return Data{DataType::Int, std::make_shared<Constant>(value)}; + return Data{DataType::Int, std::make_shared<Constant>(to_little_endian(int32_t(i)))};  } -Data FlowGraph::MakeLocalPointer(FlowGraph::LocalScope& scope, const std::string& name) +Data FlowGraph::MakeLocalPointer(std::shared_ptr<FlowGraph::LocalScope> scope, const std::string& name)  { - Data data{DataType::Pointer, std::make_shared<LocalStorage>(scope, name)}; - scope.push_back(std::make_shared<Data>(data)); + Data data{DataType::Pointer, std::make_shared<LocalStorage>(name)}; + scope->push_back(std::make_shared<Data>(data));   return data;  } -Data FlowGraph::MakeLocalSize(FlowGraph::LocalScope& scope, const std::string& name) +Data FlowGraph::MakeLocalSize(std::shared_ptr<FlowGraph::LocalScope> scope, const std::string& name)  { - Data data{DataType::Size, std::make_shared<LocalStorage>(scope, name)}; - scope.push_back(std::make_shared<Data>(data)); + Data data{DataType::Size, std::make_shared<LocalStorage>(name)}; + scope->push_back(std::make_shared<Data>(data));   return data;  } -Data FlowGraph::MakeTemporaryInt(FlowGraph::LocalScope& scope) +Data FlowGraph::MakeTemporaryInt(std::shared_ptr<FlowGraph::LocalScope> scope)  { - Data data{DataType::Int, std::make_shared<TemporaryStorage>(scope)}; - scope.push_back(std::make_shared<Data>(data)); + Data data{DataType::Int, std::make_shared<TemporaryStorage>()}; + scope->push_back(std::make_shared<Data>(data));   return data;  } -LocalScope& CreateScopeOp::scope() +FlowGraph::CreateScopeOp::CreateScopeOp(): m_scope(std::make_shared<LocalScope>()) +{ +} + +std::shared_ptr<LocalScope> FlowGraph::CreateScopeOp::scope()  {   return m_scope;  } + +FlowGraph::DestroyScopeOp::DestroyScopeOp(std::shared_ptr<LocalScope> scope): m_scope(std::make_shared<LocalScope>()) +{ +} + diff --git a/flowgraph/node.h b/flowgraph/node.h index 5ea194d..6a3ef14 100644 --- a/flowgraph/node.h +++ b/flowgraph/node.h @@ -5,6 +5,8 @@  #include "data.h"  #include "storage.h" +#include <memory> +  namespace FlowGraph {   // Node in Graph: Building block of the graph @@ -46,9 +48,9 @@ namespace FlowGraph {   };   Data MakeConstantInt(int i); - Data MakeLocalPointer(FlowGraph::LocalScope& scope, const std::string& name); - Data MakeLocalSize(FlowGraph::LocalScope& scope, const std::string& name); - Data MakeTemporaryInt(LocalScope& scope); + Data MakeLocalPointer(std::shared_ptr<FlowGraph::LocalScope> scope, const std::string& name); + Data MakeLocalSize(std::shared_ptr<FlowGraph::LocalScope> scope, const std::string& name); + Data MakeTemporaryInt(std::shared_ptr<LocalScope> scope);   class MemCopy: public Node   { @@ -176,17 +178,19 @@ namespace FlowGraph {   class CreateScopeOp: public Node   {   public: -  CreateScopeOp() {} -  LocalScope& scope(); +  CreateScopeOp(); +  std::shared_ptr<LocalScope> scope();   private: -  LocalScope m_scope; +  std::shared_ptr<LocalScope> m_scope;   };   // Close current scope, closing stack frame   class DestroyScopeOp: public Node   {   public: -  DestroyScopeOp(LocalScope& scope) {} +  DestroyScopeOp(std::shared_ptr<LocalScope> scope); + private: +  std::shared_ptr<LocalScope> m_scope;   };  } // namespace FlowGraph diff --git a/flowgraph/scope.cpp b/flowgraph/scope.cpp index 54a3cca..dd6c62c 100644 --- a/flowgraph/scope.cpp +++ b/flowgraph/scope.cpp @@ -2,6 +2,14 @@  #include "storage.h" +FlowGraph::LocalScope::LocalScope() +{ +} + +FlowGraph::LocalScope::~LocalScope() +{ +} +  void FlowGraph::LocalScope::push_back(std::shared_ptr<Data> data)  {   m_variables.push_back(data); @@ -9,18 +17,22 @@ void FlowGraph::LocalScope::push_back(std::shared_ptr<Data> data)  void FlowGraph::LocalScope::append(const FlowGraph::LocalScope& other)  { + // actually move variables to new scope   m_variables.insert(m_variables.end(), other.m_variables.begin(), other.m_variables.end());  } -index_t FlowGraph::LocalScope::indexOfStorage(const Storage& storage) const +index_t FlowGraph::LocalScope::indexOfData(const FlowGraph::Data& data) 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 (&i_storage == &storage) // compare addresses +  if (*m_variables[i] == data)     return i;   } - throw std::runtime_error("ICE: Storage not found"); + throw std::runtime_error("ICE: Data not found");  } + +size_t FlowGraph::LocalScope::size() const +{ + return m_variables.size(); +} + diff --git a/flowgraph/scope.h b/flowgraph/scope.h index 65898cf..3fc0fcc 100644 --- a/flowgraph/scope.h +++ b/flowgraph/scope.h @@ -16,11 +16,14 @@ namespace FlowGraph {   class LocalScope   {   public: -  LocalScope() = default; +  LocalScope(); +  ~LocalScope();    void push_back(std::shared_ptr<Data> data);    void append(const LocalScope& other); -  index_t indexOfStorage(const Storage& storage) const; +  index_t indexOfData(const FlowGraph::Data& data) const; + +  size_t size() const;   private:    std::vector<std::shared_ptr<Data>> m_variables; diff --git a/flowgraph/storage.cpp b/flowgraph/storage.cpp index e9577d6..fb82bc2 100644 --- a/flowgraph/storage.cpp +++ b/flowgraph/storage.cpp @@ -2,22 +2,12 @@  using namespace std::string_literals; -FlowGraph::TemporaryStorage::TemporaryStorage(LocalScope& scope): - m_scope(scope) +FlowGraph::LocalStorage::LocalStorage(const std::string& name): + m_name(name)  {  } -std::string FlowGraph::TemporaryStorage::name() const +FlowGraph::TemporaryStorage::TemporaryStorage()  { - 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 27c201e..7b5c53b 100644 --- a/flowgraph/storage.h +++ b/flowgraph/storage.h @@ -5,6 +5,7 @@  #include "scope.h"  #include <cstdint> +#include <memory>  #include <string>  #include <vector> @@ -23,7 +24,7 @@ namespace FlowGraph {   class Constant: public Storage   {   public: -  Constant(std::vector<uint8_t>& value): m_value(value) {} // little endian data +  Constant(const std::vector<uint8_t>& value): m_value(value) {} // little endian data    const std::vector<uint8_t>& value() const { return m_value; }   private:    std::vector<uint8_t> m_value; @@ -42,12 +43,10 @@ namespace FlowGraph {   class LocalStorage : public Storage   {   public: -  LocalStorage(LocalScope& scope, const std::string& name): m_name(name), m_scope(scope) {} +  LocalStorage(const std::string& name);    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,11 +54,7 @@ namespace FlowGraph {   class TemporaryStorage : public Storage   {   public: -  TemporaryStorage(LocalScope& scope); -  std::string name() const; -  index_t indexOfStorage() const; - private: -  LocalScope& m_scope; +  TemporaryStorage();   };   // dereferenced pointer | 
