-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathdump.cpp
63 lines (50 loc) · 1.92 KB
/
dump.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2018-2019 The evmone Authors.
// Licensed under the Apache License, Version 2.0.
#include <test/utils/utils.hpp>
#include <evmc/instructions.h>
#include <evmone/analysis.hpp>
#include <iomanip>
#include <iostream>
void dump_analysis(const evmone::code_analysis& analysis)
{
using namespace evmone;
auto names = evmc_get_instruction_names_table(EVMC_BYZANTIUM);
auto metrics = evmc_get_instruction_metrics_table(EVMC_BYZANTIUM);
const block_info* block = nullptr;
for (size_t i = 0; i < analysis.instrs.size(); ++i)
{
auto& instr = analysis.instrs[i];
auto c = static_cast<uint8_t>((size_t)instr.fn);
auto name = names[c];
if (!name)
name = "XX";
if (c == OPX_BEGINBLOCK)
{
block = &analysis.blocks[size_t(instr.arg.p.number)];
auto get_jumpdest_offset = [&analysis](size_t index) noexcept
{
// TODO: Replace with lower_bound().
for (const auto& d : analysis.jumpdest_map)
{
if (d.second == static_cast<int>(index))
return d.first;
}
return -1;
};
std::cout << "┌ ";
auto offset = get_jumpdest_offset(i);
if (offset >= 0)
std::cout << std::setw(2) << offset;
else
std::cout << " ";
std::cout << " " << std::setw(10) << block->gas_cost << " " << block->stack_req << " "
<< block->stack_max << " " << block->stack_diff << "\n";
}
std::cout << "│ " << std::setw(9) << std::left << name << std::setw(4) << std::right
<< metrics[c].gas_cost;
if (c >= OP_PUSH1 && c <= OP_PUSH32)
std::cout << '\t' << to_hex({instr.arg.data, 32});
std::cout << '\n';
}
}