3
3
// SPDX-License-Identifier: Apache-2.0
4
4
5
5
#include " baseline.hpp"
6
+ #include " baseline_instruction_table.hpp"
6
7
#include " execution_state.hpp"
7
8
#include " instructions.hpp"
8
9
#include " vm.hpp"
@@ -84,12 +85,12 @@ inline void op_return(ExecutionState& state) noexcept
84
85
state.status = StatusCode;
85
86
}
86
87
87
- inline evmc_status_code check_requirements (const char * const * instruction_names,
88
- const evmc_instruction_metrics* instruction_metrics , ExecutionState& state, uint8_t op) noexcept
88
+ inline evmc_status_code check_requirements (
89
+ const InstructionTable& instruction_table , ExecutionState& state, uint8_t op) noexcept
89
90
{
90
- const auto metrics = instruction_metrics [op];
91
+ const auto metrics = instruction_table [op];
91
92
92
- if (instruction_names[op] == nullptr )
93
+ if (metrics. gas_cost == instr::undefined )
93
94
return EVMC_UNDEFINED_INSTRUCTION;
94
95
95
96
if ((state.gas_left -= metrics.gas_cost ) < 0 )
@@ -98,7 +99,7 @@ inline evmc_status_code check_requirements(const char* const* instruction_names,
98
99
const auto stack_size = state.stack .size ();
99
100
if (stack_size < metrics.stack_height_required )
100
101
return EVMC_STACK_UNDERFLOW;
101
- if (stack_size + metrics. stack_height_change > Stack::limit)
102
+ if (stack_size == Stack::limit && metrics. can_overflow_stack )
102
103
return EVMC_STACK_OVERFLOW;
103
104
104
105
return EVMC_SUCCESS;
@@ -114,8 +115,7 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
114
115
if constexpr (TracingEnabled)
115
116
tracer->notify_execution_start (state.rev , *state.msg , state.code );
116
117
117
- const auto instruction_names = evmc_get_instruction_names_table (state.rev );
118
- const auto instruction_metrics = evmc_get_instruction_metrics_table (state.rev );
118
+ const auto & instruction_table = get_baseline_instruction_table (state.rev );
119
119
120
120
const auto * const code = state.code .data ();
121
121
auto pc = code;
@@ -129,7 +129,7 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
129
129
}
130
130
131
131
const auto op = *pc;
132
- const auto status = check_requirements (instruction_names, instruction_metrics , state, op);
132
+ const auto status = check_requirements (instruction_table , state, op);
133
133
if (status != EVMC_SUCCESS)
134
134
{
135
135
state.status = status;
0 commit comments