Skip to content

Commit

Permalink
Use metrics from op_table
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 12, 2019
1 parent 4edc45d commit f3f0f0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/evmone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_library(evmone
limits.hpp
opcodes_helpers.h
)
target_link_libraries(evmone PUBLIC evmc::evmc PRIVATE intx::intx evmc::instructions ethash::keccak)
target_link_libraries(evmone PUBLIC evmc::evmc PRIVATE intx::intx ethash::keccak)
target_include_directories(evmone PUBLIC
$<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
Expand Down
16 changes: 5 additions & 11 deletions lib/evmone/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)
const auto max_args_storage_size = code_size + 1;
analysis.push_values.reserve(max_args_storage_size);

const auto* instr_table = evmc_get_instruction_metrics_table(rev);

// Create first block.
analysis.instrs.emplace_back(opx_beginblock_fn);
auto block = block_analysis{0};
Expand All @@ -56,17 +54,13 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)
while (code_pos != code_end)
{
const auto opcode = *code_pos++;
const auto opcode_info = op_tbl[opcode];

const auto metrics = instr_table[opcode];
const auto instr_stack_req = metrics.num_stack_arguments;
const auto instr_stack_change = metrics.num_stack_returned_items - instr_stack_req;

block.stack_req = std::max(block.stack_req, instr_stack_req - block.stack_change);
block.stack_change += instr_stack_change;
block.stack_req = std::max(block.stack_req, opcode_info.stack_req - block.stack_change);
block.stack_change += opcode_info.stack_change;
block.stack_max_growth = std::max(block.stack_max_growth, block.stack_change);

if (metrics.gas_cost > 0) // can be -1 for undefined instruction
block.gas_cost += metrics.gas_cost;
block.gas_cost += opcode_info.gas_cost;

if (opcode == OP_JUMPDEST)
{
Expand All @@ -77,7 +71,7 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size)
static_cast<int16_t>(analysis.instrs.size() - 1));
}
else
analysis.instrs.emplace_back(op_tbl[opcode].fn);
analysis.instrs.emplace_back(opcode_info.fn);

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

Expand Down

0 comments on commit f3f0f0d

Please sign in to comment.