summaryrefslogtreecommitdiffhomepage
path: root/flowgraph
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-11-06 18:20:34 +0100
committerRoland Reichwein <mail@reichwein.it>2020-11-06 18:20:34 +0100
commit71c7fd62f8b5257b82cf32b0f747fcf313fcc617 (patch)
tree6f014b14d08080459a04a965912c62605d9015ca /flowgraph
parent62aafc5c9273cb0b7a91bf2e4dee1ac2d3658bb3 (diff)
Prepare Token/Node handling
Diffstat (limited to 'flowgraph')
-rw-r--r--flowgraph/data.h2
-rw-r--r--flowgraph/node.cpp21
-rw-r--r--flowgraph/node.h5
-rw-r--r--flowgraph/storage.h5
4 files changed, 28 insertions, 5 deletions
diff --git a/flowgraph/data.h b/flowgraph/data.h
index 353567c..1ed4964 100644
--- a/flowgraph/data.h
+++ b/flowgraph/data.h
@@ -1,3 +1,5 @@
+// Basic Data types, abstract (not yet machine specific)
+
#pragma once
#include <cstdint>
diff --git a/flowgraph/node.cpp b/flowgraph/node.cpp
index fc55ef6..f81a7e1 100644
--- a/flowgraph/node.cpp
+++ b/flowgraph/node.cpp
@@ -2,8 +2,25 @@
#include "data.h"
+#include <boost/endian/conversion.hpp>
+
using namespace FlowGraph;
-Data FlowGraph::MakeLocalPointer(const std::string& name) { return Data(DataType::Pointer, std::make_shared<LocalStorage>(name)); }
-Data FlowGraph::MakeLocalSize(const std::string& name) { return Data(DataType::Size, std::make_shared<LocalStorage>(name)); }
+// 4 byte for now
+Data FlowGraph::MakeConstantInt(int i)
+{
+ std::vector<uint8_t> value(size_t(4));
+ *(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));
+}
+
+Data FlowGraph::MakeLocalPointer(const std::string& name)
+{
+ return Data(DataType::Pointer, std::make_shared<LocalStorage>(name));
+}
+
+Data FlowGraph::MakeLocalSize(const std::string& name)
+{
+ return Data(DataType::Size, std::make_shared<LocalStorage>(name));
+}
diff --git a/flowgraph/node.h b/flowgraph/node.h
index 37af95a..40846e2 100644
--- a/flowgraph/node.h
+++ b/flowgraph/node.h
@@ -1,3 +1,5 @@
+// Nodes in flow graph: Abstract Operations
+
#pragma once
#include "data.h"
@@ -36,6 +38,7 @@ namespace FlowGraph {
Data m_location; // in: Pointer
};
+ Data MakeConstantInt(int i);
Data MakeLocalPointer(const std::string& name);
Data MakeLocalSize(const std::string& name);
@@ -147,4 +150,4 @@ namespace FlowGraph {
Data m_source1;
};
-}
+} // namespace FlowGraph
diff --git a/flowgraph/storage.h b/flowgraph/storage.h
index c2fa7c5..efd7d52 100644
--- a/flowgraph/storage.h
+++ b/flowgraph/storage.h
@@ -1,3 +1,4 @@
+// Different kinds of abstract storage locations: Constants, Global and Local Storage, Temporaries, ...
#pragma once
#include "data.h"
@@ -15,13 +16,13 @@ namespace FlowGraph {
class Storage
{
public:
- virtual ~Storage() {} // force class to be polymorphic
+ virtual ~Storage() {} // force class to be polymorphic, for smart pointers
};
class Constant: public Storage
{
public:
- Constant(std::vector<uint8_t> value) {} // little endian data
+ Constant(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;