From 439561a5fa352e087ef3e3d4ccee0c4fe7ec66fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 30 Oct 2014 19:28:10 +0100 Subject: [PATCH] Use readPushData() in basic block analysis --- libevmjit/Compiler.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/libevmjit/Compiler.cpp b/libevmjit/Compiler.cpp index 92357e8d8..1e394eba0 100644 --- a/libevmjit/Compiler.cpp +++ b/libevmjit/Compiler.cpp @@ -56,29 +56,20 @@ void Compiler::createBasicBlocks(bytesConstRef bytecode) ProgramCounter currentPC = curr - bytecode.begin(); validJumpTargets[currentPC] = true; - auto inst = static_cast(*curr); + auto inst = Instruction(*curr); switch (inst) { case Instruction::ANY_PUSH: { - auto numBytes = static_cast(inst) - static_cast(Instruction::PUSH1) + 1; - auto next = curr + numBytes + 1; - if (next >= bytecode.end()) + auto val = readPushData(curr, bytecode.end()); + auto next = curr + 1; + if (next == bytecode.end()) break; - auto nextInst = static_cast(*next); - + auto nextInst = Instruction(*next); 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. ProgramCounter targetPC = val < bytecode.size() ? val.convert_to() : bytecode.size(); splitPoints.insert(targetPC); @@ -86,8 +77,6 @@ void Compiler::createBasicBlocks(bytesConstRef bytecode) ProgramCounter jumpPC = (next - bytecode.begin()); directJumpTargets[jumpPC] = targetPC; } - - curr += numBytes; break; }