diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-11-15 18:39:01 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-11-15 18:39:01 +0100 |
commit | a3b4cd4fdd4340c952eaa00bca9bebf817b901ae (patch) | |
tree | 055d3ae4b9d1e37682c2e49b31a6531f189eebf5 /asm/intel64/encode.cpp | |
parent | d07c5bc14edbe071ee7b4f47f174780e95e451aa (diff) |
Fixed unit tests, prepared hierarchical evaluation via stack (WIP)
Diffstat (limited to 'asm/intel64/encode.cpp')
-rw-r--r-- | asm/intel64/encode.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/asm/intel64/encode.cpp b/asm/intel64/encode.cpp index 123dff2..03a7897 100644 --- a/asm/intel64/encode.cpp +++ b/asm/intel64/encode.cpp @@ -37,7 +37,7 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment) std::runtime_error("Bad value for operand 1: Constant expected"); } - if (op.type() == FlowGraph::UnaryOperationType::Store) { + if (op.type() == FlowGraph::UnaryOperationType::Negate) { Asm::Args args1{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate1)}}; segment.push_back(makeOp("mov", args1)); } else @@ -84,16 +84,14 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment) std::runtime_error("Bad value for operand 2: Constant expected"); } - Asm::Args args1{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate1)}}; - segment.push_back(makeOp("mov", args1)); + segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate1)}})); - Asm::Args args2{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate2)}}; - - if (op.type() == FlowGraph::BinaryOperationType::Add) - segment.push_back(makeOp("add", args2)); - else if (op.type() == FlowGraph::BinaryOperationType::Multiply) - segment.push_back(makeOp("mul", args2)); - else + if (op.type() == FlowGraph::BinaryOperationType::Add) { + segment.push_back(makeOp("add", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate2)}})); + } else if (op.type() == FlowGraph::BinaryOperationType::Multiply) { + segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("ebx"), Asm::Args::Immediate32(immediate2)}})); + segment.push_back(makeOp("mul", Asm::Args{{Asm::Args::Register32("ebx")}})); + } else throw std::runtime_error("ICE: Asm: Unsupported binary operation type: "s + std::to_string(static_cast<int>(op.type()))); } else if (typeid(node_deref) == typeid(FlowGraph::CreateScopeOp)) { @@ -104,6 +102,12 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment) } else if (typeid(node_deref) == typeid(FlowGraph::DestroyScopeOp)) { //FlowGraph::DestroyScopeOp& op {dynamic_cast<FlowGraph::DestroyScopeOp&>(*node)}; segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}})); + + // Move + segment.push_back(makeOp("xor", Asm::Args{{Asm::Args::Register64("rdi"), Asm::Args::Register64("rdi")}})); + segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Register32("eax")}})); + } else if (typeid(node_deref) == typeid(FlowGraph::DataNode)) { + // ignore: Immediate data is used in subsequent nodes } else { throw std::runtime_error("ICE: Encoding: Unsupported node: "s + demangle(typeid(node_deref))); } |