summaryrefslogtreecommitdiffhomepage
path: root/flowgraph/storage.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-10-24 16:32:18 +0200
committerRoland Reichwein <mail@reichwein.it>2020-10-24 16:32:18 +0200
commit1011655d2ef76a0c0aa29dbbff091dab139198e3 (patch)
tree63763828f259846f56285691805c187583ecb6bb /flowgraph/storage.h
parent1349c00b782eca3ea841bfa388301cb6fc908cc7 (diff)
Add FlowGraph
Diffstat (limited to 'flowgraph/storage.h')
-rw-r--r--flowgraph/storage.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/flowgraph/storage.h b/flowgraph/storage.h
new file mode 100644
index 0000000..c2fa7c5
--- /dev/null
+++ b/flowgraph/storage.h
@@ -0,0 +1,85 @@
+#pragma once
+
+#include "data.h"
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace FlowGraph {
+
+ // Parameter to Data class, defining where the data is stored
+ // Explicitely not including size
+ // But including label/data/pointer
+ // -> includes identity of certain data point
+ class Storage
+ {
+ public:
+ virtual ~Storage() {} // force class to be polymorphic
+ };
+
+ class Constant: public Storage
+ {
+ public:
+ Constant(std::vector<uint8_t> value) {} // little endian data
+ const std::vector<uint8_t>& value() const { return m_value; }
+ private:
+ std::vector<uint8_t> m_value;
+ };
+
+ class GlobalStorage : public Storage
+ {
+ public:
+ GlobalStorage(const std::string& name): m_name(name) {}
+ const std::string& name() const { return m_name; }
+ private:
+ std::string m_name;
+ };
+
+ class LocalStorage : public Storage
+ {
+ public:
+ LocalStorage(const std::string& name): m_name(name) {}
+ const std::string& name() const { return m_name; }
+ private:
+ std::string m_name;
+ };
+
+ // Provide a context for local temporaries name generation
+ class LocalScope
+ {
+ public:
+ size_t getNewIndex() { return m_index++; }
+ private:
+ size_t m_index{ 0 };
+ };
+
+ // intermediate results, anonymous values
+ // use generated name
+ class TemporaryStorage : public Storage
+ {
+ public:
+ TemporaryStorage(LocalScope& scope);
+ const std::string& name() const { return m_name; }
+ private:
+ std::string m_name;
+ };
+
+ // 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;
+ };
+
+}