Skip to content

Commit 7b01841

Browse files
authored
Merge pull request #312 from ethereum/renames
Rename some structs
2 parents f9694d2 + 2f717ab commit 7b01841

File tree

7 files changed

+46
-44
lines changed

7 files changed

+46
-44
lines changed

lib/evmone/analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ struct block_analysis
3939
}
4040
};
4141

42-
code_analysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size) noexcept
42+
AdvancedCodeAnalysis analyze(evmc_revision rev, const uint8_t* code, size_t code_size) noexcept
4343
{
4444
const auto& op_tbl = get_op_table(rev);
4545
const auto opx_beginblock_fn = op_tbl[OPX_BEGINBLOCK].fn;
4646

47-
code_analysis analysis;
47+
AdvancedCodeAnalysis analysis;
4848

4949
const auto max_instrs_size = code_size + 1;
5050
analysis.instrs.reserve(max_instrs_size);

lib/evmone/analysis.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace evmone
1717
{
1818
struct instruction;
1919

20+
/// Compressed information about instruction basic block.
2021
struct block_info
2122
{
2223
/// The total base gas cost of all instructions in the block.
@@ -41,23 +42,24 @@ struct block_info
4142
};
4243
static_assert(sizeof(block_info) == 8);
4344

44-
struct code_analysis;
45+
struct AdvancedCodeAnalysis;
4546

46-
struct execution_state : ExecutionState
47+
/// The execution state specialized for the Advanced interpreter.
48+
struct AdvancedExecutionState : ExecutionState
4749
{
4850
/// The gas cost of the current block.
4951
///
5052
/// This is only needed to correctly calculate the "current gas left" value.
5153
uint32_t current_block_cost = 0;
5254

5355
/// Pointer to code analysis.
54-
const code_analysis* analysis = nullptr;
56+
const AdvancedCodeAnalysis* analysis = nullptr;
5557

56-
execution_state() = default;
58+
AdvancedExecutionState() = default;
5759

58-
execution_state(const evmc_message& message, evmc_revision revision,
60+
AdvancedExecutionState(const evmc_message& message, evmc_revision revision,
5961
const evmc_host_interface& host_interface, evmc_host_context* host_ctx,
60-
const uint8_t* code_ptr, size_t code_size, const code_analysis& a) noexcept
62+
const uint8_t* code_ptr, size_t code_size, const AdvancedCodeAnalysis& a) noexcept
6163
: ExecutionState{message, revision, host_interface, host_ctx, code_ptr, code_size},
6264
analysis{&a}
6365
{}
@@ -72,7 +74,7 @@ struct execution_state : ExecutionState
7274
/// Resets the contents of the execution_state so that it could be reused.
7375
void reset(const evmc_message& message, evmc_revision revision,
7476
const evmc_host_interface& host_interface, evmc_host_context* host_ctx,
75-
const uint8_t* code_ptr, size_t code_size, const code_analysis& a) noexcept
77+
const uint8_t* code_ptr, size_t code_size, const AdvancedCodeAnalysis& a) noexcept
7678
{
7779
ExecutionState::reset(message, revision, host_interface, host_ctx, code_ptr, code_size);
7880
current_block_cost = 0;
@@ -91,7 +93,7 @@ static_assert(
9193
sizeof(instruction_argument) == sizeof(uint64_t), "Incorrect size of instruction_argument");
9294

9395
/// The pointer to function implementing an instruction execution.
94-
using instruction_exec_fn = const instruction* (*)(const instruction*, execution_state&);
96+
using instruction_exec_fn = const instruction* (*)(const instruction*, AdvancedExecutionState&);
9597

9698
/// The evmone intrinsic opcodes.
9799
///
@@ -125,7 +127,7 @@ struct instruction
125127
explicit constexpr instruction(instruction_exec_fn f) noexcept : fn{f}, arg{} {}
126128
};
127129

128-
struct code_analysis
130+
struct AdvancedCodeAnalysis
129131
{
130132
std::vector<instruction> instrs;
131133

@@ -143,7 +145,7 @@ struct code_analysis
143145
std::vector<int32_t> jumpdest_targets;
144146
};
145147

146-
inline int find_jumpdest(const code_analysis& analysis, int offset) noexcept
148+
inline int find_jumpdest(const AdvancedCodeAnalysis& analysis, int offset) noexcept
147149
{
148150
const auto begin = std::begin(analysis.jumpdest_offsets);
149151
const auto end = std::end(analysis.jumpdest_offsets);
@@ -153,7 +155,7 @@ inline int find_jumpdest(const code_analysis& analysis, int offset) noexcept
153155
-1;
154156
}
155157

156-
EVMC_EXPORT code_analysis analyze(
158+
EVMC_EXPORT AdvancedCodeAnalysis analyze(
157159
evmc_revision rev, const uint8_t* code, size_t code_size) noexcept;
158160

159161
EVMC_EXPORT const op_table& get_op_table(evmc_revision rev) noexcept;

lib/evmone/execution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ evmc_result execute(evmc_vm* /*unused*/, const evmc_host_interface* host, evmc_h
1414
const auto analysis = analyze(rev, code, code_size);
1515

1616
auto state =
17-
std::make_unique<execution_state>(*msg, rev, *host, ctx, code, code_size, analysis);
17+
std::make_unique<AdvancedExecutionState>(*msg, rev, *host, ctx, code, code_size, analysis);
1818

1919
const auto* instr = &state->analysis->instrs[0];
2020
while (instr != nullptr)

lib/evmone/instructions.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ namespace evmone
1111
namespace
1212
{
1313
template <void InstrFn(evm_stack&)>
14-
const instruction* op(const instruction* instr, execution_state& state) noexcept
14+
const instruction* op(const instruction* instr, AdvancedExecutionState& state) noexcept
1515
{
1616
InstrFn(state.stack);
1717
return ++instr;
1818
}
1919

2020
template <void InstrFn(ExecutionState&)>
21-
const instruction* op(const instruction* instr, execution_state& state) noexcept
21+
const instruction* op(const instruction* instr, AdvancedExecutionState& state) noexcept
2222
{
2323
InstrFn(state);
2424
return ++instr;
2525
}
2626

2727
template <evmc_status_code InstrFn(ExecutionState&)>
28-
const instruction* op(const instruction* instr, execution_state& state) noexcept
28+
const instruction* op(const instruction* instr, AdvancedExecutionState& state) noexcept
2929
{
3030
const auto status_code = InstrFn(state);
3131
if (status_code != EVMC_SUCCESS)
3232
return state.exit(status_code);
3333
return ++instr;
3434
}
3535

36-
const instruction* op_stop(const instruction*, execution_state& state) noexcept
36+
const instruction* op_stop(const instruction*, AdvancedExecutionState& state) noexcept
3737
{
3838
return state.exit(EVMC_SUCCESS);
3939
}
4040

41-
const instruction* op_sstore(const instruction* instr, execution_state& state) noexcept
41+
const instruction* op_sstore(const instruction* instr, AdvancedExecutionState& state) noexcept
4242
{
4343
const auto gas_left_correction = state.current_block_cost - instr->arg.number;
4444
state.gas_left += gas_left_correction;
@@ -53,7 +53,7 @@ const instruction* op_sstore(const instruction* instr, execution_state& state) n
5353
return ++instr;
5454
}
5555

56-
const instruction* op_jump(const instruction*, execution_state& state) noexcept
56+
const instruction* op_jump(const instruction*, AdvancedExecutionState& state) noexcept
5757
{
5858
const auto dst = state.stack.pop();
5959
auto pc = -1;
@@ -64,7 +64,7 @@ const instruction* op_jump(const instruction*, execution_state& state) noexcept
6464
return &state.analysis->instrs[static_cast<size_t>(pc)];
6565
}
6666

67-
const instruction* op_jumpi(const instruction* instr, execution_state& state) noexcept
67+
const instruction* op_jumpi(const instruction* instr, AdvancedExecutionState& state) noexcept
6868
{
6969
if (state.stack[1] != 0)
7070
instr = op_jump(instr, state);
@@ -81,34 +81,34 @@ const instruction* op_jumpi(const instruction* instr, execution_state& state) no
8181
return instr;
8282
}
8383

84-
const instruction* op_pc(const instruction* instr, execution_state& state) noexcept
84+
const instruction* op_pc(const instruction* instr, AdvancedExecutionState& state) noexcept
8585
{
8686
state.stack.push(instr->arg.number);
8787
return ++instr;
8888
}
8989

90-
const instruction* op_gas(const instruction* instr, execution_state& state) noexcept
90+
const instruction* op_gas(const instruction* instr, AdvancedExecutionState& state) noexcept
9191
{
9292
const auto correction = state.current_block_cost - instr->arg.number;
9393
const auto gas = static_cast<uint64_t>(state.gas_left + correction);
9494
state.stack.push(gas);
9595
return ++instr;
9696
}
9797

98-
const instruction* op_push_small(const instruction* instr, execution_state& state) noexcept
98+
const instruction* op_push_small(const instruction* instr, AdvancedExecutionState& state) noexcept
9999
{
100100
state.stack.push(instr->arg.small_push_value);
101101
return ++instr;
102102
}
103103

104-
const instruction* op_push_full(const instruction* instr, execution_state& state) noexcept
104+
const instruction* op_push_full(const instruction* instr, AdvancedExecutionState& state) noexcept
105105
{
106106
state.stack.push(*instr->arg.push_value);
107107
return ++instr;
108108
}
109109

110110
template <evmc_opcode LogOp>
111-
const instruction* op_log(const instruction* instr, execution_state& state) noexcept
111+
const instruction* op_log(const instruction* instr, AdvancedExecutionState& state) noexcept
112112
{
113113
constexpr auto num_topics = LogOp - OP_LOG0;
114114
const auto status_code = log(state, num_topics);
@@ -117,13 +117,13 @@ const instruction* op_log(const instruction* instr, execution_state& state) noex
117117
return ++instr;
118118
}
119119

120-
const instruction* op_invalid(const instruction*, execution_state& state) noexcept
120+
const instruction* op_invalid(const instruction*, AdvancedExecutionState& state) noexcept
121121
{
122122
return state.exit(EVMC_INVALID_INSTRUCTION);
123123
}
124124

125125
template <evmc_status_code status_code>
126-
const instruction* op_return(const instruction*, execution_state& state) noexcept
126+
const instruction* op_return(const instruction*, AdvancedExecutionState& state) noexcept
127127
{
128128
const auto offset = state.stack[0];
129129
const auto size = state.stack[1];
@@ -138,7 +138,7 @@ const instruction* op_return(const instruction*, execution_state& state) noexcep
138138
}
139139

140140
template <evmc_call_kind Kind, bool Static = false>
141-
const instruction* op_call(const instruction* instr, execution_state& state) noexcept
141+
const instruction* op_call(const instruction* instr, AdvancedExecutionState& state) noexcept
142142
{
143143
const auto gas_left_correction = state.current_block_cost - instr->arg.number;
144144
state.gas_left += gas_left_correction;
@@ -154,7 +154,7 @@ const instruction* op_call(const instruction* instr, execution_state& state) noe
154154
}
155155

156156
template <evmc_call_kind Kind>
157-
const instruction* op_create(const instruction* instr, execution_state& state) noexcept
157+
const instruction* op_create(const instruction* instr, AdvancedExecutionState& state) noexcept
158158
{
159159
const auto gas_left_correction = state.current_block_cost - instr->arg.number;
160160
state.gas_left += gas_left_correction;
@@ -169,17 +169,17 @@ const instruction* op_create(const instruction* instr, execution_state& state) n
169169
return ++instr;
170170
}
171171

172-
const instruction* op_undefined(const instruction*, execution_state& state) noexcept
172+
const instruction* op_undefined(const instruction*, AdvancedExecutionState& state) noexcept
173173
{
174174
return state.exit(EVMC_UNDEFINED_INSTRUCTION);
175175
}
176176

177-
const instruction* op_selfdestruct(const instruction*, execution_state& state) noexcept
177+
const instruction* op_selfdestruct(const instruction*, AdvancedExecutionState& state) noexcept
178178
{
179179
return state.exit(selfdestruct(state));
180180
}
181181

182-
const instruction* opx_beginblock(const instruction* instr, execution_state& state) noexcept
182+
const instruction* opx_beginblock(const instruction* instr, AdvancedExecutionState& state) noexcept
183183
{
184184
auto& block = instr->arg.block;
185185

test/unittests/execution_state_test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ static_assert(!std::is_copy_constructible<evmone::ExecutionState>::value);
1313
static_assert(!std::is_move_assignable<evmone::ExecutionState>::value);
1414
static_assert(!std::is_copy_assignable<evmone::ExecutionState>::value);
1515

16-
static_assert(std::is_default_constructible<evmone::execution_state>::value);
17-
static_assert(!std::is_move_constructible<evmone::execution_state>::value);
18-
static_assert(!std::is_copy_constructible<evmone::execution_state>::value);
19-
static_assert(!std::is_move_assignable<evmone::execution_state>::value);
20-
static_assert(!std::is_copy_assignable<evmone::execution_state>::value);
16+
static_assert(std::is_default_constructible<evmone::AdvancedExecutionState>::value);
17+
static_assert(!std::is_move_constructible<evmone::AdvancedExecutionState>::value);
18+
static_assert(!std::is_copy_constructible<evmone::AdvancedExecutionState>::value);
19+
static_assert(!std::is_move_assignable<evmone::AdvancedExecutionState>::value);
20+
static_assert(!std::is_copy_assignable<evmone::AdvancedExecutionState>::value);
2121

2222
TEST(execution_state, construct)
2323
{
@@ -60,7 +60,7 @@ TEST(execution_state, default_construct)
6060

6161
TEST(execution_state, default_construct_advanced)
6262
{
63-
const evmone::execution_state st;
63+
const evmone::AdvancedExecutionState st;
6464

6565
EXPECT_EQ(st.gas_left, 0);
6666
EXPECT_EQ(st.stack.size(), 0);
@@ -82,9 +82,9 @@ TEST(execution_state, reset_advanced)
8282
{
8383
const evmc_message msg{};
8484
const uint8_t code[]{0xff};
85-
evmone::code_analysis analysis;
85+
evmone::AdvancedCodeAnalysis analysis;
8686

87-
evmone::execution_state st;
87+
evmone::AdvancedExecutionState st;
8888
st.gas_left = 1;
8989
st.stack.push({});
9090
st.memory.resize(2);
@@ -117,7 +117,7 @@ TEST(execution_state, reset_advanced)
117117
msg2.gas = 13;
118118
const evmc_host_interface host_interface2{};
119119
const uint8_t code2[]{0x80, 0x81};
120-
evmone::code_analysis analysis2;
120+
evmone::AdvancedCodeAnalysis analysis2;
121121

122122
st.reset(
123123
msg2, EVMC_HOMESTEAD, host_interface2, nullptr, code2, std::size(code2), analysis2);

test/utils/dump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <iomanip>
1010
#include <iostream>
1111

12-
void dump(const evmone::code_analysis& analysis)
12+
void dump(const evmone::AdvancedCodeAnalysis& analysis)
1313
{
1414
using namespace evmone;
1515

test/utils/dump.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
#include <evmone/analysis.hpp>
77

8-
void dump(const evmone::code_analysis& analysis);
8+
void dump(const evmone::AdvancedCodeAnalysis& analysis);

0 commit comments

Comments
 (0)