Skip to content

Commit 9a65e7e

Browse files
committed
iiiiiiiiiiiiiiiiiii
1 parent ca00490 commit 9a65e7e

File tree

7 files changed

+39
-31
lines changed

7 files changed

+39
-31
lines changed

libevmasm/Assembly.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ string Assembly::toStringInHex(u256 _value)
229229
return hexStr.str();
230230
}
231231

232-
AssemblyItem Assembly::assemblyItemFromJSON(Json::Value const& _json, Assembly& _assembly)
232+
AssemblyItem Assembly::loadItemFromJSON(Json::Value const& _json, Assembly& _assembly)
233233
{
234234
std::string name = _json["name"].isString() ? _json["name"].asString() : "";
235235
int begin = _json["begin"].isInt() ? _json["begin"].asInt() : -1;
@@ -261,12 +261,12 @@ AssemblyItem Assembly::assemblyItemFromJSON(Json::Value const& _json, Assembly&
261261
SourceLocation location;
262262
location.start = begin;
263263
location.end = end;
264-
location.source = source;
264+
location.sourceIndex = source;
265265
if (c_instructions.find(name) != c_instructions.end())
266266
{
267267
AssemblyItem item{c_instructions.at(name), location};
268268
if (!value.empty())
269-
item.setJumpTypeFromString(value);
269+
item.setJumpType(value);
270270
return item;
271271
}
272272
else
@@ -278,7 +278,7 @@ AssemblyItem Assembly::assemblyItemFromJSON(Json::Value const& _json, Assembly&
278278
data = u256("0x" + value);
279279
AssemblyItem item{AssemblyItemType::Push, data, location};
280280
if (!jumpType.empty())
281-
item.setJumpTypeFromString(jumpType);
281+
item.setJumpType(jumpType);
282282
return item;
283283
}
284284
else if (name == "PUSH tag")
@@ -452,8 +452,8 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
452452
for (AssemblyItem const& i: m_items)
453453
{
454454
int sourceIndex = -1;
455-
if (i.location().source.has_value())
456-
sourceIndex = i.location().source.value();
455+
if (i.location().sourceIndex.has_value())
456+
sourceIndex = i.location().sourceIndex.value();
457457
else if (i.location().sourceName)
458458
{
459459
auto iter = _sourceIndices.find(*i.location().sourceName);
@@ -486,20 +486,23 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
486486
return root;
487487
}
488488

489-
void Assembly::forEachJSONAssemblyItem(Json::Value const& _code, Assembly& _assembly)
489+
void Assembly::addAssemblyItemsFromJSON(Json::Value const& _code, Assembly& _assembly)
490490
{
491491
solAssert(_code.isArray(), "");
492492
for (auto it = _code.begin(); it != _code.end(); ++it)
493493
{
494-
AssemblyItem current = assemblyItemFromJSON(*it, _assembly);
494+
AssemblyItem current = loadItemFromJSON(*it, _assembly);
495495
_assembly.m_items.emplace_back(current);
496496

497497
auto nextIt = std::next(it);
498498
if (nextIt != _code.end())
499499
{
500-
AssemblyItem next = assemblyItemFromJSON(*nextIt, _assembly);
501-
if (current.type() == AssemblyItemType::Tag &&
502-
next.type() == AssemblyItemType::Operation && next.instruction() == Instruction::JUMPDEST)
500+
AssemblyItem next = loadItemFromJSON(*nextIt, _assembly);
501+
if (
502+
current.type() == AssemblyItemType::Tag &&
503+
next.type() == AssemblyItemType::Operation &&
504+
next.instruction() == Instruction::JUMPDEST
505+
)
503506
++it;
504507
}
505508
}
@@ -508,7 +511,7 @@ void Assembly::forEachJSONAssemblyItem(Json::Value const& _code, Assembly& _asse
508511
bool Assembly::loadFromAssemblyJSON(Json::Value const& _json, Assembly& _assembly)
509512
{
510513
solAssert(_json[".code"].isArray(), "");
511-
forEachJSONAssemblyItem(_json[".code"], _assembly);
514+
addAssemblyItemsFromJSON(_json[".code"], _assembly);
512515
if (_json[".auxdata"].isString())
513516
{
514517
_assembly.m_auxiliaryData = fromHex(_json[".auxdata"].asString());

libevmasm/Assembly.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ class Assembly
171171

172172
unsigned bytesRequired(unsigned subTagSize) const;
173173

174-
static AssemblyItem assemblyItemFromJSON(Json::Value const& _json, Assembly& _assembly);
175-
static void forEachJSONAssemblyItem(Json::Value const& _code, Assembly& _assembly);
174+
static AssemblyItem loadItemFromJSON(Json::Value const& _json, Assembly& _assembly);
176175
std::vector<Json::Value> assemblyItemAsJSON(AssemblyItem const& _item, int _sourceIndex) const;
177176

178177
private:
178+
static void addAssemblyItemsFromJSON(Json::Value const& _code, Assembly& _assembly);
179179
static Json::Value createJsonValue(
180180
std::string _name,
181181
int _source,

libevmasm/AssemblyItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ string AssemblyItem::getJumpTypeAsString() const
179179
}
180180
}
181181

182-
void AssemblyItem::setJumpTypeFromString(std::string const& _jumpType)
182+
void AssemblyItem::setJumpType(std::string const& _jumpType)
183183
{
184184
if (_jumpType == "[in]")
185185
m_jumpType = JumpType::IntoFunction;

libevmasm/AssemblyItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class AssemblyItem
160160
langutil::SourceLocation const& location() const { return m_location; }
161161

162162
void setJumpType(JumpType _jumpType) { m_jumpType = _jumpType; }
163-
void setJumpTypeFromString(std::string const& _jumpType);
163+
void setJumpType(std::string const& _jumpType);
164164
JumpType getJumpType() const { return m_jumpType; }
165165
std::string getJumpTypeAsString() const;
166166

liblangutil/SourceLocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct SourceLocation
103103
int start = -1;
104104
int end = -1;
105105
std::shared_ptr<std::string const> sourceName;
106-
std::optional<int> source = std::nullopt;
106+
std::optional<int> sourceIndex = std::nullopt;
107107
};
108108

109109
SourceLocation parseSourceLocation(

scripts/AsmJsonImportTest.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -eo pipefail
44

55
# Bash script to test the asm-json-import input mode of the compiler by
66
# first exporting a .sol file to JSON that containing assembly json and corresponding bytecode,
@@ -46,17 +46,17 @@ function testImportExportEquivalence {
4646
then
4747
# save exported json as expected result (silently)
4848
$SOLC --combined-json asm,bin,compact-format --pretty-json "$nth_input_file" "${all_input_files[@]}" > expected.json 2> /dev/null
49-
for contract in $(jq '.contracts | keys' expected.json | jq '.[]' 2> /dev/null)
49+
for contract in $(jq '.contracts | keys | .[]' expected.json 2> /dev/null)
5050
do
5151
jq ".contracts.${contract}.asm" expected.json > asm.json 2> /dev/null
52-
jq ".contracts.${contract}.bin" expected.json | jq --raw-output '.' > expected.bin 2> /dev/null
52+
jq --raw-output ".contracts.${contract}.bin" expected.json > expected.bin 2> /dev/null
5353
expected_bin=$(cat expected.bin)
54-
if [ -z "$expected_bin" ]
54+
if [[ $expected_bin == "" ]]
5555
then
5656
continue
5757
fi
5858

59-
if ! $SOLC --import-asm-json asm.json --bin > obtained.bin 2> /dev/null
59+
if ! "$SOLC" --import-asm-json asm.json --bin > obtained.bin 2> /dev/null
6060
then
6161
# For investigating, use exit 1 here so the script stops at the
6262
# first failing test

solc/CommandLineInterface.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,10 @@ void CommandLineInterface::handleAst()
839839

840840
bool CommandLineInterface::actOnInput()
841841
{
842-
if (m_options.input.mode == InputMode::StandardJson ||
843-
m_options.input.mode == InputMode::Assembler)
842+
if (
843+
m_options.input.mode == InputMode::StandardJson ||
844+
m_options.input.mode == InputMode::Assembler
845+
)
844846
// Already done in "processInput" phase.
845847
return true;
846848
else if (m_options.input.mode == InputMode::Linker)
@@ -1105,8 +1107,9 @@ bool CommandLineInterface::assembleFromAssemblyJson()
11051107

11061108
Json::Value assemblyJson;
11071109
m_assembly = make_unique<evmasm::Assembly>();
1108-
return util::jsonParseStrict(m_fileReader.sourceCodes().begin()->second, assemblyJson) &&
1109-
m_assembly->loadFromAssemblyJSON(assemblyJson, *m_assembly);
1110+
return
1111+
util::jsonParseStrict(m_fileReader.sourceCodes().begin()->second, assemblyJson) &&
1112+
m_assembly->loadFromAssemblyJSON(assemblyJson, *m_assembly);
11101113
}
11111114

11121115
void CommandLineInterface::outputCompilationResults()
@@ -1130,12 +1133,13 @@ void CommandLineInterface::outputCompilationResults()
11301133
sout() << m_assembly->assemblyString() << endl;
11311134
}
11321135
}
1133-
1134-
if (m_compiler)
1136+
else if (m_compiler)
11351137
{
11361138
solAssert(m_assembly == nullptr, "");
1137-
if (!m_compiler->compilationSuccessful()
1138-
&& m_options.output.stopAfter == CompilerStack::State::CompilationSuccessful)
1139+
if (
1140+
!m_compiler->compilationSuccessful() &&
1141+
m_options.output.stopAfter == CompilerStack::State::CompilationSuccessful
1142+
)
11391143
{
11401144
serr() << endl << "Compilation halted after AST generation due to errors." << endl;
11411145
return;
@@ -1161,7 +1165,8 @@ void CommandLineInterface::outputCompilationResults()
11611165
createFile(
11621166
m_compiler->filesystemFriendlyName(contract)
11631167
+ (m_options.compiler.outputs.asmJson ? "_evm.json" : ".evm"),
1164-
ret);
1168+
ret
1169+
);
11651170
}
11661171
else
11671172
{

0 commit comments

Comments
 (0)