Skip to content

Commit

Permalink
baseline: VM-level ExecutionStates
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 12, 2024
1 parent 19a527e commit b2e5484
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/evmone/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ evmc_set_option_result set_option(evmc_vm* c_vm, char const* c_name, char const*
} // namespace


inline constexpr VM::VM() noexcept
VM::VM() noexcept
: evmc_vm{
EVMC_ABI_VERSION,
"evmone",
Expand All @@ -82,7 +82,21 @@ inline constexpr VM::VM() noexcept
evmone::get_capabilities,
evmone::set_option,
}
{}
{
m_execution_states.reserve(1025);
}

ExecutionState& VM::get_execution_state(size_t depth) noexcept
{
// Vector already has the capacity for all possible depths,
// so reallocation never happens (therefore: noexcept).
// TODO: Maybe just use std::array?
// FIXME: unit test where max depth is reached is needed.
assert(depth < m_execution_states.capacity());
if (m_execution_states.size() <= depth)
m_execution_states.resize(depth + 1);
return m_execution_states[depth];
}

} // namespace evmone

Expand Down
7 changes: 6 additions & 1 deletion lib/evmone/vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include "execution_state.hpp"
#include "tracing.hpp"
#include <evmc/evmc.h>
#include <vector>

#if defined(_MSC_VER) && !defined(__clang__)
#define EVMONE_CGOTO_SUPPORTED 0
Expand All @@ -22,10 +24,13 @@ class VM : public evmc_vm
bool validate_eof = false;

private:
std::vector<ExecutionState> m_execution_states;
std::unique_ptr<Tracer> m_first_tracer;

public:
inline constexpr VM() noexcept;
VM() noexcept;

[[nodiscard]] ExecutionState& get_execution_state(size_t depth) noexcept;

void add_tracer(std::unique_ptr<Tracer> tracer) noexcept
{
Expand Down

0 comments on commit b2e5484

Please sign in to comment.