-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e2539d
commit f4d37b5
Showing
34 changed files
with
166 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Amd64Register, 8> 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<Amd64PushO64>(Amd64RegisterCode::RBP); | ||
entry->SetLabel(function->name_); | ||
|
||
object.EmplaceInstruction<Amd64MovMR64>(Amd64RegisterCode::RBP, Amd64RegisterCode::RSP); | ||
|
||
// Function Body | ||
for (auto block : function->blocks_) | ||
{ | ||
for (auto &instruction : block->instructions_) | ||
{ | ||
instruction->Apply(&translator); | ||
} | ||
} | ||
} | ||
|
||
return std::move(object); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
#include "Amd64Register.h" | ||
|
||
using namespace city; | ||
|
||
Amd64Register::Amd64Register(Amd64RegisterCode code) : code_(code) {} |
8 changes: 4 additions & 4 deletions
8
src/backend/x86/x86Register.h → src/backend/amd64/Amd64Register.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Amd64PopO64>(Amd64RegisterCode::RBP); | ||
this->module.EmplaceInstruction<Amd46RetZONear>(); | ||
|
||
return {}; | ||
} | ||
|
||
IRTranslationResult Amd64Translator::Translate(StoreInst *instruction) {} |
8 changes: 5 additions & 3 deletions
8
src/backend/x86/x86TranslationInterface.h → src/backend/amd64/Amd64Translator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...6/instruction/arithmetic/x86AddMI32Inst.h → ...4/instruction/arithmetic/x86AddMI32Inst.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...6/instruction/arithmetic/x86AddRM32Inst.h → ...4/instruction/arithmetic/x86AddRM32Inst.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../x86/instruction/control/Amd64RetZONear.h → ...md64/instruction/control/Amd64RetZONear.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.