/src/solidity/libevmasm/EthdebugSchema.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | This file is part of solidity. |
3 | | |
4 | | solidity is free software: you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License as published by |
6 | | the Free Software Foundation, either version 3 of the License, or |
7 | | (at your option) any later version. |
8 | | |
9 | | solidity is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU General Public License |
15 | | along with solidity. If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | // SPDX-License-Identifier: GPL-3.0 |
18 | | |
19 | | #include <libevmasm/EthdebugSchema.h> |
20 | | |
21 | | #include <libsolutil/Numeric.h> |
22 | | #include <libsolutil/Visitor.h> |
23 | | |
24 | | using namespace solidity; |
25 | | using namespace solidity::evmasm::ethdebug; |
26 | | |
27 | | void schema::data::to_json(Json& _json, HexValue const& _hexValue) |
28 | 1.29M | { |
29 | 1.29M | _json = util::toHex(_hexValue.value, util::HexPrefix::Add); |
30 | 1.29M | } |
31 | | |
32 | | void schema::data::to_json(Json& _json, Unsigned const& _unsigned) |
33 | 10.7M | { |
34 | 10.7M | std::visit(util::GenericVisitor{ |
35 | 10.7M | [&](HexValue const& _hexValue) { _json = _hexValue; }, |
36 | 10.7M | [&](std::uint64_t const _value) { _json = _value; } |
37 | 10.7M | }, _unsigned.value); |
38 | 10.7M | } |
39 | | |
40 | | void schema::materials::to_json(Json& _json, ID const& _id) |
41 | 2.93M | { |
42 | 2.93M | std::visit(util::GenericVisitor{ |
43 | 2.93M | [&](std::string const& _hexValue) { _json = _hexValue; }, |
44 | 2.93M | [&](std::uint64_t const _value) { _json = _value; } |
45 | 2.93M | }, _id.value); |
46 | 2.93M | } |
47 | | |
48 | | void schema::materials::to_json(Json& _json, Reference const& _source) |
49 | 2.93M | { |
50 | 2.93M | _json["id"] = _source.id; |
51 | 2.93M | if (_source.type) |
52 | 0 | _json["type"] = *_source.type == Reference::Type::Compilation ? "compilation" : "source"; |
53 | 2.93M | } |
54 | | |
55 | | void schema::materials::to_json(Json& _json, SourceRange::Range const& _range) |
56 | 2.90M | { |
57 | 2.90M | _json["length"] = _range.length; |
58 | 2.90M | _json["offset"] = _range.offset; |
59 | 2.90M | } |
60 | | |
61 | | |
62 | | void schema::materials::to_json(Json& _json, SourceRange const& _sourceRange) |
63 | 2.93M | { |
64 | 2.93M | _json["source"] = _sourceRange.source; |
65 | 2.93M | if (_sourceRange.range) |
66 | 2.90M | _json["range"] = *_sourceRange.range; |
67 | 2.93M | } |
68 | | |
69 | | void schema::to_json(Json& _json, Program::Contract const& _contract) |
70 | 32.6k | { |
71 | 32.6k | if (_contract.name) |
72 | 32.6k | _json["name"] = *_contract.name; |
73 | 32.6k | _json["definition"] = _contract.definition; |
74 | 32.6k | } |
75 | | |
76 | | void schema::program::to_json(Json& _json, Context::Variable const& _contextVariable) |
77 | 0 | { |
78 | 0 | auto const numProperties = |
79 | 0 | _contextVariable.identifier.has_value() + |
80 | 0 | _contextVariable.declaration.has_value(); |
81 | 0 | solRequire(numProperties >= 1, EthdebugException, "Context variable has no properties."); |
82 | 0 | if (_contextVariable.identifier) |
83 | 0 | { |
84 | 0 | solRequire(!_contextVariable.identifier->empty(), EthdebugException, "Variable identifier must not be empty."); |
85 | 0 | _json["identifier"] = *_contextVariable.identifier; |
86 | 0 | } |
87 | 0 | if (_contextVariable.declaration) |
88 | 0 | _json["declaration"] = *_contextVariable.declaration; |
89 | 0 | } |
90 | | |
91 | | void schema::program::to_json(Json& _json, Context const& _context) |
92 | 2.90M | { |
93 | 2.90M | solRequire(_context.code.has_value() + _context.remark.has_value() + _context.variables.has_value() >= 1, EthdebugException, "Context needs >=1 properties."); |
94 | 2.90M | if (_context.code) |
95 | 2.90M | _json["code"] = *_context.code; |
96 | 2.90M | if (_context.variables) |
97 | 0 | { |
98 | 0 | solRequire(!_context.variables->empty(), EthdebugException, "Context variables must not be empty if provided."); |
99 | 0 | _json["variables"] = *_context.variables; |
100 | 0 | } |
101 | 2.90M | if (_context.remark) |
102 | 0 | _json["remark"] = *_context.remark; |
103 | 2.90M | } |
104 | | |
105 | | void schema::program::to_json(Json& _json, Instruction::Operation const& _operation) |
106 | 3.64M | { |
107 | 3.64M | _json = { {"mnemonic", _operation.mnemonic} }; |
108 | 3.64M | if (!_operation.arguments.empty()) |
109 | 1.29M | _json["arguments"] = _operation.arguments; |
110 | 3.64M | } |
111 | | |
112 | | void schema::program::to_json(Json& _json, Instruction const& _instruction) |
113 | 3.64M | { |
114 | 3.64M | _json["offset"] = _instruction.offset; |
115 | 3.64M | if (_instruction.operation) |
116 | 3.64M | _json["operation"] = *_instruction.operation; |
117 | 3.64M | if (_instruction.context) |
118 | 2.90M | _json["context"] = *_instruction.context; |
119 | 3.64M | } |
120 | | |
121 | | void schema::to_json(Json& _json, Program const& _program) |
122 | 32.6k | { |
123 | 32.6k | if (_program.compilation) |
124 | 0 | _json["compilation"] = *_program.compilation; |
125 | 32.6k | _json["contract"] = _program.contract; |
126 | 32.6k | _json["environment"] = _program.environment; |
127 | 32.6k | if (_program.context) |
128 | 0 | _json["context"] = *_program.context; |
129 | 32.6k | _json["instructions"] = _program.instructions; |
130 | 32.6k | } |
131 | | |
132 | | void schema::to_json(Json& _json, Program::Environment const& _environment) |
133 | 32.6k | { |
134 | 32.6k | switch (_environment) |
135 | 32.6k | { |
136 | 0 | case Program::Environment::CALL: |
137 | 0 | _json = "call"; |
138 | 0 | break; |
139 | 32.6k | case Program::Environment::CREATE: |
140 | 32.6k | _json = "create"; |
141 | 32.6k | break; |
142 | 32.6k | } |
143 | 32.6k | } |