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

Commit 917d4b5

Browse files
gumb0chfast
authored andcommitted
Move trace() call to common place (NEXT / CONTINUE / BREAK macros) instead of repeating it in every opcode implementation.
1 parent 8169302 commit 917d4b5

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
@@ -149,7 +149,7 @@ namespace dev
149149
{
150150
namespace eth
151151
{
152-
void VM::trace() noexcept
152+
void VM::trace(uint64_t _pc) noexcept
153153
{
154154
if (m_traceCallback)
155155
{
@@ -161,7 +161,7 @@ void VM::trace() noexcept
161161
topStackItem = toEvmC(m_SPP[0]);
162162
pushedStackItem = &topStackItem;
163163
}
164-
m_traceCallback(m_traceContext, m_PC, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP,
164+
m_traceCallback(m_traceContext, _pc, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP,
165165
pushedStackItem, m_mem.size(), 0, 0, nullptr);
166166
}
167167
}
@@ -449,7 +449,6 @@ void VM::interpretCases()
449449
updateIOGas();
450450

451451
m_SPP[0] = (u256)*(h256 const*)(m_mem.data() + (unsigned)m_SP[0]);
452-
trace();
453452
}
454453
NEXT
455454

@@ -460,7 +459,6 @@ void VM::interpretCases()
460459
updateIOGas();
461460

462461
*(h256*)&m_mem[(unsigned)m_SP[0]] = (h256)m_SP[1];
463-
trace();
464462
}
465463
NEXT
466464

@@ -1202,14 +1200,11 @@ void VM::interpretCases()
12021200
// get val at two-byte offset into const pool and advance pc by one-byte remainder
12031201
TRACE_OP(2, m_PC, m_OP);
12041202
unsigned off;
1205-
uint64_t pc = m_PC;
1206-
++pc;
1207-
off = m_code[pc++] << 8;
1208-
off |= m_code[pc++];
1209-
pc += m_code[pc];
1203+
++m_PC;
1204+
off = m_code[m_PC++] << 8;
1205+
off |= m_code[m_PC++];
1206+
m_PC += m_code[m_PC];
12101207
m_SPP[0] = m_pool[off];
1211-
trace();
1212-
m_PC = pc;
12131208
TRACE_VAL(2, "Retrieved pooled const", m_SPP[0]);
12141209
#else
12151210
throwBadInstruction();
@@ -1222,7 +1217,6 @@ void VM::interpretCases()
12221217
ON_OP();
12231218
updateIOGas();
12241219
m_SPP[0] = m_code[m_PC + 1];
1225-
trace();
12261220
m_PC += 2;
12271221
}
12281222
CONTINUE
@@ -1271,7 +1265,6 @@ void VM::interpretCases()
12711265
for (; numBytes--; ++codeOffset)
12721266
m_SPP[0] = (m_SPP[0] << 8) | m_code[codeOffset];
12731267

1274-
trace();
12751268
m_PC = codeOffset;
12761269
}
12771270
CONTINUE
@@ -1417,7 +1410,6 @@ void VM::interpretCases()
14171410
}
14181411

14191412
updateIOGas();
1420-
trace();
14211413
}
14221414
NEXT
14231415

libaleth-interpreter/VM.h

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

119119
evmc_trace_callback m_traceCallback = nullptr;
120120
evmc_tracer_context* m_traceContext = nullptr;
121-
void trace() noexcept;
121+
void trace(uint64_t _pc) noexcept;
122122

123123
// initialize interpreter
124124
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)