summaryrefslogtreecommitdiffhomepage
path: root/flowgraph
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-11-16 12:48:44 +0100
committerRoland Reichwein <mail@reichwein.it>2020-11-16 12:48:44 +0100
commitc9cb051fae190acfc36813e4a23759fb9b9c3df3 (patch)
treefcd8c93cd5dc2a3272eac253b0291611e16ea13f /flowgraph
parent300219dc8519720a36525c7b40c6a327580fe0bd (diff)
Implement hierarchical evaluation (WIP)
Diffstat (limited to 'flowgraph')
-rw-r--r--flowgraph/node.cpp16
-rw-r--r--flowgraph/scope.cpp10
-rw-r--r--flowgraph/scope.h4
-rw-r--r--flowgraph/storage.cpp10
-rw-r--r--flowgraph/storage.h5
5 files changed, 32 insertions, 13 deletions
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 <boost/endian/conversion.hpp>
+#include <memory>
+
using namespace FlowGraph;
FlowGraph::Data& Node::destination()
@@ -19,22 +21,28 @@ 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>(value)};
}
Data FlowGraph::MakeLocalPointer(FlowGraph::LocalScope& scope, const std::string& name)
{
- return Data(DataType::Pointer, std::make_shared<LocalStorage>(scope, name));
+ Data data{DataType::Pointer, std::make_shared<LocalStorage>(scope, name)};
+ scope.push_back(std::make_shared<Data>(data));
+ return data;
}
Data FlowGraph::MakeLocalSize(FlowGraph::LocalScope& scope, const std::string& name)
{
- return Data(DataType::Size, std::make_shared<LocalStorage>(scope, name));
+ Data data{DataType::Size, std::make_shared<LocalStorage>(scope, name)};
+ scope.push_back(std::make_shared<Data>(data));
+ return data;
}
Data FlowGraph::MakeTemporaryInt(FlowGraph::LocalScope& scope)
{
- return Data(DataType::Int, std::make_shared<TemporaryStorage>(scope));
+ Data data{DataType::Int, std::make_shared<TemporaryStorage>(scope)};
+ scope.push_back(std::make_shared<Data>(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<FlowGraph::TemporaryStorage&>(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> data);
void append(const LocalScope& other);
- index_t indexOfStorage(const TemporaryStorage& storage) const;
+ index_t indexOfStorage(const Storage& storage) const;
private:
std::vector<std::shared_ptr<Data>> 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;
};