mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Commandline interface for gas estimation.
This commit is contained in:
parent
61fae129f2
commit
fdbce582ab
@ -34,6 +34,7 @@
|
|||||||
#include <libdevcore/CommonData.h>
|
#include <libdevcore/CommonData.h>
|
||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <libevmcore/Instruction.h>
|
#include <libevmcore/Instruction.h>
|
||||||
|
#include <libevmcore/Params.h>
|
||||||
#include <libsolidity/Scanner.h>
|
#include <libsolidity/Scanner.h>
|
||||||
#include <libsolidity/Parser.h>
|
#include <libsolidity/Parser.h>
|
||||||
#include <libsolidity/ASTPrinter.h>
|
#include <libsolidity/ASTPrinter.h>
|
||||||
@ -55,6 +56,7 @@ namespace solidity
|
|||||||
static string const g_argAbiStr = "json-abi";
|
static string const g_argAbiStr = "json-abi";
|
||||||
static string const g_argSolAbiStr = "sol-abi";
|
static string const g_argSolAbiStr = "sol-abi";
|
||||||
static string const g_argSignatureHashes = "hashes";
|
static string const g_argSignatureHashes = "hashes";
|
||||||
|
static string const g_argGas = "gas";
|
||||||
static string const g_argAsmStr = "asm";
|
static string const g_argAsmStr = "asm";
|
||||||
static string const g_argAsmJsonStr = "asm-json";
|
static string const g_argAsmJsonStr = "asm-json";
|
||||||
static string const g_argAstStr = "ast";
|
static string const g_argAstStr = "ast";
|
||||||
@ -94,6 +96,7 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args)
|
|||||||
{
|
{
|
||||||
|
|
||||||
return
|
return
|
||||||
|
_args.count(g_argGas) ||
|
||||||
humanTargetedStdout(_args, g_argAbiStr) ||
|
humanTargetedStdout(_args, g_argAbiStr) ||
|
||||||
humanTargetedStdout(_args, g_argSolAbiStr) ||
|
humanTargetedStdout(_args, g_argSolAbiStr) ||
|
||||||
humanTargetedStdout(_args, g_argSignatureHashes) ||
|
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)
|
bool CommandLineInterface::parseArguments(int argc, char** argv)
|
||||||
{
|
{
|
||||||
// Declare the supported options.
|
// Declare the supported options.
|
||||||
@ -278,6 +305,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
|
|||||||
"Request to output the contract's Solidity ABI interface.")
|
"Request to output the contract's Solidity ABI interface.")
|
||||||
(g_argSignatureHashes.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
|
(g_argSignatureHashes.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
|
||||||
"Request to output the contract's functions' signature hashes.")
|
"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"),
|
(g_argNatspecUserStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
|
||||||
"Request to output the contract's Natspec user documentation.")
|
"Request to output the contract's Natspec user documentation.")
|
||||||
(g_argNatspecDevStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
|
(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);
|
handleBytecode(contract);
|
||||||
handleSignatureHashes(contract);
|
handleSignatureHashes(contract);
|
||||||
handleMeta(DocumentationType::ABIInterface, contract);
|
handleMeta(DocumentationType::ABIInterface, contract);
|
||||||
|
@ -61,6 +61,7 @@ private:
|
|||||||
void handleSignatureHashes(std::string const& _contract);
|
void handleSignatureHashes(std::string const& _contract);
|
||||||
void handleMeta(DocumentationType _type,
|
void handleMeta(DocumentationType _type,
|
||||||
std::string const& _contract);
|
std::string const& _contract);
|
||||||
|
void handleGasEstimation(std::string const& _contract);
|
||||||
|
|
||||||
/// Compiler arguments variable map
|
/// Compiler arguments variable map
|
||||||
boost::program_options::variables_map m_args;
|
boost::program_options::variables_map m_args;
|
||||||
|
Loading…
Reference in New Issue
Block a user