Skip to content

Commit

Permalink
change API: hide ExecutionState
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 12, 2024
1 parent f0697a6 commit 8242be7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/evmone/baseline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 9 additions & 6 deletions lib/evmone/baseline_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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);

Expand Down Expand Up @@ -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<ExecutionState>(*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
10 changes: 5 additions & 5 deletions test/bench/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 62 in test/bench/helpers.hpp

View check run for this annotation

Codecov / codecov/patch

test/bench/helpers.hpp#L62

Added line #L62 was not covered by tests
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<evmone::VM*>(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<evmone::VM*>(c_vm.get_raw_pointer());

Check warning on line 66 in test/bench/helpers.hpp

View check run for this annotation

Codecov / codecov/patch

test/bench/helpers.hpp#L66

Added line #L66 was not covered by tests
return evmc::Result{
baseline::execute(vm, host.get_interface(), host.to_context(), rev, msg, analysis)};

Check warning on line 68 in test/bench/helpers.hpp

View check run for this annotation

Codecov / codecov/patch

test/bench/helpers.hpp#L68

Added line #L68 was not covered by tests
}

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

0 comments on commit 8242be7

Please sign in to comment.