From d07c5bc14edbe071ee7b4f47f174780e95e451aa Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 15 Nov 2020 13:55:18 +0100 Subject: Simplify Asm construction --- cpp.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'cpp.cpp') diff --git a/cpp.cpp b/cpp.cpp index 887dbbd..4bb8a01 100644 --- a/cpp.cpp +++ b/cpp.cpp @@ -13,6 +13,8 @@ #include #include +#include + #include #include #include @@ -398,6 +400,11 @@ std::unordered_map> CPP::getNodeEv { "multiplicative-expression", [&](index_t index) -> std::any { if (childTypesOfNodeMatch(index, {"multiplicative-expression", "*", "pm-expression"})) { + if (getValue(index, 0).type() != typeid(FlowGraph::Data)) + throw std::runtime_error("ICE: multiplicative-expression: Bad data type for argument 1: "s + demangle(getValue(index, 0).type())); + if (getValue(index, 2).type() != typeid(FlowGraph::Data)) + throw std::runtime_error("ICE: multiplicative-expression: Bad data type for argument 3: "s + demangle(getValue(index, 2).type())); + FlowGraph::LocalScope scope; // TODO: move to context! FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)}; FlowGraph::Data value0 {std::any_cast(getValue(index, 0))}; @@ -414,6 +421,11 @@ std::unordered_map> CPP::getNodeEv { "additive-expression", [&](index_t index) -> std::any { if (childTypesOfNodeMatch(index, {"additive-expression", "+", "multiplicative-expression"})) { + if (getValue(index, 0).type() != typeid(FlowGraph::Data)) + throw std::runtime_error("ICE: additive-expression: Bad data type for argument 1: "s + demangle(getValue(index, 0).type())); + if (getValue(index, 2).type() != typeid(FlowGraph::Data)) + throw std::runtime_error("ICE: additive-expression: Bad data type for argument 3: "s + demangle(getValue(index, 2).type())); + FlowGraph::LocalScope scope; // TODO: move to context! FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)}; FlowGraph::Data value0 {std::any_cast(getValue(index, 0))}; @@ -507,19 +519,27 @@ std::unordered_map> CPP::getNodeEv { "expression", [&](index_t index) -> std::any { if (childTypesOfNodeMatch(index, {"assignment-expression"})) { + std::shared_ptr scope_node {std::make_shared()}; + mCPPContext.graph.push_back(scope_node); + + FlowGraph::LocalScope& scope{scope_node->scope()}; + if (getValue(index, 0).type() == typeid(FlowGraph::Data)) { // got Data -> make trivial Node out of it and return it - FlowGraph::LocalScope scope; // TODO: move to context! + FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)}; FlowGraph::Data source {std::any_cast(getValue(index, 0))}; std::shared_ptr node {std::make_shared(FlowGraph::UnaryOperationType::Store, destination, source)}; mCPPContext.graph.push_back(node); return node; - } else { + } else if (getValue(index, 0).type() == typeid(std::shared_ptr)) { std::shared_ptr node {std::any_cast>(getValue(index, 0))}; mCPPContext.graph.push_back(node); return getValue(index, 0); + } else { + throw std::runtime_error("ICE: expression: Unsupported argument type: "s + demangle(getValue(index, 0).type())); } + mCPPContext.graph.push_back(std::make_shared(scope)); } throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } -- cgit v1.2.3