[BOLT] Add BinaryFunction::registerBranch(). NFC (#83337)
Add an external interface to register a branch in a function that is in disassembled state. Allows to make custom modifications to the disassembler. E.g., a pre-CFG pass can add an instruction and register a branch that will later be used during the CFG construction.
This commit is contained in:
parent
3f2a9e5910
commit
d7d564b2fc
@ -2056,6 +2056,14 @@ public:
|
|||||||
/// Returns false if disassembly failed.
|
/// Returns false if disassembly failed.
|
||||||
Error disassemble();
|
Error disassemble();
|
||||||
|
|
||||||
|
/// An external interface to register a branch while the function is in
|
||||||
|
/// disassembled state. Allows to make custom modifications to the
|
||||||
|
/// disassembler. E.g., a pre-CFG pass can add an instruction and register
|
||||||
|
/// a branch that will later be used during the CFG construction.
|
||||||
|
///
|
||||||
|
/// Return a label at the branch destination.
|
||||||
|
MCSymbol *registerBranch(uint64_t Src, uint64_t Dst);
|
||||||
|
|
||||||
Error handlePCRelOperand(MCInst &Instruction, uint64_t Address,
|
Error handlePCRelOperand(MCInst &Instruction, uint64_t Address,
|
||||||
uint64_t Size);
|
uint64_t Size);
|
||||||
|
|
||||||
|
@ -1445,6 +1445,16 @@ add_instruction:
|
|||||||
return Error::success();
|
return Error::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MCSymbol *BinaryFunction::registerBranch(uint64_t Src, uint64_t Dst) {
|
||||||
|
assert(CurrentState == State::Disassembled &&
|
||||||
|
"Cannot register branch unless function is in disassembled state.");
|
||||||
|
assert(containsAddress(Src) && containsAddress(Dst) &&
|
||||||
|
"Cannot register external branch.");
|
||||||
|
MCSymbol *Target = getOrCreateLocalLabel(Dst);
|
||||||
|
TakenBranches.emplace_back(Src - getAddress(), Dst - getAddress());
|
||||||
|
return Target;
|
||||||
|
}
|
||||||
|
|
||||||
bool BinaryFunction::scanExternalRefs() {
|
bool BinaryFunction::scanExternalRefs() {
|
||||||
bool Success = true;
|
bool Success = true;
|
||||||
bool DisassemblyFailed = false;
|
bool DisassemblyFailed = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user