Skip to content

Commit 4849556

Browse files
committed
eof: objectCompiler tests updating
1 parent 864652b commit 4849556

40 files changed

+330
-75
lines changed

test/libyul/ObjectCompilerTest.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <liblangutil/DebugInfoSelection.h>
3333

3434
#include <boost/algorithm/string.hpp>
35+
#include <boost/algorithm/string/split.hpp>
3536

3637
#include <ostream>
3738

@@ -78,18 +79,34 @@ TestCase::TestResult ObjectCompilerTest::run(std::ostream& _stream, std::string
7879
solAssert(obj.bytecode);
7980
solAssert(obj.sourceMappings);
8081

81-
m_obtainedResult = "Assembly:\n" + obj.assembly->assemblyString(yulStack.debugInfoSelection());
82+
constexpr std::array allowedOutputs = {"Assembly", "Bytecode", "Opcodes", "SourceMappings"};
83+
auto const outputSetting = m_reader.stringSetting("output", "Assembly,Bytecode,Opcodes,SourceMappings");
84+
std::vector<std::string> outputs;
85+
boost::split(outputs, outputSetting, boost::is_any_of(","));
86+
for (auto const& output: outputs)
87+
if (std::find(allowedOutputs.begin(), allowedOutputs.end(), output) == allowedOutputs.end())
88+
BOOST_THROW_EXCEPTION(std::runtime_error{"Invalid output type: \"" + output + "\""});
89+
90+
if (std::find(outputs.begin(), outputs.end(), "Assembly") != outputs.end())
91+
m_obtainedResult = "Assembly:\n" + obj.assembly->assemblyString(yulStack.debugInfoSelection());
8292
if (obj.bytecode->bytecode.empty())
8393
m_obtainedResult += "-- empty bytecode --\n";
8494
else
85-
m_obtainedResult +=
86-
"Bytecode: " +
87-
util::toHex(obj.bytecode->bytecode) +
88-
"\nOpcodes: " +
89-
boost::trim_copy(evmasm::disassemble(obj.bytecode->bytecode, solidity::test::CommonOptions::get().evmVersion())) +
90-
"\nSourceMappings:" +
91-
(obj.sourceMappings->empty() ? "" : " " + *obj.sourceMappings) +
92-
"\n";
95+
{
96+
if (std::find(outputs.begin(), outputs.end(), "Bytecode") != outputs.end())
97+
m_obtainedResult += "Bytecode: " + util::toHex(obj.bytecode->bytecode);
98+
if (std::find(outputs.begin(), outputs.end(), "Opcodes") != outputs.end())
99+
{
100+
m_obtainedResult += (!m_obtainedResult.empty() && m_obtainedResult.back() != '\n') ? "\n" : "";
101+
m_obtainedResult += "Opcodes: " +
102+
boost::trim_copy(evmasm::disassemble(obj.bytecode->bytecode, solidity::test::CommonOptions::get().evmVersion()));
103+
}
104+
if (std::find(outputs.begin(), outputs.end(), "SourceMappings") != outputs.end())
105+
{
106+
m_obtainedResult += (!m_obtainedResult.empty() && m_obtainedResult.back() != '\n') ? "\n" : "";
107+
m_obtainedResult += "SourceMappings:" + (obj.sourceMappings->empty() ? "" : " " + *obj.sourceMappings) + "\n";
108+
}
109+
}
93110

94111
return checkResult(_stream, _linePrefix, _formatted);
95112
}

test/libyul/objectCompiler/data.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
object "a" {
22
code {}
33
// Unreferenced data is not added to the assembled bytecode.
4+
// TODO: This is not implemented for EOF. Should work for legacy and EOF when implemented.
45
data "str" "Hello, World!"
56
}
67
// ====
78
// EVMVersion: >=constantinople
9+
// bytecodeFormat: legacy
810
// ----
911
// Assembly:
1012
// /* "source":22:29 */

test/libyul/objectCompiler/datacopy.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ object "a" {
1313
}
1414
// ====
1515
// EVMVersion: >=shanghai
16+
// bytecodeFormat: legacy
1617
// ----
1718
// Assembly:
1819
// /* "source":77:92 */

test/libyul/objectCompiler/dataoffset_code.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ object "a" {
77
}
88
// ====
99
// EVMVersion: >=shanghai
10+
// bytecodeFormat: legacy
1011
// ----
1112
// Assembly:
1213
// /* "source":44:61 */

test/libyul/objectCompiler/dataoffset_data.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ object "a" {
44
}
55
// ====
66
// EVMVersion: >=shanghai
7+
// bytecodeFormat: legacy
78
// ----
89
// Assembly:
910
// /* "source":56:75 */

test/libyul/objectCompiler/dataoffset_self.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ object "a" {
44
}
55
// ====
66
// EVMVersion: >=shanghai
7+
// bytecodeFormat: legacy
78
// ----
89
// Assembly:
910
// /* "source":44:59 */

test/libyul/objectCompiler/datasize_code.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ object "a" {
77
}
88
// ====
99
// EVMVersion: >=shanghai
10+
// bytecodeFormat: legacy
1011
// ----
1112
// Assembly:
1213
// /* "source":44:59 */

test/libyul/objectCompiler/datasize_data.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ object "a" {
44
}
55
// ====
66
// EVMVersion: >=shanghai
7+
// bytecodeFormat: legacy
78
// ----
89
// Assembly:
910
// /* "source":44:61 */

test/libyul/objectCompiler/datasize_self.yul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ object "a" {
44
}
55
// ====
66
// EVMVersion: >=shanghai
7+
// bytecodeFormat: legacy
78
// ----
89
// Assembly:
910
// /* "source":36:49 */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
function e(_._) {
3+
e(0)
4+
}
5+
e(2)
6+
function f(n._) {
7+
f(0)
8+
}
9+
f(2)
10+
function g(_.n) {
11+
g(0)
12+
}
13+
g(2)
14+
}
15+
// ====
16+
// bytecodeFormat: >=EOFv1
17+
// outputs: Assembly
18+
// ----
19+
// Assembly:
20+
// /* "source":53:54 */
21+
// 0x02
22+
// /* "source":51:55 */
23+
// jumpf{code_section_1}
24+
//
25+
// code_section_1: assembly {
26+
// /* "source":136:137 */
27+
// 0x00
28+
// /* "source":134:138 */
29+
// jumpf{code_section_1}
30+
// }

0 commit comments

Comments
 (0)