diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-11-22 14:09:58 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-11-22 14:09:58 +0100 |
commit | fd8517e10937a5b72ed839ce900306f281d74b7d (patch) | |
tree | 598348411052ca0ed60df873b41d2d5a5621079e /asm | |
parent | 1fae63de23320a1663b7c591e247ad81852ab6dc (diff) |
Fix frame pointer - pop was too early
Diffstat (limited to 'asm')
-rw-r--r-- | asm/intel64/encode.cpp | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/asm/intel64/encode.cpp b/asm/intel64/encode.cpp index a51854a..1cc1a6d 100644 --- a/asm/intel64/encode.cpp +++ b/asm/intel64/encode.cpp @@ -214,22 +214,16 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment) segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register64("rbp"), Asm::Args::Register64("rsp")}})); } else if (typeid(node_deref) == typeid(FlowGraph::DestroyScopeOp)) { - //FlowGraph::DestroyScopeOp& op {dynamic_cast<FlowGraph::DestroyScopeOp&>(*node)}; // TODO: Destroy stack frame - segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}})); segment.push_back(makeLoadValue(graph.lastOp()->destination(), graph)); // TODO: Just get last operation result to eax for now 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")}})); -#if 0 - segment.push_back(makeOp("xor", Asm::Args{{Asm::Args::Register64("rbp"), Asm::Args::Register64("rbp")}})); - segment.push_back(makeOp("dec", Asm::Args{{Asm::Args::Register64("rbp")}})); - segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Mem32Ptr64("rbp", -4), Asm::Args::Immediate32(3)}})); - segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Mem32Ptr64("rbp", -4)}})); - //segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register32("edi"), Asm::Args::Immediate32(3)}})); -#endif - segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register64("rax"), Asm::Args::Immediate32(60)}})); // syscall 60: exit() + + //FlowGraph::DestroyScopeOp& op {dynamic_cast<FlowGraph::DestroyScopeOp&>(*node)}; // TODO: Destroy stack frame + segment.push_back(makeOp("pop", Asm::Args{{Asm::Args::Register64("rbp")}})); + segment.push_back(makeOp("syscall")); // rax: #syscall, rdi: exit code value } else if (typeid(node_deref) == typeid(FlowGraph::DataNode)) { // ignore: Immediate data is used in subsequent nodes |