From 328f2b0a8efa41d0343b4df022ce1106a5984fb4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 10 Apr 2017 14:52:13 +0100 Subject: Use new gasEstimate in CLI --- solc/CommandLineInterface.cpp | 72 +++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index f0b73152..90cc4769 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -315,49 +315,55 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co void CommandLineInterface::handleGasEstimation(string const& _contract) { - using Gas = GasEstimator::GasConsumption; - if (!m_compiler->assemblyItems(_contract) && !m_compiler->runtimeAssemblyItems(_contract)) - return; + Json::Value estimates = m_compiler->gasEstimates(_contract); cout << "Gas estimation:" << endl; - if (eth::AssemblyItems const* items = m_compiler->assemblyItems(_contract)) + + if (estimates["creation"].isObject()) { - Gas gas = GasEstimator::functionalEstimation(*items); - u256 bytecodeSize(m_compiler->runtimeObject(_contract).bytecode.size()); + Json::Value creation = estimates["creation"]; cout << "construction:" << endl; - cout << " " << gas << " + " << (bytecodeSize * eth::GasCosts::createDataGas) << " = "; - gas += bytecodeSize * eth::GasCosts::createDataGas; - cout << gas << endl; + if (creation["executionCost"].isNull()) + cout << " infinite"; + else + cout << " " << creation["executionCost"]; + if (creation["codeDepositCost"].isNull()) + cout << " + infinite"; + else + cout << " + " << creation["codeDepositCost"]; + if (creation["totalCost"].isNull()) + cout << " = infinite"; + else + cout << " = " << creation["totalCost"] << endl; } - if (eth::AssemblyItems const* items = m_compiler->runtimeAssemblyItems(_contract)) + + if (estimates["external"].isObject()) { - ContractDefinition const& contract = m_compiler->contractDefinition(_contract); + Json::Value externalFunctions = estimates["external"]; cout << "external:" << endl; - for (auto it: contract.interfaceFunctions()) - { - string sig = it.second->externalSignature(); - GasEstimator::GasConsumption gas = GasEstimator::functionalEstimation(*items, sig); - cout << " " << sig << ":\t" << gas << endl; - } - if (contract.fallbackFunction()) + for (auto const& name: externalFunctions.getMemberNames()) { - GasEstimator::GasConsumption gas = GasEstimator::functionalEstimation(*items, "INVALID"); - cout << " fallback:\t" << gas << endl; + if (name.empty()) + cout << " fallback:\t"; + else + cout << " " << name << ":\t"; + if (externalFunctions[name].isNull()) + cout << "infinite" << endl; + else + cout << externalFunctions[name] << endl; } + } + + if (estimates["internal"].isObject()) + { + Json::Value internalFunctions = estimates["internal"]; cout << "internal:" << endl; - for (auto const& it: contract.definedFunctions()) + for (auto const& name: internalFunctions.getMemberNames()) { - if (it->isPartOfExternalInterface() || it->isConstructor()) - continue; - size_t entry = m_compiler->functionEntryPoint(_contract, *it); - GasEstimator::GasConsumption gas = GasEstimator::GasConsumption::infinite(); - if (entry > 0) - gas = GasEstimator::functionalEstimation(*items, entry, *it); - FunctionType type(*it); - cout << " " << it->name() << "("; - auto paramTypes = type.parameterTypes(); - for (auto it = paramTypes.begin(); it != paramTypes.end(); ++it) - cout << (*it)->toString() << (it + 1 == paramTypes.end() ? "" : ","); - cout << "):\t" << gas << endl; + cout << " " << name << ":\t"; + if (internalFunctions[name].isNull()) + cout << "infinite" << endl; + else + cout << internalFunctions[name] << endl; } } } -- cgit