From 9e7f4c9d43b310c280cd6432cd4150411f4b914e Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 14 Nov 2020 22:06:10 +0100 Subject: Added system tests --- cpp.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'cpp.cpp') diff --git a/cpp.cpp b/cpp.cpp index 0b078ee..887dbbd 100644 --- a/cpp.cpp +++ b/cpp.cpp @@ -315,6 +315,7 @@ bool CPP::childTypesOfChildMatch(index_t index, index_t child_index, const std:: return childTypesOfNodeMatch(m_nodes[index].child_ids[child_index], pattern); } +// Get value for specified node, at bnf rule index child_index std::any CPP::getValue(index_t node_id, index_t child_index) { size_t num_values_on_top {m_nodes[node_id].child_ids.size()}; @@ -506,9 +507,19 @@ std::unordered_map> CPP::getNodeEv { "expression", [&](index_t index) -> std::any { if (childTypesOfNodeMatch(index, {"assignment-expression"})) { - std::shared_ptr node {std::any_cast>(getValue(index, 0))}; - mCPPContext.graph.push_back(node); - return getValue(index, 0); + 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 { + 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 } @@ -592,9 +603,10 @@ void CPP::link() mCode = std::vector{ 0x48, 0xc7, 0xc0, 0x3c, 0x00, 0x00, 0x00, // mov $0x3c,%rax # syscall 60 0x48, 0x31, 0xff, // xor %rdi,%rdi # exit code 0 - } + mSegment.getCode() + std::vector{ // add to edi + } + mSegment.getCode() + std::vector{ // # leave exit code in edi 0x0f, 0x05, // syscall - }; + } + ; } // phases of translation, according to standard -- cgit v1.2.3