Skip to content

Commit

Permalink
Use instruction classification is the analysis loop
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 16, 2019
1 parent 205032c commit 1fa0dbd
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions lib/evmone/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,12 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)

auto& instr = analysis.instrs.back();

bool is_terminator = false; // A flag whenever this is a block terminating instruction.
switch (opcode)
switch (opcode_info.kind)
{
case OP_JUMP:
case OP_JUMPI:
case OP_STOP:
case OP_RETURN:
case OP_REVERT:
case OP_SELFDESTRUCT:
is_terminator = true;
default:
break;

case ANY_SMALL_PUSH:
case op_kind::small_push:
{
const auto push_size = size_t(opcode - OP_PUSH1 + 1);
const auto push_end = code_pos + push_size;
Expand All @@ -104,7 +97,7 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)
break;
}

case ANY_LARGE_PUSH:
case op_kind::large_push:
{
const auto push_size = size_t(opcode - OP_PUSH1 + 1);
const auto push_end = code_pos + push_size;
Expand All @@ -130,23 +123,18 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)
break;
}

case OP_GAS:
case OP_CALL:
case OP_CALLCODE:
case OP_DELEGATECALL:
case OP_STATICCALL:
case OP_CREATE:
case OP_CREATE2:
case op_kind::gas_counter_access:
instr.arg.number = block.gas_cost;
break;

case OP_PC:
case op_kind::pc:
instr.arg.number = static_cast<int>(code_pos - code - 1);
break;
}

// If this is a terminating instruction or the next instruction is a JUMPDEST.
if (is_terminator || (code_pos != code_end && *code_pos == OP_JUMPDEST))
if (opcode_info.kind == op_kind::terminator ||
(code_pos != code_end && *code_pos == OP_JUMPDEST))
{
// Save current block.
const auto stack_req = block.stack_req <= stack_req_max ?
Expand Down

0 comments on commit 1fa0dbd

Please sign in to comment.