-
Notifications
You must be signed in to change notification settings - Fork 64
feat: integrate Rabbitizer via FetchContent #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #include "ps2recomp/elf_analyzer.h" | ||
| #include <rabbitizer.h> | ||
| #include <iostream> | ||
| #include <sstream> | ||
| #include <algorithm> | ||
|
|
@@ -20,7 +21,6 @@ namespace ps2recomp | |
| : m_elfPath(elfPath) | ||
| { | ||
| m_elfParser = std::make_unique<ElfParser>(elfPath); | ||
| m_decoder = std::make_unique<R5900Decoder>(); | ||
|
|
||
| initializeLibraryFunctions(); | ||
| } | ||
|
|
@@ -192,7 +192,7 @@ namespace ps2recomp | |
| const std::vector<std::string> stdLibFuncs = { | ||
| // I/O functions | ||
| "printf", "sprintf", "snprintf", "fprintf", "vprintf", "vfprintf", "vsprintf", "vsnprintf", | ||
| "puts", "putchar", "getchar", "gets", "fgets", "fputs", "scanf", "fscanf", "sscanf", | ||
| "puts", "putchar", "getchar", "gets", "fgets", "fputs", "scanf", "fscanf", "sscanf", | ||
| "sprint", "sbprintf", | ||
|
|
||
| // Memory management | ||
|
|
@@ -255,7 +255,7 @@ namespace ps2recomp | |
| { | ||
| if (inst.opcode == OPCODE_JAL) | ||
| { | ||
| uint32_t target = (inst.address & 0xF0000000) | (inst.target << 2); | ||
| uint32_t target = inst.target; | ||
|
|
||
| for (const auto &func : m_functions) | ||
| { | ||
|
|
@@ -537,7 +537,7 @@ namespace ps2recomp | |
|
|
||
| if (nextInst.opcode == OPCODE_J || nextInst.opcode == OPCODE_JAL) | ||
| { | ||
| uint32_t jumpTarget = (nextInst.address & 0xF0000000) | (nextInst.target << 2); | ||
| uint32_t jumpTarget = nextInst.target; | ||
|
|
||
| for (const auto §ion : m_sections) | ||
| { | ||
|
|
@@ -652,7 +652,7 @@ namespace ps2recomp | |
|
|
||
| if (inst.opcode == OPCODE_JAL) | ||
| { | ||
| targetAddr = (inst.address & 0xF0000000) | (inst.target << 2); | ||
| targetAddr = inst.target; | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -1358,7 +1358,7 @@ namespace ps2recomp | |
| // Jump target for J/JAL | ||
| if ((inst.opcode == OPCODE_J || inst.opcode == OPCODE_JAL) && !inst.isCall) | ||
| { | ||
| uint32_t target = (inst.address & 0xF0000000) | (inst.target << 2); | ||
| uint32_t target = inst.target; | ||
| leaders.insert(target); | ||
| } | ||
| } | ||
|
|
@@ -1439,7 +1439,7 @@ namespace ps2recomp | |
| if (lastInst.opcode == OPCODE_J || lastInst.opcode == OPCODE_JAL) | ||
| { | ||
| // Direct jump | ||
| uint32_t targetAddr = (lastInst.address & 0xF0000000) | (lastInst.target << 2); | ||
| uint32_t targetAddr = lastInst.target; | ||
|
|
||
| // Only add successor if it's within this function | ||
| if (targetAddr >= function.start && targetAddr < function.end && | ||
|
|
@@ -1580,16 +1580,33 @@ namespace ps2recomp | |
|
|
||
| uint32_t rawInstruction = m_elfParser->readWord(addr); | ||
|
|
||
| try | ||
| { | ||
| Instruction inst = m_decoder->decodeInstruction(addr, rawInstruction); | ||
| instructions.push_back(inst); | ||
| } | ||
| catch (const std::exception &e) | ||
| { | ||
| std::cerr << "Error decoding instruction at " << formatAddress(addr) | ||
| << ": " << e.what() << std::endl; | ||
| } | ||
| RabbitizerInstruction instr; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use decodeInstruction function here ? |
||
| RabbitizerInstruction_init(&instr, rawInstruction, addr); | ||
|
|
||
| Instruction inst; | ||
| inst.address = addr; | ||
| inst.raw = rawInstruction; | ||
| inst.opcode = RAB_INSTR_GET_opcode(&instr); | ||
| inst.rs = RAB_INSTR_GET_rs(&instr); | ||
| inst.rt = RAB_INSTR_GET_rt(&instr); | ||
| inst.rd = RAB_INSTR_GET_rd(&instr); | ||
| inst.sa = RAB_INSTR_GET_sa(&instr); | ||
| inst.function = RAB_INSTR_GET_function(&instr); | ||
| inst.immediate = RAB_INSTR_GET_immediate(&instr); | ||
| inst.simmediate = static_cast<uint32_t>(RabbitizerInstruction_getProcessedImmediate(&instr)); | ||
| inst.target = RabbitizerInstruction_getInstrIndexAsVram(&instr); | ||
| inst.hasDelaySlot = RabbitizerInstruction_hasDelaySlot(&instr); | ||
| inst.isCall = RabbitizerInstruction_isFunctionCall(&instr); | ||
| inst.isReturn = RabbitizerInstruction_isReturn(&instr); | ||
| inst.isBranch = (RabbitizerInstruction_getBranchOffsetGeneric(&instr) != 0) || | ||
| RabbitizerInstruction_isJumptableJump(&instr); | ||
| inst.isJump = RabbitizerInstruction_isUnconditionalBranch(&instr) || | ||
| RabbitizerInstruction_isJumptableJump(&instr); | ||
| inst.isMMI = (inst.opcode == OPCODE_MMI); | ||
| inst.isVU = (inst.opcode == OPCODE_COP2); | ||
|
|
||
| instructions.push_back(inst); | ||
| RabbitizerInstruction_destroy(&instr); | ||
| } | ||
|
|
||
| return instructions; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| #ifndef PS2RECOMP_DECODER_H | ||
| #define PS2RECOMP_DECODER_H | ||
|
|
||
| #include "ps2recomp/types.h" | ||
| #include "ps2recomp/instructions.h" | ||
| #include <cstdint> | ||
|
|
||
| namespace ps2recomp | ||
| { | ||
| Instruction decodeInstruction(uint32_t address, uint32_t rawInstruction); | ||
| uint32_t getBranchTarget(const Instruction &inst); | ||
| uint32_t getJumpTarget(const Instruction &inst); | ||
| } | ||
|
|
||
| #endif // PS2RECOMP_DECODER_H |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.