Skip to content

Add outputs setting to ObjectCompilerTest #15803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions test/libyul/ObjectCompilerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ ObjectCompilerTest::ObjectCompilerTest(std::string const& _filename):
},
"minimal"
);

constexpr std::array allowedOutputs = {"Assembly", "Bytecode", "Opcodes", "SourceMappings"};
boost::split(m_outputSetting, m_reader.stringSetting("outputs", "Assembly,Bytecode,Opcodes,SourceMappings"), boost::is_any_of(","));
for (auto const& output: m_outputSetting)
if (std::find(allowedOutputs.begin(), allowedOutputs.end(), output) == allowedOutputs.end())
BOOST_THROW_EXCEPTION(std::runtime_error{"Invalid output type: \"" + output + "\""});

m_expectation = m_reader.simpleExpectations();
}

Expand All @@ -78,18 +85,26 @@ TestCase::TestResult ObjectCompilerTest::run(std::ostream& _stream, std::string
solAssert(obj.bytecode);
solAssert(obj.sourceMappings);

m_obtainedResult = "Assembly:\n" + obj.assembly->assemblyString(yulStack.debugInfoSelection());
if (std::find(m_outputSetting.begin(), m_outputSetting.end(), "Assembly") != m_outputSetting.end())
m_obtainedResult = "Assembly:\n" + obj.assembly->assemblyString(yulStack.debugInfoSelection());
if (obj.bytecode->bytecode.empty())
m_obtainedResult += "-- empty bytecode --\n";
else
m_obtainedResult +=
"Bytecode: " +
util::toHex(obj.bytecode->bytecode) +
"\nOpcodes: " +
boost::trim_copy(evmasm::disassemble(obj.bytecode->bytecode, solidity::test::CommonOptions::get().evmVersion())) +
"\nSourceMappings:" +
(obj.sourceMappings->empty() ? "" : " " + *obj.sourceMappings) +
"\n";
{
if (std::find(m_outputSetting.begin(), m_outputSetting.end(), "Bytecode") != m_outputSetting.end())
m_obtainedResult += "Bytecode: " + util::toHex(obj.bytecode->bytecode);
if (std::find(m_outputSetting.begin(), m_outputSetting.end(), "Opcodes") != m_outputSetting.end())
{
m_obtainedResult += (!m_obtainedResult.empty() && m_obtainedResult.back() != '\n') ? "\n" : "";
m_obtainedResult += "Opcodes: " +
boost::trim_copy(evmasm::disassemble(obj.bytecode->bytecode, solidity::test::CommonOptions::get().evmVersion()));
}
if (std::find(m_outputSetting.begin(), m_outputSetting.end(), "SourceMappings") != m_outputSetting.end())
{
m_obtainedResult += (!m_obtainedResult.empty() && m_obtainedResult.back() != '\n') ? "\n" : "";
m_obtainedResult += "SourceMappings:" + (obj.sourceMappings->empty() ? "" : " " + *obj.sourceMappings) + "\n";
}
}

return checkResult(_stream, _linePrefix, _formatted);
}
1 change: 1 addition & 0 deletions test/libyul/ObjectCompilerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ObjectCompilerTest: public solidity::frontend::test::EVMVersionRestrictedT
void disambiguate();

frontend::OptimisationPreset m_optimisationPreset;
std::vector<std::string> m_outputSetting;
};

}