Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 7dd24d3

Browse files
committed
Move trace() call to common place (NEXT / CONTINUE / BREAK macros) instead of repeating it in every opcode implementation.
1 parent df1517f commit 7dd24d3

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

libaleth-interpreter/VM.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace dev
124124
{
125125
namespace eth
126126
{
127-
void VM::trace() noexcept
127+
void VM::trace(uint64_t _pc) noexcept
128128
{
129129
if (m_traceCallback)
130130
{
@@ -136,7 +136,7 @@ void VM::trace() noexcept
136136
topStackItem = toEvmC(m_SPP[0]);
137137
pushedStackItem = &topStackItem;
138138
}
139-
m_traceCallback(m_traceContext, m_PC, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP,
139+
m_traceCallback(m_traceContext, _pc, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP,
140140
pushedStackItem, m_mem.size(), 0, 0, nullptr);
141141
}
142142
}
@@ -437,7 +437,6 @@ void VM::interpretCases()
437437
updateIOGas();
438438

439439
m_SPP[0] = (u256)*(h256 const*)(m_mem.data() + (unsigned)m_SP[0]);
440-
trace();
441440
}
442441
NEXT
443442

@@ -448,7 +447,6 @@ void VM::interpretCases()
448447
updateIOGas();
449448

450449
*(h256*)&m_mem[(unsigned)m_SP[0]] = (h256)m_SP[1];
451-
trace();
452450
}
453451
NEXT
454452

@@ -1197,14 +1195,11 @@ void VM::interpretCases()
11971195
// get val at two-byte offset into const pool and advance pc by one-byte remainder
11981196
TRACE_OP(2, m_PC, m_OP);
11991197
unsigned off;
1200-
uint64_t pc = m_PC;
1201-
++pc;
1202-
off = m_code[pc++] << 8;
1203-
off |= m_code[pc++];
1204-
pc += m_code[pc];
1198+
++m_PC;
1199+
off = m_code[m_PC++] << 8;
1200+
off |= m_code[m_PC++];
1201+
m_PC += m_code[m_PC];
12051202
m_SPP[0] = m_pool[off];
1206-
trace();
1207-
m_PC = pc;
12081203
TRACE_VAL(2, "Retrieved pooled const", m_SPP[0]);
12091204
#else
12101205
throwBadInstruction();
@@ -1217,7 +1212,6 @@ void VM::interpretCases()
12171212
ON_OP();
12181213
updateIOGas();
12191214
m_SPP[0] = m_code[m_PC + 1];
1220-
trace();
12211215
m_PC += 2;
12221216
}
12231217
CONTINUE
@@ -1266,7 +1260,6 @@ void VM::interpretCases()
12661260
for (; numBytes--; ++codeOffset)
12671261
m_SPP[0] = (m_SPP[0] << 8) | m_code[codeOffset];
12681262

1269-
trace();
12701263
m_PC = codeOffset;
12711264
}
12721265
CONTINUE
@@ -1396,7 +1389,6 @@ void VM::interpretCases()
13961389

13971390
updateSSGas();
13981391
updateIOGas();
1399-
trace();
14001392

14011393
evmc_uint256be key = toEvmC(m_SP[0]);
14021394
evmc_uint256be value = toEvmC(m_SP[1]);

libaleth-interpreter/VM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class VM
117117

118118
evmc_trace_callback m_traceCallback = nullptr;
119119
evmc_tracer_context* m_traceContext = nullptr;
120-
void trace() noexcept;
120+
void trace(uint64_t _pc) noexcept;
121121

122122
// initialize interpreter
123123
void initEntry();

libaleth-interpreter/VMConfig.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,24 @@ namespace eth
124124
#if EVM_SWITCH_DISPATCH
125125

126126
#define INIT_CASES
127-
#define DO_CASES \
128-
for (;;) \
129-
{ \
130-
fetchInstruction(); \
131-
switch (m_OP) \
127+
#define DO_CASES \
128+
for (;;) \
129+
{ \
130+
fetchInstruction(); \
131+
auto startPC = m_PC; \
132+
switch (m_OP) \
132133
{
133134
#define CASE(name) case Instruction::name:
134-
#define NEXT \
135-
++m_PC; \
135+
#define NEXT \
136+
trace(startPC); \
137+
++m_PC; \
136138
break;
137-
#define CONTINUE continue;
138-
#define BREAK return;
139+
#define CONTINUE \
140+
trace(startPC); \
141+
continue;
142+
#define BREAK \
143+
trace(startPC); \
144+
return;
139145
#define DEFAULT default:
140146
#define WHILE_CASES \
141147
} \
@@ -410,19 +416,24 @@ namespace eth
410416
&&SUICIDE, \
411417
};
412418

413-
#define DO_CASES \
414-
fetchInstruction(); \
419+
#define DO_CASES \
420+
fetchInstruction(); \
421+
auto startPC = m_PC; \
415422
goto* jumpTable[(int)m_OP];
416423
#define CASE(name) \
417424
name:
418425
#define NEXT \
426+
trace(startPC); \
419427
++m_PC; \
420428
fetchInstruction(); \
421429
goto* jumpTable[(int)m_OP];
422430
#define CONTINUE \
431+
trace(startPC); \
423432
fetchInstruction(); \
424433
goto* jumpTable[(int)m_OP];
425-
#define BREAK return;
434+
#define BREAK \
435+
trace(startPC); \
436+
return;
426437
#define DEFAULT
427438
#define WHILE_CASES
428439

0 commit comments

Comments
 (0)