Merge pull request #8391 from ethereum/optimizedIRCommandline

Enable optimized IR output via the commandline.
This commit is contained in:
chriseth 2020-03-09 15:05:29 +01:00 committed by GitHub
commit 4ad998eb5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 24 deletions

View File

@ -7,6 +7,7 @@ Language Features:
Compiler Features: Compiler Features:
* AssemblyStack: Support for source locations (source mappings) and thus debugging Yul sources. * AssemblyStack: Support for source locations (source mappings) and thus debugging Yul sources.
* Commandline Interface: Enable output of experimental optimized IR via ``--ir-optimized``.
Bugfixes: Bugfixes:

View File

@ -127,6 +127,7 @@ static string const g_strInterface = "interface";
static string const g_strYul = "yul"; static string const g_strYul = "yul";
static string const g_strYulDialect = "yul-dialect"; static string const g_strYulDialect = "yul-dialect";
static string const g_strIR = "ir"; static string const g_strIR = "ir";
static string const g_strIROptimized = "ir-optimized";
static string const g_strIPFS = "ipfs"; static string const g_strIPFS = "ipfs";
static string const g_strLicense = "license"; static string const g_strLicense = "license";
static string const g_strLibraries = "libraries"; static string const g_strLibraries = "libraries";
@ -190,6 +191,7 @@ static string const g_argImportAst = g_strImportAst;
static string const g_argInputFile = g_strInputFile; static string const g_argInputFile = g_strInputFile;
static string const g_argYul = g_strYul; static string const g_argYul = g_strYul;
static string const g_argIR = g_strIR; static string const g_argIR = g_strIR;
static string const g_argIROptimized = g_strIROptimized;
static string const g_argEwasm = g_strEwasm; static string const g_argEwasm = g_strEwasm;
static string const g_argLibraries = g_strLibraries; static string const g_argLibraries = g_strLibraries;
static string const g_argLink = g_strLink; static string const g_argLink = g_strLink;
@ -336,36 +338,50 @@ void CommandLineInterface::handleOpcode(string const& _contract)
void CommandLineInterface::handleIR(string const& _contractName) void CommandLineInterface::handleIR(string const& _contractName)
{ {
if (m_args.count(g_argIR)) if (!m_args.count(g_argIR))
return;
if (m_args.count(g_argOutputDir))
createFile(m_compiler->filesystemFriendlyName(_contractName) + ".yul", m_compiler->yulIR(_contractName));
else
{ {
if (m_args.count(g_argOutputDir)) sout() << "IR:" << endl;
createFile(m_compiler->filesystemFriendlyName(_contractName) + ".yul", m_compiler->yulIR(_contractName)); sout() << m_compiler->yulIR(_contractName) << endl;
else }
{ }
sout() << "IR:" << endl;
sout() << m_compiler->yulIR(_contractName) << endl; void CommandLineInterface::handleIROptimized(string const& _contractName)
} {
if (!m_args.count(g_argIROptimized))
return;
if (m_args.count(g_argOutputDir))
createFile(m_compiler->filesystemFriendlyName(_contractName) + "_opt.yul", m_compiler->yulIROptimized(_contractName));
else
{
sout() << "Optimized IR:" << endl;
sout() << m_compiler->yulIROptimized(_contractName) << endl;
} }
} }
void CommandLineInterface::handleEwasm(string const& _contractName) void CommandLineInterface::handleEwasm(string const& _contractName)
{ {
if (m_args.count(g_argEwasm)) if (!m_args.count(g_argEwasm))
return;
if (m_args.count(g_argOutputDir))
{ {
if (m_args.count(g_argOutputDir)) createFile(m_compiler->filesystemFriendlyName(_contractName) + ".wast", m_compiler->ewasm(_contractName));
{ createFile(
createFile(m_compiler->filesystemFriendlyName(_contractName) + ".wast", m_compiler->ewasm(_contractName)); m_compiler->filesystemFriendlyName(_contractName) + ".wasm",
createFile( asString(m_compiler->ewasmObject(_contractName).bytecode)
m_compiler->filesystemFriendlyName(_contractName) + ".wasm", );
asString(m_compiler->ewasmObject(_contractName).bytecode) }
); else
} {
else sout() << "Ewasm text:" << endl;
{ sout() << m_compiler->ewasm(_contractName) << endl;
sout() << "Ewasm text:" << endl; sout() << "Ewasm binary (hex): " << m_compiler->ewasmObject(_contractName).toHex() << endl;
sout() << m_compiler->ewasm(_contractName) << endl;
sout() << "Ewasm binary (hex): " << m_compiler->ewasmObject(_contractName).toHex() << endl;
}
} }
} }
@ -812,6 +828,7 @@ Allowed options)",
(g_argBinaryRuntime.c_str(), "Binary of the runtime part of the contracts in hex.") (g_argBinaryRuntime.c_str(), "Binary of the runtime part of the contracts in hex.")
(g_argAbi.c_str(), "ABI specification of the contracts.") (g_argAbi.c_str(), "ABI specification of the contracts.")
(g_argIR.c_str(), "Intermediate Representation (IR) of all contracts (EXPERIMENTAL).") (g_argIR.c_str(), "Intermediate Representation (IR) of all contracts (EXPERIMENTAL).")
(g_argIROptimized.c_str(), "Optimized intermediate Representation (IR) of all contracts (EXPERIMENTAL).")
(g_argEwasm.c_str(), "Ewasm text representation of all contracts (EXPERIMENTAL).") (g_argEwasm.c_str(), "Ewasm text representation of all contracts (EXPERIMENTAL).")
(g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.") (g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.")
(g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.") (g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.")
@ -1123,7 +1140,7 @@ bool CommandLineInterface::processInput()
m_compiler->setRevertStringBehaviour(m_revertStrings); m_compiler->setRevertStringBehaviour(m_revertStrings);
// TODO: Perhaps we should not compile unless requested // TODO: Perhaps we should not compile unless requested
m_compiler->enableIRGeneration(m_args.count(g_argIR)); m_compiler->enableIRGeneration(m_args.count(g_argIR) || m_args.count(g_argIROptimized));
m_compiler->enableEwasmGeneration(m_args.count(g_argEwasm)); m_compiler->enableEwasmGeneration(m_args.count(g_argEwasm));
OptimiserSettings settings = m_args.count(g_argOptimize) ? OptimiserSettings::standard() : OptimiserSettings::minimal(); OptimiserSettings settings = m_args.count(g_argOptimize) ? OptimiserSettings::standard() : OptimiserSettings::minimal();
@ -1631,6 +1648,7 @@ void CommandLineInterface::outputCompilationResults()
handleBytecode(contract); handleBytecode(contract);
handleIR(contract); handleIR(contract);
handleIROptimized(contract);
handleEwasm(contract); handleEwasm(contract);
handleSignatureHashes(contract); handleSignatureHashes(contract);
handleMetadata(contract); handleMetadata(contract);

View File

@ -65,6 +65,7 @@ private:
void handleBinary(std::string const& _contract); void handleBinary(std::string const& _contract);
void handleOpcode(std::string const& _contract); void handleOpcode(std::string const& _contract);
void handleIR(std::string const& _contract); void handleIR(std::string const& _contract);
void handleIROptimized(std::string const& _contract);
void handleEwasm(std::string const& _contract); void handleEwasm(std::string const& _contract);
void handleBytecode(std::string const& _contract); void handleBytecode(std::string const& _contract);
void handleSignatureHashes(std::string const& _contract); void handleSignatureHashes(std::string const& _contract);