diff options
author | chriseth <c@ethdev.com> | 2015-05-22 20:19:58 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-05-22 22:12:40 +0800 |
commit | fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2 (patch) | |
tree | 0e95ad76248b0a11c13515378d781a8935960b77 /CommandLineInterface.cpp | |
parent | 61fae129f2f1ae7ed73603edf06b48f5e8c8582f (diff) | |
download | dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.tar dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.tar.gz dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.tar.bz2 dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.tar.lz dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.tar.xz dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.tar.zst dexon-solidity-fdbce582ab6f6028f4bf3081f1ce24ddc2473ea2.zip |
Commandline interface for gas estimation.
Diffstat (limited to 'CommandLineInterface.cpp')
-rw-r--r-- | CommandLineInterface.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index b81fcad1..c86938f8 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -34,6 +34,7 @@ #include <libdevcore/CommonData.h> #include <libdevcore/CommonIO.h> #include <libevmcore/Instruction.h> +#include <libevmcore/Params.h> #include <libsolidity/Scanner.h> #include <libsolidity/Parser.h> #include <libsolidity/ASTPrinter.h> @@ -55,6 +56,7 @@ namespace solidity static string const g_argAbiStr = "json-abi"; static string const g_argSolAbiStr = "sol-abi"; static string const g_argSignatureHashes = "hashes"; +static string const g_argGas = "gas"; static string const g_argAsmStr = "asm"; static string const g_argAsmJsonStr = "asm-json"; static string const g_argAstStr = "ast"; @@ -94,6 +96,7 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) { return + _args.count(g_argGas) || humanTargetedStdout(_args, g_argAbiStr) || humanTargetedStdout(_args, g_argSolAbiStr) || humanTargetedStdout(_args, g_argSignatureHashes) || @@ -245,6 +248,30 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co } } +void CommandLineInterface::handleGasEstimation(string const& _contract) +{ + using Gas = GasEstimator::GasConsumption; + if (!m_compiler->getAssemblyItems(_contract) && !m_compiler->getRuntimeAssemblyItems(_contract)) + return; + cout << "Gas estimation:" << endl; + if (eth::AssemblyItems const* items = m_compiler->getAssemblyItems(_contract)) + { + Gas gas = GasEstimator::functionalEstimation(*items); + u256 bytecodeSize(m_compiler->getRuntimeBytecode(_contract).size()); + cout << "[construction]:\t"; + cout << gas << " + " << (bytecodeSize * eth::c_createDataGas) << " = "; + gas += bytecodeSize * eth::c_createDataGas; + cout << gas << endl; + } + if (eth::AssemblyItems const* items = m_compiler->getRuntimeAssemblyItems(_contract)) + for (auto it: m_compiler->getContractDefinition(_contract).getInterfaceFunctions()) + { + string sig = it.second->externalSignature(); + GasEstimator::GasConsumption gas = GasEstimator::functionalEstimation(*items, sig); + cout << sig << ":\t" << gas << endl; + } +} + bool CommandLineInterface::parseArguments(int argc, char** argv) { // Declare the supported options. @@ -278,6 +305,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) "Request to output the contract's Solidity ABI interface.") (g_argSignatureHashes.c_str(), po::value<OutputType>()->value_name("stdout|file|both"), "Request to output the contract's functions' signature hashes.") + (g_argGas.c_str(), + "Request to output an estimate for each function's maximal gas usage.") (g_argNatspecUserStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"), "Request to output the contract's Natspec user documentation.") (g_argNatspecDevStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"), @@ -553,6 +582,9 @@ void CommandLineInterface::actOnInput() } } + if (m_args.count(g_argGas)) + handleGasEstimation(contract); + handleBytecode(contract); handleSignatureHashes(contract); handleMeta(DocumentationType::ABIInterface, contract); |