From 1011655d2ef76a0c0aa29dbbff091dab139198e3 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 24 Oct 2020 16:32:18 +0200 Subject: Add FlowGraph --- flowgraph/node.h | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 flowgraph/node.h (limited to 'flowgraph/node.h') diff --git a/flowgraph/node.h b/flowgraph/node.h new file mode 100644 index 0000000..37af95a --- /dev/null +++ b/flowgraph/node.h @@ -0,0 +1,150 @@ +#pragma once + +#include "data.h" +#include "storage.h" + +namespace FlowGraph { + + // Node in Graph: Building block of the graph + // Abstracts actions of program flow, yet machine independent, + // to be converted later into machine code + // Basic elements: + // - Subroutine calls + // - Arithmetic/logical operations + // Arguments (Data instances) will be provided explicitly from outside + class Node + { + public: + virtual ~Node() {}; // force class to be polymorphic + }; + + // Memory on Heap: new and delete + class AllocateDynamic: public Node + { + public: + AllocateDynamic(Data& location, Data& size): m_location(location), m_size(size) {} + private: + Data m_location; // in/out: Pointer + Data m_size; // in: Size + }; + + class DeallocateDynamic: public Node + { + public: + DeallocateDynamic(Data& location) : m_location(location) {} // in + private: + Data m_location; // in: Pointer + }; + + Data MakeLocalPointer(const std::string& name); + Data MakeLocalSize(const std::string& name); + + class MemCopy: public Node + { + public: + MemCopy(Data& destination, Data& source, Data& size): m_destination(destination), m_source(source), m_size(size) {} + private: + Data m_destination; // Pointer + Data m_source; // Pointer + Data m_size; // in bytes + }; + + class Move: public Node + { + public: + Move(Data& destination, Data& source): m_destination(destination), m_source(source) {} + private: + Data m_destination; + Data m_source; + }; + + enum class JumpVariant + { + Unconditional, + GT, + LT, + GE, + LE, + EQ, + NE + }; + + // Unconditional Jump, conditional Jump + class Jump: public Node + { + public: + Jump(JumpVariant variant, Data& source0, Data& source1, std::shared_ptr destination): + m_variant(variant), + m_source0(source0), + m_source1(source1), + m_destination(destination) + {} + private: + JumpVariant m_variant; + Data m_source0; + Data m_source1; + std::shared_ptr m_destination; // successor on branch + }; + + // Call Subroutine + class Call: public Node + { + public: + Call(std::shared_ptr destination, std::vector arguments): m_destination(destination), m_arguments(arguments) {} + private: + std::shared_ptr m_destination; + std::vector m_arguments; + }; + + // Return from Subroutine + class Return: public Node + { + public: + Return(std::vector returnValues): m_returnValues(returnValues) {} + private: + std::vector m_returnValues; + }; + + enum class UnaryOperationType { + Increment, + Decrement, + Negate + }; + + class UnaryOperation: public Node + { + public: + UnaryOperation(Data& destination, Data& source): m_destination(destination), m_source(source) {} + private: + Data m_destination; + Data m_source; + }; + + enum class BinaryOperationType { + Add, + Subtract, + Multiply, + Divide, + Modulo, + ShiftRight, + ShiftLeft, + BitwiseAnd, + BitwiseOr, + BitwiseXor, + BitwiseNot, + LogicalAnd, + LogicalOr, + LogicalNot + }; + + class BinaryOperation: public Node + { + public: + BinaryOperation(Data& destination, Data& source0, Data& source1): m_destination(destination), m_source0(source0), m_source1(source1) {} + private: + Data m_destination; + Data m_source0; + Data m_source1; + }; + +} -- cgit v1.2.3