#include "graph.h" #include "minicc.h" #include "node.h" #include using namespace std::string_literals; FlowGraph::Graph::Graph() { } FlowGraph::Graph::Graph(const std::deque>& nodes): std::deque>(nodes) { auto createLocalScope {std::make_shared()}; this->push_front(createLocalScope); auto destroyLocalScope {std::make_shared(createLocalScope->scope())}; this->push_back(destroyLocalScope); } FlowGraph::Graph::~Graph() { } // Assume first node of graph to be CreateScopeOp FlowGraph::LocalScope& FlowGraph::Graph::scope() const { if (this->empty()) throw std::runtime_error("ICE: FlowGraph expected to be non-empty!"); auto& front_deref {*front()}; if (typeid(front_deref) != typeid(FlowGraph::CreateScopeOp)) throw std::runtime_error("ICE: Bad type of first graph element: "s + demangle(typeid(front_deref))); FlowGraph::CreateScopeOp& createScope {dynamic_cast(front_deref)}; return createScope.scope(); } void FlowGraph::Graph::append(const FlowGraph::Graph& other) { this->insert(this->end() - 1, other.begin() + 1, other.end() - 1); this->scope().append(other.scope()); } void FlowGraph::Graph::append(std::shared_ptr node) { this->insert(this->end() - 1, node); } std::shared_ptr FlowGraph::Graph::lastOp() const { if (size() >= 3) return *(end() - 2); throw std::runtime_error("ICE: No last operation found in graph"); }