Browse Source

Use readPushData() in basic block analysis

cl-refactor
Paweł Bylica 10 years ago
parent
commit
1728f58cba
  1. 21
      libevmjit/Compiler.cpp

21
libevmjit/Compiler.cpp

@ -56,29 +56,20 @@ void Compiler::createBasicBlocks(bytesConstRef bytecode)
ProgramCounter currentPC = curr - bytecode.begin(); ProgramCounter currentPC = curr - bytecode.begin();
validJumpTargets[currentPC] = true; validJumpTargets[currentPC] = true;
auto inst = static_cast<Instruction>(*curr); auto inst = Instruction(*curr);
switch (inst) switch (inst)
{ {
case Instruction::ANY_PUSH: case Instruction::ANY_PUSH:
{ {
auto numBytes = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::PUSH1) + 1; auto val = readPushData(curr, bytecode.end());
auto next = curr + numBytes + 1; auto next = curr + 1;
if (next >= bytecode.end()) if (next == bytecode.end())
break; break;
auto nextInst = static_cast<Instruction>(*next); auto nextInst = Instruction(*next);
if (nextInst == Instruction::JUMP || nextInst == Instruction::JUMPI) if (nextInst == Instruction::JUMP || nextInst == Instruction::JUMPI)
{ {
// Compute target PC of the jump.
u256 val = 0;
for (auto iter = curr + 1; iter < next; ++iter)
{
val <<= 8;
val |= *iter;
}
// Create a block for the JUMP target. // Create a block for the JUMP target.
ProgramCounter targetPC = val < bytecode.size() ? val.convert_to<ProgramCounter>() : bytecode.size(); ProgramCounter targetPC = val < bytecode.size() ? val.convert_to<ProgramCounter>() : bytecode.size();
splitPoints.insert(targetPC); splitPoints.insert(targetPC);
@ -86,8 +77,6 @@ void Compiler::createBasicBlocks(bytesConstRef bytecode)
ProgramCounter jumpPC = (next - bytecode.begin()); ProgramCounter jumpPC = (next - bytecode.begin());
directJumpTargets[jumpPC] = targetPC; directJumpTargets[jumpPC] = targetPC;
} }
curr += numBytes;
break; break;
} }

Loading…
Cancel
Save