diff options
Diffstat (limited to 'asm/intel64/encode.cpp')
-rw-r--r-- | asm/intel64/encode.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/asm/intel64/encode.cpp b/asm/intel64/encode.cpp index 62101f3..a51854a 100644 --- a/asm/intel64/encode.cpp +++ b/asm/intel64/encode.cpp @@ -3,10 +3,9 @@ #include "asm/assembler.h" #include "asm/parse.h" +#include "byteorder.h" #include "minicc.h" -#include <boost/endian/conversion.hpp> - #include <exception> namespace { @@ -26,7 +25,7 @@ std::shared_ptr<Op> makeLoadValue(const FlowGraph::Data& data, const FlowGraph:: if (value.value().size() < sizeof(uint32_t)) throw std::runtime_error("ICE: Int data from operand needs at least 4 bytes, got "s + std::to_string(value.value().size())); - uint32_t immediate = from_little_endian(value.value()); + uint32_t immediate = endian::from_little32(value.value()); return makeOp("mov", Asm::Args{{Asm::Args::Register32("eax"), Asm::Args::Immediate32(immediate)}}); } else if (typeid(data_storage) == typeid(FlowGraph::TemporaryStorage)) { @@ -72,7 +71,7 @@ std::shared_ptr<Op> makeAddValue(const FlowGraph::Data& data, const FlowGraph::G if (value.value().size() < sizeof(uint32_t)) throw std::runtime_error("ICE: Int data from operand needs at least 4 bytes, got "s + std::to_string(value.value().size())); - uint32_t immediate = from_little_endian(value.value()); + uint32_t immediate = endian::from_little32(value.value()); return makeOp("add", Asm::Args{{Asm::Args::Register32("eax"), Asm::Args::Immediate32(immediate)}}); } else if (typeid(data_storage) == typeid(FlowGraph::TemporaryStorage)) { @@ -99,7 +98,7 @@ std::vector<std::shared_ptr<Chunk>> makeMulValue(const FlowGraph::Data& data, co if (value.value().size() < sizeof(uint32_t)) throw std::runtime_error("ICE: Int data from operand needs at least 4 bytes, got "s + std::to_string(value.value().size())); - uint32_t immediate = from_little_endian(value.value()); + uint32_t immediate = endian::from_little32(value.value()); return {{ makeOp("mov", Asm::Args{{Asm::Args::Register32("ebx"), Asm::Args::Immediate32(immediate)}}), @@ -129,7 +128,7 @@ std::vector<std::shared_ptr<Chunk>> makeDivValue(const FlowGraph::Data& data, co if (value.value().size() < sizeof(uint32_t)) throw std::runtime_error("ICE: Int data from operand needs at least 4 bytes, got "s + std::to_string(value.value().size())); - uint32_t immediate = from_little_endian(value.value()); + uint32_t immediate = endian::from_little32(value.value()); return {{ makeOp("mov", Asm::Args{{Asm::Args::Register32("ebx"), Asm::Args::Immediate32(immediate)}}), @@ -211,12 +210,12 @@ void Asm::toMachineCode(const FlowGraph::Graph& graph, Segment& segment) } else if (typeid(node_deref) == typeid(FlowGraph::CreateScopeOp)) { //FlowGraph::CreateScopeOp& op {dynamic_cast<FlowGraph::CreateScopeOp&>(*node)}; // TODO: Create stack frame - //segment.push_back(makeOp("push", Asm::Args{{Asm::Args::Register64("rbp")}})); - //segment.push_back(makeOp("mov", Asm::Args{{Asm::Args::Register64("rbp"), Asm::Args::Register64("rsp")}})); + segment.push_back(makeOp("push", Asm::Args{{Asm::Args::Register64("rbp")}})); + 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(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")}})); |