From dd2a994fbbe946fa751b689e92c85696469e5e5c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 7 Nov 2020 22:26:59 +0100 Subject: Fill mCPPContext.graph with first node! To be converted to asm --- cpp.cpp | 8 ++++++-- cpp.h | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cpp.cpp b/cpp.cpp index afd6c52..2184a39 100644 --- a/cpp.cpp +++ b/cpp.cpp @@ -405,7 +405,8 @@ std::unordered_map> CPP::getNodeEv FlowGraph::Data value0 {std::any_cast(getValue(index, 0))}; FlowGraph::Data value1 {std::any_cast(getValue(index, 1))}; - return std::make_shared(FlowGraph::BinaryOperationType::Add, destination, value0, value1); + std::shared_ptr node {std::make_shared(FlowGraph::BinaryOperationType::Add, destination, value0, value1)}; + return node; } throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } @@ -499,8 +500,11 @@ std::unordered_map> CPP::getNodeEv }, { "expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"assignment-expression", ""}) && !getValue(index, 1).has_value()) + if (childTypesOfNodeMatch(index, {"assignment-expression", ""}) && !getValue(index, 1).has_value()) { + std::shared_ptr node {std::any_cast>(getValue(index, 0))}; + mCPPContext.graph.push_back(node); return getValue(index, 0); + } throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, diff --git a/cpp.h b/cpp.h index 4c9f490..267aa9d 100644 --- a/cpp.h +++ b/cpp.h @@ -1,5 +1,6 @@ #pragma once +#include "flowgraph/graph.h" #include "grammer.h" #include "minicc.h" @@ -13,6 +14,8 @@ struct CPPContext { // global variable definitions // functions declarations // functions definitions + + FlowGraph::Graph graph; }; class CPP { @@ -62,7 +65,8 @@ private: std::unordered_map> getNodeEvalMap(); std::unordered_map> node_eval_map; - CPPContext mContext; + CPPContext mCPPContext; + void getValueOfToken(index_t index); void getValueOfNode(index_t index); void visitRecursive(index_t node_id); -- cgit v1.2.3