diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-11-15 13:55:18 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-11-15 13:55:18 +0100 |
commit | d07c5bc14edbe071ee7b4f47f174780e95e451aa (patch) | |
tree | 889ed88ea6907119b75b7b76f616a604c9857e3d /cpp.cpp | |
parent | 9e7f4c9d43b310c280cd6432cd4150411f4b914e (diff) |
Simplify Asm construction
Diffstat (limited to 'cpp.cpp')
-rw-r--r-- | cpp.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -13,6 +13,8 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> +#include <boost/core/demangle.hpp> + #include <functional> #include <optional> #include <unordered_set> @@ -398,6 +400,11 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> 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<FlowGraph::Data>(getValue(index, 0))}; @@ -414,6 +421,11 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> 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<FlowGraph::Data>(getValue(index, 0))}; @@ -507,19 +519,27 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv { "expression", [&](index_t index) -> std::any { if (childTypesOfNodeMatch(index, {"assignment-expression"})) { + std::shared_ptr<FlowGraph::CreateScopeOp> scope_node {std::make_shared<FlowGraph::CreateScopeOp>()}; + 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<FlowGraph::Data>(getValue(index, 0))}; std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::UnaryOperation>(FlowGraph::UnaryOperationType::Store, destination, source)}; mCPPContext.graph.push_back(node); return node; - } else { + } else if (getValue(index, 0).type() == typeid(std::shared_ptr<FlowGraph::Node>)) { std::shared_ptr<FlowGraph::Node> node {std::any_cast<std::shared_ptr<FlowGraph::Node>>(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<FlowGraph::DestroyScopeOp>(scope)); } throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } |