Add --show-metadata to enable metadata output.

This commit is contained in:
Alexander Arlt 2020-03-10 21:07:11 -05:00
parent f8344cb4df
commit 9d67edb163
4 changed files with 12 additions and 7 deletions

View File

@ -96,7 +96,8 @@ CommonOptions::CommonOptions(std::string _caption):
("optimize", po::bool_switch(&optimize), "enables optimization")
("optimize-yul", po::bool_switch(&optimizeYul), "enables Yul optimization")
("abiencoderv2", po::bool_switch(&useABIEncoderV2), "enables abi encoder v2")
("show-messages", po::bool_switch(&showMessages), "enables message output");
("show-messages", po::bool_switch(&showMessages), "enables message output")
("show-metadata", po::bool_switch(&showMetadata), "enables metadata output");
}
void CommonOptions::validate() const

View File

@ -50,6 +50,7 @@ struct CommonOptions: boost::noncopyable
bool disableSMT = false;
bool useABIEncoderV2 = false;
bool showMessages = false;
bool showMetadata = false;
langutil::EVMVersion evmVersion() const;

View File

@ -21,6 +21,7 @@
*/
#include <cstdlib>
#include <iostream>
#include <boost/test/framework.hpp>
#include <test/libsolidity/SolidityExecutionFramework.h>
@ -60,6 +61,7 @@ bytes SolidityExecutionFramework::compileContract(
formatter.printErrorInformation(*error);
BOOST_ERROR("Compiling contract failed");
}
std::string contractName(_contractName.empty() ? m_compiler.lastContractName() : _contractName);
evmasm::LinkerObject obj;
if (m_compileViaYul)
{
@ -70,9 +72,7 @@ bytes SolidityExecutionFramework::compileContract(
// get code that does not exhaust the stack.
OptimiserSettings::full()
);
if (!asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(
_contractName.empty() ? m_compiler.lastContractName() : _contractName
)))
if (!asmStack.parseAndAnalyze("", m_compiler.yulIROptimized(contractName)))
{
langutil::SourceReferenceFormatter formatter(std::cerr);
@ -84,7 +84,9 @@ bytes SolidityExecutionFramework::compileContract(
obj = std::move(*asmStack.assemble(yul::AssemblyStack::Machine::EVM).bytecode);
}
else
obj = m_compiler.object(_contractName.empty() ? m_compiler.lastContractName() : _contractName);
obj = m_compiler.object(contractName);
BOOST_REQUIRE(obj.linkReferences.empty());
if (m_showMetadata)
cout << "metadata: " << m_compiler.metadata(contractName) << endl;
return obj.bytecode;
}

View File

@ -41,9 +41,9 @@ class SolidityExecutionFramework: public solidity::test::ExecutionFramework
{
public:
SolidityExecutionFramework() {}
SolidityExecutionFramework(): m_showMetadata(solidity::test::CommonOptions::get().showMetadata) {}
explicit SolidityExecutionFramework(langutil::EVMVersion _evmVersion):
ExecutionFramework(_evmVersion)
ExecutionFramework(_evmVersion), m_showMetadata(solidity::test::CommonOptions::get().showMetadata)
{}
virtual bytes const& compileAndRunWithoutCheck(
@ -68,6 +68,7 @@ public:
protected:
solidity::frontend::CompilerStack m_compiler;
bool m_compileViaYul = false;
bool m_showMetadata = false;
RevertStrings m_revertStrings = RevertStrings::Default;
};