Skip to content

Commit 112ff3c

Browse files
committed
baseline: Hide execution state from public API
Use the new array of `ExecutionState`s from the `VM`. Remove the `ExecutionState` parameter from the Baseline execution API. This removes the need of maintaining an external object pool for execution states.
1 parent 243efeb commit 112ff3c

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/evmone/baseline.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ EVMC_EXPORT CodeAnalysis analyze(bytes_view code, bool eof_enabled);
8080
evmc_result execute(evmc_vm* vm, const evmc_host_interface* host, evmc_host_context* ctx,
8181
evmc_revision rev, const evmc_message* msg, const uint8_t* code, size_t code_size) noexcept;
8282

83-
/// Executes in Baseline interpreter on the given external and initialized state.
84-
EVMC_EXPORT evmc_result execute(
85-
const VM&, int64_t gas_limit, ExecutionState& state, const CodeAnalysis& analysis) noexcept;
83+
/// Executes in Baseline interpreter with the pre-processed code.
84+
EVMC_EXPORT evmc_result execute(VM&, const evmc_host_interface& host, evmc_host_context* ctx,
85+
evmc_revision rev, const evmc_message& msg, const CodeAnalysis& analysis) noexcept;
8686

8787
} // namespace baseline
8888
} // namespace evmone

lib/evmone/baseline_execution.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,16 @@ int64_t dispatch_cgoto(
287287
#endif
288288
} // namespace
289289

290-
evmc_result execute(
291-
const VM& vm, int64_t gas, ExecutionState& state, const CodeAnalysis& analysis) noexcept
290+
evmc_result execute(VM& vm, const evmc_host_interface& host, evmc_host_context* ctx,
291+
evmc_revision rev, const evmc_message& msg, const CodeAnalysis& analysis) noexcept
292292
{
293-
state.analysis.baseline = &analysis; // Assign code analysis for instruction implementations.
294-
295293
const auto code = analysis.executable_code();
294+
auto gas = msg.gas;
295+
296+
auto& state = vm.get_execution_state(static_cast<size_t>(msg.depth));
297+
state.reset(msg, rev, host, ctx, analysis.raw_code());
298+
299+
state.analysis.baseline = &analysis; // Assign code analysis for instruction implementations.
296300

297301
const auto& cost_table = get_baseline_cost_table(state.rev, analysis.eof_header().version);
298302

@@ -349,7 +353,6 @@ evmc_result execute(evmc_vm* c_vm, const evmc_host_interface* host, evmc_host_co
349353
}
350354

351355
const auto code_analysis = analyze(container, eof_enabled);
352-
auto state = std::make_unique<ExecutionState>(*msg, rev, *host, ctx, container);
353-
return execute(*vm, msg->gas, *state, code_analysis);
356+
return execute(*vm, *host, ctx, rev, *msg, code_analysis);
354357
}
355358
} // namespace evmone::baseline

test/bench/helpers.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ inline evmc::Result advanced_execute(evmc::VM& /*vm*/, advanced::AdvancedExecuti
5959
return evmc::Result{execute(exec_state, analysis)};
6060
}
6161

62-
inline evmc::Result baseline_execute(evmc::VM& c_vm, ExecutionState& exec_state,
62+
inline evmc::Result baseline_execute(evmc::VM& c_vm, [[maybe_unused]] ExecutionState& exec_state,
6363
const baseline::CodeAnalysis& analysis, const evmc_message& msg, evmc_revision rev,
64-
evmc::Host& host, bytes_view code)
64+
evmc::Host& host, [[maybe_unused]] bytes_view code)
6565
{
66-
const auto& vm = *static_cast<evmone::VM*>(c_vm.get_raw_pointer());
67-
exec_state.reset(msg, rev, host.get_interface(), host.to_context(), code);
68-
return evmc::Result{baseline::execute(vm, msg.gas, exec_state, analysis)};
66+
auto& vm = *static_cast<evmone::VM*>(c_vm.get_raw_pointer());
67+
return evmc::Result{
68+
baseline::execute(vm, host.get_interface(), host.to_context(), rev, msg, analysis)};
6969
}
7070

7171
inline evmc::Result evmc_execute(evmc::VM& vm, FakeExecutionState& /*exec_state*/,

0 commit comments

Comments
 (0)