fxos/lib/passes/cfg.cpp

38 lines
832 B
C++

//---
// fxos.passes.cfg: CFG construction, as used by other passes
//---
#include <fxos/disassembly.h>
#include <cassert>
namespace FxOS {
CfgPass::CfgPass(Disassembly &disasm):
DisassemblyPass(disasm)
{
}
void CfgPass::analyze(uint32_t pc, ConcreteInstruction &ci)
{
std::vector<std::string> jump_mnemonics {
"bra", "bf", "bf.s", "bf/s", "bt", "bt.s", "bt/s",
};
/* Set the jmptarget fields whenever needed. This is easy because jump
instructions have trivially computable destinations */
for(auto mnemonic: jump_mnemonics)
{
if(ci.inst.mnemonic != mnemonic) continue;
auto &args = ci.inst.args;
assert((args.size() < 1 || args[0].kind != Argument::PcJump)
&& "invalid use of a jump instruction\n");
ci.jmptarget = pc + args[0].disp;
}
enqueue_unseen_successors(pc, ci);
}
} /* namespace FxOS */