From ab3ed680b569496319fc8c336919dfe0b1af18e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 10 Sep 2019 21:22:57 +0200 Subject: [PATCH] Use metrics from op_table --- lib/evmone/CMakeLists.txt | 2 +- lib/evmone/analysis.cpp | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/evmone/CMakeLists.txt b/lib/evmone/CMakeLists.txt index e57eb523fe..c4184340b6 100644 --- a/lib/evmone/CMakeLists.txt +++ b/lib/evmone/CMakeLists.txt @@ -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 $$ ) diff --git a/lib/evmone/analysis.cpp b/lib/evmone/analysis.cpp index 0df6ad5ea0..e5d26606fa 100644 --- a/lib/evmone/analysis.cpp +++ b/lib/evmone/analysis.cpp @@ -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}; @@ -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) { @@ -77,7 +71,7 @@ code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size) static_cast(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();