summaryrefslogtreecommitdiffhomepage
path: root/asm/intel64/encode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'asm/intel64/encode.cpp')
-rw-r--r--asm/intel64/encode.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/asm/intel64/encode.cpp b/asm/intel64/encode.cpp
index 03a7897..681e407 100644
--- a/asm/intel64/encode.cpp
+++ b/asm/intel64/encode.cpp
@@ -47,7 +47,19 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment)
FlowGraph::BinaryOperation& op {dynamic_cast<FlowGraph::BinaryOperation&>(*node)};
auto operands {op.operands()};
- // TODO: ignore destination (0) for now
+
+#if 0
+ if (op.type() == FlowGraph::BinaryOperationType::Add) {
+ segment.push_back(loadmakeOp("add", Asm::Args{{Asm::Args::Register32("eax"), 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())));
+#endif
+
+
+
if (operands[1].type() != FlowGraph::DataType::Int) {
std::runtime_error("Bad type for operand 1: "s + std::to_string(int(operands[1].type())));
@@ -83,11 +95,11 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment)
} catch (const std::bad_cast& ex) {
std::runtime_error("Bad value for operand 2: Constant expected");
}
-
- segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate1)}}));
+ segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("eax"), Asm::Args::Immediate32(immediate1)}}));
+
if (op.type() == FlowGraph::BinaryOperationType::Add) {
- segment.push_back(makeOp("add", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(immediate2)}}));
+ segment.push_back(makeOp("add", Asm::Args{{Asm::Args::Register32("eax"), 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")}}));
@@ -103,7 +115,7 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment)
//FlowGraph::DestroyScopeOp& op {dynamic_cast<FlowGraph::DestroyScopeOp&>(*node)};
segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}}));
- // Move
+ // Move eax for exit() via rdi
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)) {