From b2e548458d73551e4421fe6db0fa5424ec2e00bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Sun, 1 Sep 2024 13:55:21 +0200 Subject: [PATCH] baseline: VM-level ExecutionStates --- lib/evmone/vm.cpp | 18 ++++++++++++++++-- lib/evmone/vm.hpp | 7 ++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/evmone/vm.cpp b/lib/evmone/vm.cpp index 014ebca00c..fbfa91bb70 100644 --- a/lib/evmone/vm.cpp +++ b/lib/evmone/vm.cpp @@ -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", @@ -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 diff --git a/lib/evmone/vm.hpp b/lib/evmone/vm.hpp index 34bcd4a920..6549e3ae3e 100644 --- a/lib/evmone/vm.hpp +++ b/lib/evmone/vm.hpp @@ -3,8 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#include "execution_state.hpp" #include "tracing.hpp" #include +#include #if defined(_MSC_VER) && !defined(__clang__) #define EVMONE_CGOTO_SUPPORTED 0 @@ -22,10 +24,13 @@ class VM : public evmc_vm bool validate_eof = false; private: + std::vector m_execution_states; std::unique_ptr 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) noexcept {