diff --git a/CMakeLists.txt b/CMakeLists.txt index 59e82e9..00e2e27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,26 +60,26 @@ add_library(city src/ir/instruction/control/RetInst.cpp src/ir/instruction/control/BranchInst.cpp src/ir/instruction/memory/StoreInst.cpp - src/backend/x86/x86.cpp - src/backend/x86/x86.h - src/backend/IRTranslationInterface.h - src/backend/x86/x86TranslationInterface.cpp - src/backend/x86/x86TranslationInterface.h - src/backend/x86/instruction/x86Instruction.cpp - src/backend/x86/instruction/x86Instruction.h - src/backend/x86/instruction/arithmetic/x86AddRM32Inst.h + src/backend/amd64/Amd64.cpp + src/backend/amd64/Amd64.h + src/backend/IRTranslator.h + src/backend/amd64/Amd64Translator.cpp + src/backend/amd64/Amd64Translator.h + src/backend/amd64/instruction/Amd64Instruction.cpp + src/backend/amd64/instruction/Amd64Instruction.h + src/backend/amd64/instruction/arithmetic/x86AddRM32Inst.h src/ByteBuffer.h - src/backend/x86/instruction/arithmetic/x86AddMI32Inst.h + src/backend/amd64/instruction/arithmetic/x86AddMI32Inst.h src/ir/instruction/InstructionFunctor.h src/backend/NativeInstruction.cpp src/backend/NativeInstruction.h - src/backend/x86/x86Register.cpp - src/backend/x86/x86Register.h - src/backend/x86/x86ModRM.h - src/backend/x86/instruction/memory/Amd64PushO64.h - src/backend/x86/instruction/memory/Amd64MovMR64.h - src/backend/x86/instruction/memory/Amd64PopO64.h - src/backend/x86/instruction/control/Amd64RetZONear.h + src/backend/amd64/Amd64Register.cpp + src/backend/amd64/Amd64Register.h + src/backend/amd64/Amd64ModRM.h + src/backend/amd64/instruction/memory/Amd64PushO64.h + src/backend/amd64/instruction/memory/Amd64MovMR64.h + src/backend/amd64/instruction/memory/Amd64PopO64.h + src/backend/amd64/instruction/control/Amd64RetZONear.h src/runtime/Windows.cpp src/runtime/Windows.h src/Object.cpp diff --git a/src/backend/Backend.cpp b/src/backend/Backend.cpp index 1252671..9fa88eb 100644 --- a/src/backend/Backend.cpp +++ b/src/backend/Backend.cpp @@ -4,11 +4,11 @@ using namespace city; #ifdef __x86_64__ -#include "x86/x86.h" +#include "amd64/Amd64.h" std::unique_ptr Backend::CreateHostNative() { - return std::make_unique(); + return std::make_unique(); } #elifdef __aarch64__ diff --git a/src/backend/IRTranslationInterface.h b/src/backend/IRTranslator.h similarity index 59% rename from src/backend/IRTranslationInterface.h rename to src/backend/IRTranslator.h index d40d3a1..8ac337f 100644 --- a/src/backend/IRTranslationInterface.h +++ b/src/backend/IRTranslator.h @@ -10,11 +10,11 @@ namespace city { }; - struct IRTranslationInterface : InstructionFunctor + struct IRTranslator : InstructionFunctor { - NativeModule &object; + NativeModule &module; - explicit IRTranslationInterface(NativeModule &object) : object(object) {} + explicit IRTranslator(NativeModule &native_module) : module(native_module) {} }; } // namespace city diff --git a/src/backend/amd64/Amd64.cpp b/src/backend/amd64/Amd64.cpp new file mode 100644 index 0000000..52331b2 --- /dev/null +++ b/src/backend/amd64/Amd64.cpp @@ -0,0 +1,47 @@ +#include "Amd64.h" +#include "Amd64Translator.h" +#include "instruction/memory/Amd64MovMR64.h" +#include "instruction/memory/Amd64PopO64.h" +#include "instruction/memory/Amd64PushO64.h" +#include "ir/Block.h" +#include "ir/Function.h" +#include "ir/instruction/IRInstruction.h" + +using namespace city; + +std::array const x86_register_definitions = { + Amd64Register(Amd64RegisterCode::XMM0), + Amd64Register(Amd64RegisterCode::XMM1), + Amd64Register(Amd64RegisterCode::XMM2), + Amd64Register(Amd64RegisterCode::XMM3), + Amd64Register(Amd64RegisterCode::XMM4), + Amd64Register(Amd64RegisterCode::XMM5), + Amd64Register(Amd64RegisterCode::XMM6), + Amd64Register(Amd64RegisterCode::XMM7), +}; + +NativeModule Amd64::BuildModule(IRModule &module) +{ + NativeModule object{}; + + Amd64Translator translator{object}; + for (auto &function : module.functions_) + { + // Function Prolog + auto entry = object.EmplaceInstruction(Amd64RegisterCode::RBP); + entry->SetLabel(function->name_); + + object.EmplaceInstruction(Amd64RegisterCode::RBP, Amd64RegisterCode::RSP); + + // Function Body + for (auto block : function->blocks_) + { + for (auto &instruction : block->instructions_) + { + instruction->Apply(&translator); + } + } + } + + return std::move(object); +} diff --git a/src/backend/x86/x86.h b/src/backend/amd64/Amd64.h similarity index 58% rename from src/backend/x86/x86.h rename to src/backend/amd64/Amd64.h index 13b45ac..f39fc3c 100644 --- a/src/backend/x86/x86.h +++ b/src/backend/amd64/Amd64.h @@ -1,21 +1,14 @@ #ifndef X86_64_H #define X86_64_H -#include -#include #include "backend/Backend.h" -#include "x86Register.h" namespace city { - class x86 : public Backend + class Amd64 : public Backend { - std::array registers_; - public: [[nodiscard]] NativeModule BuildModule(IRModule &module) override; - - x86(); }; } // namespace city diff --git a/src/backend/x86/x86ModRM.h b/src/backend/amd64/Amd64ModRM.h similarity index 93% rename from src/backend/x86/x86ModRM.h rename to src/backend/amd64/Amd64ModRM.h index a8f53ce..b80d61c 100644 --- a/src/backend/x86/x86ModRM.h +++ b/src/backend/amd64/Amd64ModRM.h @@ -5,7 +5,7 @@ namespace city { - enum class x86Mod : std::uint8_t + enum class Amd64Mod : std::uint8_t { Memory = 0x0, MemoryD8 = 0x1, @@ -13,7 +13,7 @@ namespace city Register = 0x3, }; - enum class x86RegisterCode : std::uint8_t + enum class Amd64RegisterCode : std::uint8_t { AL = 0x0, AX = 0x0, diff --git a/src/backend/amd64/Amd64Register.cpp b/src/backend/amd64/Amd64Register.cpp new file mode 100644 index 0000000..da088ad --- /dev/null +++ b/src/backend/amd64/Amd64Register.cpp @@ -0,0 +1,6 @@ + +#include "Amd64Register.h" + +using namespace city; + +Amd64Register::Amd64Register(Amd64RegisterCode code) : code_(code) {} diff --git a/src/backend/x86/x86Register.h b/src/backend/amd64/Amd64Register.h similarity index 54% rename from src/backend/x86/x86Register.h rename to src/backend/amd64/Amd64Register.h index a6e4c57..48b4ab9 100644 --- a/src/backend/x86/x86Register.h +++ b/src/backend/amd64/Amd64Register.h @@ -1,17 +1,17 @@ #ifndef CITY_X86REGISTER_H #define CITY_X86REGISTER_H +#include "Amd64ModRM.h" #include "ir/Container.h" -#include "x86ModRM.h" namespace city { - class x86Register : public Container + class Amd64Register : public Container { - x86RegisterCode code_; + Amd64RegisterCode code_; public: - x86Register(x86RegisterCode code); + Amd64Register(Amd64RegisterCode code); }; } // namespace city diff --git a/src/backend/amd64/Amd64Translator.cpp b/src/backend/amd64/Amd64Translator.cpp new file mode 100644 index 0000000..cd7eaf9 --- /dev/null +++ b/src/backend/amd64/Amd64Translator.cpp @@ -0,0 +1,24 @@ +#include "Amd64Translator.h" +#include "backend/amd64/instruction/control/Amd64RetZONear.h" +#include "backend/amd64/instruction/memory/Amd64PopO64.h" + +using namespace city; + +IRTranslationResult Amd64Translator::Translate(AddInst *instruction) {} + +IRTranslationResult Amd64Translator::Translate(BranchInst *instruction) {} + +IRTranslationResult Amd64Translator::Translate(RetInst *instruction) +{ + if (instruction->HasReturnValue()) + { + auto return_value = instruction->GetReturnValue(); + } + + this->module.EmplaceInstruction(Amd64RegisterCode::RBP); + this->module.EmplaceInstruction(); + + return {}; +} + +IRTranslationResult Amd64Translator::Translate(StoreInst *instruction) {} diff --git a/src/backend/x86/x86TranslationInterface.h b/src/backend/amd64/Amd64Translator.h similarity index 69% rename from src/backend/x86/x86TranslationInterface.h rename to src/backend/amd64/Amd64Translator.h index 7511aab..c2ff5d5 100644 --- a/src/backend/x86/x86TranslationInterface.h +++ b/src/backend/amd64/Amd64Translator.h @@ -1,18 +1,20 @@ #ifndef X86_64TRANSLATIONINTERFACE_H #define X86_64TRANSLATIONINTERFACE_H -#include "backend/IRTranslationInterface.h" +#include +#include "Amd64Register.h" +#include "backend/IRTranslator.h" namespace city { - struct x86TranslationInterface : IRTranslationInterface + struct Amd64Translator : IRTranslator { IRTranslationResult Translate(AddInst *instruction) override; IRTranslationResult Translate(BranchInst *instruction) override; IRTranslationResult Translate(RetInst *instruction) override; IRTranslationResult Translate(StoreInst *instruction) override; - explicit x86TranslationInterface(NativeModule &object) : IRTranslationInterface(object) {} + explicit Amd64Translator(NativeModule &object) : IRTranslator(object) {} }; } // namespace city diff --git a/src/backend/x86/instruction/x86Instruction.cpp b/src/backend/amd64/instruction/Amd64Instruction.cpp similarity index 73% rename from src/backend/x86/instruction/x86Instruction.cpp rename to src/backend/amd64/instruction/Amd64Instruction.cpp index 77a74d2..294c311 100644 --- a/src/backend/x86/instruction/x86Instruction.cpp +++ b/src/backend/amd64/instruction/Amd64Instruction.cpp @@ -1,9 +1,9 @@ -#include "x86Instruction.h" +#include "Amd64Instruction.h" #include using namespace city; -size_t x86Instruction::GetBinarySize() const noexcept +size_t Amd64Instruction::GetBinarySize() const noexcept { std::size_t size = 0; @@ -16,7 +16,7 @@ size_t x86Instruction::GetBinarySize() const noexcept return size; } -size_t x86Instruction::WriteToBuffer(std::byte *buffer) const +size_t Amd64Instruction::WriteToBuffer(std::byte *buffer) const { std::byte *buffer_it = buffer; @@ -44,22 +44,22 @@ size_t x86Instruction::WriteToBuffer(std::byte *buffer) const return buffer_it - buffer; } -void x86Instruction::SetPrefix(std::initializer_list bytes) +void Amd64Instruction::SetPrefix(std::initializer_list bytes) { this->prefix_ = bytes; } -void x86Instruction::SetOpcode(std::initializer_list bytes) +void Amd64Instruction::SetOpcode(std::initializer_list bytes) { this->opcode_ = bytes; } -void x86Instruction::SetImmediate(std::initializer_list bytes) +void Amd64Instruction::SetImmediate(std::initializer_list bytes) { this->immediate_ = bytes; } -void x86Instruction::SetModRM(x86RegisterCode reg, x86RegisterCode r_m, x86Mod mod) +void Amd64Instruction::SetModRM(Amd64RegisterCode reg, Amd64RegisterCode r_m, Amd64Mod mod) { auto breg = static_cast(reg); auto br_m = static_cast(r_m); diff --git a/src/backend/x86/instruction/x86Instruction.h b/src/backend/amd64/instruction/Amd64Instruction.h similarity index 75% rename from src/backend/x86/instruction/x86Instruction.h rename to src/backend/amd64/instruction/Amd64Instruction.h index b2c75c6..3fe2fe2 100644 --- a/src/backend/x86/instruction/x86Instruction.h +++ b/src/backend/amd64/instruction/Amd64Instruction.h @@ -5,14 +5,15 @@ #include #include "ByteBuffer.h" #include "backend/NativeInstruction.h" -#include "backend/x86/x86.h" +#include "backend/amd64/Amd64.h" +#include "backend/amd64/Amd64ModRM.h" namespace city { /** * Container to hold x86 maximum prefix size (3 bytes). */ - using x86Prefix = ByteBuffer<3>; + using Amd64Prefix = ByteBuffer<3>; enum class Amd64PrefixCode : std::uint8_t { @@ -22,17 +23,17 @@ namespace city /** * Container to hold the x86 maximum opcode size (3 bytes). */ - using x86Opcode = ByteBuffer<3>; + using Amd64Opcode = ByteBuffer<3>; /** * Container to hold the x86 maximum immediate size (8 bytes == 1QW). */ - using x86Immediate = ByteBuffer<8>; + using Amd64Immediate = ByteBuffer<8>; - class x86Instruction : public NativeInstruction + class Amd64Instruction : public NativeInstruction { - x86Prefix prefix_ = {}; - x86Opcode opcode_ = {}; + Amd64Prefix prefix_ = {}; + Amd64Opcode opcode_ = {}; bool has_mod_rm_ = false; std::uint8_t mod_rm_ = 0x0; @@ -40,7 +41,7 @@ namespace city bool has_sib_ = false; std::uint8_t sib_ = 0x0; - x86Immediate immediate_ = {}; + Amd64Immediate immediate_ = {}; public: [[nodiscard]] size_t GetBinarySize() const noexcept override; @@ -57,7 +58,7 @@ namespace city * @param mod Addressing Mode * @return ModR/M */ - void SetModRM(x86RegisterCode reg, x86RegisterCode r_m, x86Mod mod); + void SetModRM(Amd64RegisterCode reg, Amd64RegisterCode r_m, Amd64Mod mod); }; } // namespace city diff --git a/src/backend/x86/instruction/arithmetic/x86AddMI32Inst.h b/src/backend/amd64/instruction/arithmetic/x86AddMI32Inst.h similarity index 54% rename from src/backend/x86/instruction/arithmetic/x86AddMI32Inst.h rename to src/backend/amd64/instruction/arithmetic/x86AddMI32Inst.h index 71ce962..d234d61 100644 --- a/src/backend/x86/instruction/arithmetic/x86AddMI32Inst.h +++ b/src/backend/amd64/instruction/arithmetic/x86AddMI32Inst.h @@ -1,11 +1,11 @@ #ifndef X86ADDMI32INST_H #define X86ADDMI32INST_H -#include "backend/x86/instruction/x86Instruction.h" +#include "backend/amd64/instruction/Amd64Instruction.h" namespace city { - class x86AddMI32Inst : public x86Instruction + class x86AddMI32Inst : public Amd64Instruction { }; } // namespace city diff --git a/src/backend/x86/instruction/arithmetic/x86AddRM32Inst.h b/src/backend/amd64/instruction/arithmetic/x86AddRM32Inst.h similarity index 74% rename from src/backend/x86/instruction/arithmetic/x86AddRM32Inst.h rename to src/backend/amd64/instruction/arithmetic/x86AddRM32Inst.h index 9b9e5a0..4ab5a90 100644 --- a/src/backend/x86/instruction/arithmetic/x86AddRM32Inst.h +++ b/src/backend/amd64/instruction/arithmetic/x86AddRM32Inst.h @@ -1,7 +1,7 @@ #ifndef X86ADDRM32INST_H #define X86ADDRM32INST_H -#include "backend/x86/instruction/x86Instruction.h" +#include "backend/amd64/instruction/Amd64Instruction.h" #include "ir/value/Value.h" namespace city @@ -9,7 +9,7 @@ namespace city /** * ADD r32, r/m32 */ - class x86AddRM32Inst : public x86Instruction + class x86AddRM32Inst : public Amd64Instruction { public: x86AddRM32Inst(Value *dst, Value *src) diff --git a/src/backend/x86/instruction/control/Amd64RetZONear.h b/src/backend/amd64/instruction/control/Amd64RetZONear.h similarity index 69% rename from src/backend/x86/instruction/control/Amd64RetZONear.h rename to src/backend/amd64/instruction/control/Amd64RetZONear.h index 8cec4a0..1d9b087 100644 --- a/src/backend/x86/instruction/control/Amd64RetZONear.h +++ b/src/backend/amd64/instruction/control/Amd64RetZONear.h @@ -1,11 +1,11 @@ #ifndef CITY_AMD64RETZONEAR_H #define CITY_AMD64RETZONEAR_H -#include "backend/x86/instruction/x86Instruction.h" +#include "backend/amd64/instruction/Amd64Instruction.h" namespace city { - class Amd46RetZONear : public x86Instruction + class Amd46RetZONear : public Amd64Instruction { public: Amd46RetZONear() diff --git a/src/backend/x86/instruction/memory/Amd64MovMR64.h b/src/backend/amd64/instruction/memory/Amd64MovMR64.h similarity index 58% rename from src/backend/x86/instruction/memory/Amd64MovMR64.h rename to src/backend/amd64/instruction/memory/Amd64MovMR64.h index 34089fb..f79ed33 100644 --- a/src/backend/x86/instruction/memory/Amd64MovMR64.h +++ b/src/backend/amd64/instruction/memory/Amd64MovMR64.h @@ -1,19 +1,19 @@ #ifndef CITY_AMD64MOVMR64_H #define CITY_AMD64MOVMR64_H -#include "backend/x86/instruction/x86Instruction.h" +#include "backend/amd64/instruction/Amd64Instruction.h" namespace city { - class Amd64MovMR64 : public x86Instruction + class Amd64MovMR64 : public Amd64Instruction { public: - Amd64MovMR64(x86RegisterCode dst, x86RegisterCode src) + Amd64MovMR64(Amd64RegisterCode dst, Amd64RegisterCode src) { auto rexw = static_cast(Amd64PrefixCode::REXW); this->SetPrefix({rexw}); this->SetOpcode({0x89}); - this->SetModRM(src, dst, x86Mod::Register); + this->SetModRM(src, dst, Amd64Mod::Register); } }; } // namespace city diff --git a/src/backend/x86/instruction/memory/Amd64PopO64.h b/src/backend/amd64/instruction/memory/Amd64PopO64.h similarity index 65% rename from src/backend/x86/instruction/memory/Amd64PopO64.h rename to src/backend/amd64/instruction/memory/Amd64PopO64.h index 95eea87..40ee155 100644 --- a/src/backend/x86/instruction/memory/Amd64PopO64.h +++ b/src/backend/amd64/instruction/memory/Amd64PopO64.h @@ -1,14 +1,14 @@ #ifndef CITY_AMD64POPO64_H #define CITY_AMD64POPO64_H -#include "backend/x86/instruction/x86Instruction.h" +#include "backend/amd64/instruction/Amd64Instruction.h" namespace city { - class Amd64PopO64 : public x86Instruction + class Amd64PopO64 : public Amd64Instruction { public: - Amd64PopO64(x86RegisterCode reg) + Amd64PopO64(Amd64RegisterCode reg) { std::uint8_t opcode = 0x58 + static_cast(reg); this->SetOpcode({opcode}); diff --git a/src/backend/x86/instruction/memory/Amd64PushO64.h b/src/backend/amd64/instruction/memory/Amd64PushO64.h similarity index 65% rename from src/backend/x86/instruction/memory/Amd64PushO64.h rename to src/backend/amd64/instruction/memory/Amd64PushO64.h index d323005..7643f63 100644 --- a/src/backend/x86/instruction/memory/Amd64PushO64.h +++ b/src/backend/amd64/instruction/memory/Amd64PushO64.h @@ -1,14 +1,14 @@ #ifndef CITY_AMD64PUSHO64_H #define CITY_AMD64PUSHO64_H -#include "backend/x86/instruction/x86Instruction.h" +#include "backend/amd64/instruction/Amd64Instruction.h" namespace city { - class Amd64PushO64 : public x86Instruction + class Amd64PushO64 : public Amd64Instruction { public: - Amd64PushO64(x86RegisterCode reg) + Amd64PushO64(Amd64RegisterCode reg) { std::uint8_t opcode = 0x50 + static_cast(reg); this->SetOpcode({opcode}); diff --git a/src/backend/x86/x86-reference-manual.pdf b/src/backend/amd64/x86-reference-manual.pdf similarity index 100% rename from src/backend/x86/x86-reference-manual.pdf rename to src/backend/amd64/x86-reference-manual.pdf diff --git a/src/backend/x86/x86.cpp b/src/backend/x86/x86.cpp deleted file mode 100644 index d7953d4..0000000 --- a/src/backend/x86/x86.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "x86.h" -#include "instruction/memory/Amd64MovMR64.h" -#include "instruction/memory/Amd64PopO64.h" -#include "instruction/memory/Amd64PushO64.h" -#include "ir/Block.h" -#include "ir/Function.h" -#include "ir/instruction/IRInstruction.h" -#include "x86TranslationInterface.h" - -using namespace city; - -std::array const x86_register_definitions = { - x86Register(x86RegisterCode::XMM0), - x86Register(x86RegisterCode::XMM1), - x86Register(x86RegisterCode::XMM2), - x86Register(x86RegisterCode::XMM3), - x86Register(x86RegisterCode::XMM4), - x86Register(x86RegisterCode::XMM5), - x86Register(x86RegisterCode::XMM6), - x86Register(x86RegisterCode::XMM7), -}; - -NativeModule x86::BuildModule(IRModule &module) -{ - NativeModule object{}; - - x86TranslationInterface translator{object}; - for (auto &function : module.functions_) - { - // Function Prolog - auto entry = object.EmplaceInstruction(x86RegisterCode::RBP); - entry->SetLabel(function->name_); - - object.EmplaceInstruction(x86RegisterCode::RBP, x86RegisterCode::RSP); - - // Function Body - for (auto block : function->blocks_) - { - for (auto &instruction : block->instructions_) - { - instruction->Apply(&translator); - } - } - } - - return std::move(object); -} - -x86::x86() : registers_(x86_register_definitions) {} diff --git a/src/backend/x86/x86Register.cpp b/src/backend/x86/x86Register.cpp deleted file mode 100644 index 471b608..0000000 --- a/src/backend/x86/x86Register.cpp +++ /dev/null @@ -1,6 +0,0 @@ - -#include "x86Register.h" - -using namespace city; - -x86Register::x86Register(x86RegisterCode code) : code_(code) {} diff --git a/src/backend/x86/x86TranslationInterface.cpp b/src/backend/x86/x86TranslationInterface.cpp deleted file mode 100644 index 4275222..0000000 --- a/src/backend/x86/x86TranslationInterface.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "x86TranslationInterface.h" -#include "backend/x86/instruction/control/Amd64RetZONear.h" -#include "backend/x86/instruction/memory/Amd64PopO64.h" - -using namespace city; - -IRTranslationResult x86TranslationInterface::Translate(AddInst *instruction) {} - -IRTranslationResult x86TranslationInterface::Translate(BranchInst *instruction) {} - -IRTranslationResult x86TranslationInterface::Translate(RetInst *instruction) -{ - if (!instruction->value_) - { - this->object.EmplaceInstruction(x86RegisterCode::RBP); - this->object.EmplaceInstruction(); - } - else - { - } - - return {}; -} - -IRTranslationResult x86TranslationInterface::Translate(StoreInst *instruction) {} diff --git a/src/ir/Block.h b/src/ir/Block.h index 214058f..ed3d940 100644 --- a/src/ir/Block.h +++ b/src/ir/Block.h @@ -10,14 +10,14 @@ namespace city { class Builder; class AArch64; - class x86; + class Amd64; class Function; class Block { friend class Builder; friend class AArch64; - friend class x86; + friend class Amd64; protected: Function *parent_function_; diff --git a/src/ir/Function.h b/src/ir/Function.h index 298aeb1..08feda1 100644 --- a/src/ir/Function.h +++ b/src/ir/Function.h @@ -8,13 +8,13 @@ namespace city { class Builder; class AArch64; - class x86; + class Amd64; class Function { friend class Builder; friend class AArch64; - friend class x86; + friend class Amd64; protected: std::string name_; diff --git a/src/ir/IRModule.h b/src/ir/IRModule.h index 16d1730..2d0c723 100644 --- a/src/ir/IRModule.h +++ b/src/ir/IRModule.h @@ -10,13 +10,13 @@ namespace city { class AArch64; - class x86; + class Amd64; class IRModule { friend class Builder; friend class AArch64; - friend class x86; + friend class Amd64; std::string name_; diff --git a/src/ir/instruction/IRInstruction.h b/src/ir/instruction/IRInstruction.h index 5b9c5f0..03ce7ee 100644 --- a/src/ir/instruction/IRInstruction.h +++ b/src/ir/instruction/IRInstruction.h @@ -5,7 +5,7 @@ namespace city { - class IRTranslationInterface; + class IRTranslator; class Builder; class IRInstruction @@ -18,7 +18,7 @@ namespace city void SetReturnValue(Value *return_value); public: - virtual void Apply(IRTranslationInterface *interface) = 0; + virtual void Apply(IRTranslator *interface) = 0; [[nodiscard]] virtual bool HasReturnValue() const noexcept; [[nodiscard]] Value *GetReturnValue(); diff --git a/src/ir/instruction/arithmetic/AddInst.cpp b/src/ir/instruction/arithmetic/AddInst.cpp index f813703..336fc94 100644 --- a/src/ir/instruction/arithmetic/AddInst.cpp +++ b/src/ir/instruction/arithmetic/AddInst.cpp @@ -1,9 +1,9 @@ #include "AddInst.h" -#include "backend/IRTranslationInterface.h" +#include "backend/IRTranslator.h" using namespace city; -void AddInst::Apply(IRTranslationInterface *interface) +void AddInst::Apply(IRTranslator *interface) { interface->Translate(this); } diff --git a/src/ir/instruction/arithmetic/AddInst.h b/src/ir/instruction/arithmetic/AddInst.h index f4fe371..2d90180 100644 --- a/src/ir/instruction/arithmetic/AddInst.h +++ b/src/ir/instruction/arithmetic/AddInst.h @@ -11,7 +11,7 @@ namespace city Value *rhs_; public: - void Apply(IRTranslationInterface *interface) override; + void Apply(IRTranslator *interface) override; [[nodiscard]] bool HasReturnValue() const noexcept override; diff --git a/src/ir/instruction/control/BranchInst.cpp b/src/ir/instruction/control/BranchInst.cpp index 3337fa9..0fa92c3 100644 --- a/src/ir/instruction/control/BranchInst.cpp +++ b/src/ir/instruction/control/BranchInst.cpp @@ -1,9 +1,9 @@ #include "BranchInst.h" -#include "backend/IRTranslationInterface.h" +#include "backend/IRTranslator.h" using namespace city; -void BranchInst::Apply(IRTranslationInterface *interface) +void BranchInst::Apply(IRTranslator *interface) { interface->Translate(this); } diff --git a/src/ir/instruction/control/BranchInst.h b/src/ir/instruction/control/BranchInst.h index beac6a4..070d88f 100644 --- a/src/ir/instruction/control/BranchInst.h +++ b/src/ir/instruction/control/BranchInst.h @@ -5,14 +5,14 @@ namespace city { - class IRTranslationInterface; + class IRTranslator; class BranchInst : public IRInstruction { IRInstruction *target_; public: - void Apply(IRTranslationInterface *interface) override; + void Apply(IRTranslator *interface) override; BranchInst(IRInstruction *target); }; diff --git a/src/ir/instruction/control/RetInst.cpp b/src/ir/instruction/control/RetInst.cpp index 32e763f..8db7b09 100644 --- a/src/ir/instruction/control/RetInst.cpp +++ b/src/ir/instruction/control/RetInst.cpp @@ -1,9 +1,9 @@ #include "RetInst.h" -#include "backend/IRTranslationInterface.h" +#include "backend/IRTranslator.h" using namespace city; -void RetInst::Apply(IRTranslationInterface *interface) +void RetInst::Apply(IRTranslator *interface) { interface->Translate(this); } diff --git a/src/ir/instruction/control/RetInst.h b/src/ir/instruction/control/RetInst.h index a3b0165..1929911 100644 --- a/src/ir/instruction/control/RetInst.h +++ b/src/ir/instruction/control/RetInst.h @@ -5,18 +5,12 @@ namespace city { - class IRTranslationInterface; - class x86TranslationInterface; + class IRTranslator; class RetInst : public IRInstruction { - friend class x86TranslationInterface; - - protected: - Value *value_ = nullptr; - public: - void Apply(IRTranslationInterface *interface) override; + void Apply(IRTranslator *interface) override; RetInst(Value *value); }; diff --git a/src/ir/instruction/memory/StoreInst.cpp b/src/ir/instruction/memory/StoreInst.cpp index b75ac0f..78bb566 100644 --- a/src/ir/instruction/memory/StoreInst.cpp +++ b/src/ir/instruction/memory/StoreInst.cpp @@ -1,9 +1,9 @@ #include "StoreInst.h" -#include "backend/IRTranslationInterface.h" +#include "backend/IRTranslator.h" using namespace city; -void StoreInst::Apply(IRTranslationInterface *interface) +void StoreInst::Apply(IRTranslator *interface) { interface->Translate(this); } diff --git a/src/ir/instruction/memory/StoreInst.h b/src/ir/instruction/memory/StoreInst.h index 439d1d8..fa310a4 100644 --- a/src/ir/instruction/memory/StoreInst.h +++ b/src/ir/instruction/memory/StoreInst.h @@ -5,7 +5,7 @@ namespace city { - class IRTranslationInterface; + class IRTranslator; class StoreInst : public IRInstruction { @@ -13,7 +13,7 @@ namespace city Value *src_; public: - void Apply(IRTranslationInterface *interface) override; + void Apply(IRTranslator *interface) override; StoreInst(Value *dst, Value *src); };