From 8242be7319d53c1c8105785e4d58168a9c51b67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 9 Sep 2024 14:21:30 +0200 Subject: [PATCH] change API: hide ExecutionState --- lib/evmone/baseline.hpp | 6 +++--- lib/evmone/baseline_execution.cpp | 15 +++++++++------ test/bench/helpers.hpp | 10 +++++----- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/evmone/baseline.hpp b/lib/evmone/baseline.hpp index 5c9203e1ac..d2eca7a712 100644 --- a/lib/evmone/baseline.hpp +++ b/lib/evmone/baseline.hpp @@ -80,9 +80,9 @@ EVMC_EXPORT CodeAnalysis analyze(bytes_view code, bool eof_enabled); evmc_result execute(evmc_vm* vm, const evmc_host_interface* host, evmc_host_context* ctx, evmc_revision rev, const evmc_message* msg, const uint8_t* code, size_t code_size) noexcept; -/// Executes in Baseline interpreter on the given external and initialized state. -EVMC_EXPORT evmc_result execute( - const VM&, int64_t gas_limit, ExecutionState& state, const CodeAnalysis& analysis) noexcept; +/// Executes in Baseline interpreter with the pre-processed code. +EVMC_EXPORT evmc_result execute(VM&, const evmc_host_interface& host, evmc_host_context* ctx, + evmc_revision rev, const evmc_message& msg, const CodeAnalysis& analysis) noexcept; } // namespace baseline } // namespace evmone diff --git a/lib/evmone/baseline_execution.cpp b/lib/evmone/baseline_execution.cpp index 22e839b33d..5a404a9cec 100644 --- a/lib/evmone/baseline_execution.cpp +++ b/lib/evmone/baseline_execution.cpp @@ -287,12 +287,16 @@ int64_t dispatch_cgoto( #endif } // namespace -evmc_result execute( - const VM& vm, int64_t gas, ExecutionState& state, const CodeAnalysis& analysis) noexcept +evmc_result execute(VM& vm, const evmc_host_interface& host, evmc_host_context* ctx, + evmc_revision rev, const evmc_message& msg, const CodeAnalysis& analysis) noexcept { - state.analysis.baseline = &analysis; // Assign code analysis for instruction implementations. - const auto code = analysis.executable_code(); + auto gas = msg.gas; + + auto& state = vm.get_execution_state(static_cast(msg.depth)); + state.reset(msg, rev, host, ctx, analysis.raw_code()); + + state.analysis.baseline = &analysis; // Assign code analysis for instruction implementations. const auto& cost_table = get_baseline_cost_table(state.rev, analysis.eof_header().version); @@ -349,7 +353,6 @@ evmc_result execute(evmc_vm* c_vm, const evmc_host_interface* host, evmc_host_co } const auto code_analysis = analyze(container, eof_enabled); - auto state = std::make_unique(*msg, rev, *host, ctx, container); - return execute(*vm, msg->gas, *state, code_analysis); + return execute(*vm, *host, ctx, rev, *msg, code_analysis); } } // namespace evmone::baseline diff --git a/test/bench/helpers.hpp b/test/bench/helpers.hpp index a2db5beefe..a9083afd75 100644 --- a/test/bench/helpers.hpp +++ b/test/bench/helpers.hpp @@ -59,13 +59,13 @@ inline evmc::Result advanced_execute(evmc::VM& /*vm*/, advanced::AdvancedExecuti return evmc::Result{execute(exec_state, analysis)}; } -inline evmc::Result baseline_execute(evmc::VM& c_vm, ExecutionState& exec_state, +inline evmc::Result baseline_execute(evmc::VM& c_vm, [[maybe_unused]] ExecutionState& exec_state, const baseline::CodeAnalysis& analysis, const evmc_message& msg, evmc_revision rev, - evmc::Host& host, bytes_view code) + evmc::Host& host, [[maybe_unused]] bytes_view code) { - const auto& vm = *static_cast(c_vm.get_raw_pointer()); - exec_state.reset(msg, rev, host.get_interface(), host.to_context(), code); - return evmc::Result{baseline::execute(vm, msg.gas, exec_state, analysis)}; + auto& vm = *static_cast(c_vm.get_raw_pointer()); + return evmc::Result{ + baseline::execute(vm, host.get_interface(), host.to_context(), rev, msg, analysis)}; } inline evmc::Result evmc_execute(evmc::VM& vm, FakeExecutionState& /*exec_state*/,