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

Commit

Permalink
Move trace() call to common place (NEXT / CONTINUE / BREAK macros) in…
Browse files Browse the repository at this point in the history
…stead of repeating it in every opcode implementation.
  • Loading branch information
gumb0 committed Aug 7, 2018
1 parent df1517f commit 7dd24d3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
20 changes: 6 additions & 14 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace dev
{
namespace eth
{
void VM::trace() noexcept
void VM::trace(uint64_t _pc) noexcept
{
if (m_traceCallback)
{
Expand All @@ -136,7 +136,7 @@ void VM::trace() noexcept
topStackItem = toEvmC(m_SPP[0]);
pushedStackItem = &topStackItem;
}
m_traceCallback(m_traceContext, m_PC, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP,
m_traceCallback(m_traceContext, _pc, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP,
pushedStackItem, m_mem.size(), 0, 0, nullptr);
}
}
Expand Down Expand Up @@ -437,7 +437,6 @@ void VM::interpretCases()
updateIOGas();

m_SPP[0] = (u256)*(h256 const*)(m_mem.data() + (unsigned)m_SP[0]);
trace();
}
NEXT

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

*(h256*)&m_mem[(unsigned)m_SP[0]] = (h256)m_SP[1];
trace();
}
NEXT

Expand Down Expand Up @@ -1197,14 +1195,11 @@ void VM::interpretCases()
// get val at two-byte offset into const pool and advance pc by one-byte remainder
TRACE_OP(2, m_PC, m_OP);
unsigned off;
uint64_t pc = m_PC;
++pc;
off = m_code[pc++] << 8;
off |= m_code[pc++];
pc += m_code[pc];
++m_PC;
off = m_code[m_PC++] << 8;
off |= m_code[m_PC++];
m_PC += m_code[m_PC];
m_SPP[0] = m_pool[off];
trace();
m_PC = pc;
TRACE_VAL(2, "Retrieved pooled const", m_SPP[0]);
#else
throwBadInstruction();
Expand All @@ -1217,7 +1212,6 @@ void VM::interpretCases()
ON_OP();
updateIOGas();
m_SPP[0] = m_code[m_PC + 1];
trace();
m_PC += 2;
}
CONTINUE
Expand Down Expand Up @@ -1266,7 +1260,6 @@ void VM::interpretCases()
for (; numBytes--; ++codeOffset)
m_SPP[0] = (m_SPP[0] << 8) | m_code[codeOffset];

trace();
m_PC = codeOffset;
}
CONTINUE
Expand Down Expand Up @@ -1396,7 +1389,6 @@ void VM::interpretCases()

updateSSGas();
updateIOGas();
trace();

evmc_uint256be key = toEvmC(m_SP[0]);
evmc_uint256be value = toEvmC(m_SP[1]);
Expand Down
2 changes: 1 addition & 1 deletion libaleth-interpreter/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VM

evmc_trace_callback m_traceCallback = nullptr;
evmc_tracer_context* m_traceContext = nullptr;
void trace() noexcept;
void trace(uint64_t _pc) noexcept;

// initialize interpreter
void initEntry();
Expand Down
35 changes: 23 additions & 12 deletions libaleth-interpreter/VMConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,24 @@ namespace eth
#if EVM_SWITCH_DISPATCH

#define INIT_CASES
#define DO_CASES \
for (;;) \
{ \
fetchInstruction(); \
switch (m_OP) \
#define DO_CASES \
for (;;) \
{ \
fetchInstruction(); \
auto startPC = m_PC; \
switch (m_OP) \
{
#define CASE(name) case Instruction::name:
#define NEXT \
++m_PC; \
#define NEXT \
trace(startPC); \
++m_PC; \
break;
#define CONTINUE continue;
#define BREAK return;
#define CONTINUE \
trace(startPC); \
continue;
#define BREAK \
trace(startPC); \
return;
#define DEFAULT default:
#define WHILE_CASES \
} \
Expand Down Expand Up @@ -410,19 +416,24 @@ namespace eth
&&SUICIDE, \
};

#define DO_CASES \
fetchInstruction(); \
#define DO_CASES \
fetchInstruction(); \
auto startPC = m_PC; \
goto* jumpTable[(int)m_OP];
#define CASE(name) \
name:
#define NEXT \
trace(startPC); \
++m_PC; \
fetchInstruction(); \
goto* jumpTable[(int)m_OP];
#define CONTINUE \
trace(startPC); \
fetchInstruction(); \
goto* jumpTable[(int)m_OP];
#define BREAK return;
#define BREAK \
trace(startPC); \
return;
#define DEFAULT
#define WHILE_CASES

Expand Down

0 comments on commit 7dd24d3

Please sign in to comment.