aboutsummaryrefslogtreecommitdiffstats
path: root/solc
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-04-10 21:52:05 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-13 09:17:40 +0800
commitd90fd439e2e96551018b4f90ec073cf7e9b6e4d9 (patch)
tree66967bb7c5a7b95737e4a2a189ecb67b658505ed /solc
parente6221108b601938d6165cc1a0583d70c30e6e364 (diff)
downloaddexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.tar
dexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.tar.gz
dexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.tar.bz2
dexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.tar.lz
dexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.tar.xz
dexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.tar.zst
dexon-solidity-d90fd439e2e96551018b4f90ec073cf7e9b6e4d9.zip
Use new gasEstimate in jsonCompiler
Diffstat (limited to 'solc')
-rw-r--r--solc/jsonCompiler.cpp63
1 files changed, 12 insertions, 51 deletions
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp
index 065716ea..b465d8db 100644
--- a/solc/jsonCompiler.cpp
+++ b/solc/jsonCompiler.cpp
@@ -58,61 +58,22 @@ Json::Value functionHashes(ContractDefinition const& _contract)
return functionHashes;
}
-Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
-{
- if (_gas.isInfinite || _gas.value > std::numeric_limits<Json::LargestUInt>::max())
- return Json::Value(Json::nullValue);
- else
- return Json::Value(Json::LargestUInt(_gas.value));
-}
-
Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
{
- Json::Value gasEstimates(Json::objectValue);
- using Gas = GasEstimator::GasConsumption;
- if (!_compiler.assemblyItems(_contract) && !_compiler.runtimeAssemblyItems(_contract))
- return gasEstimates;
- if (eth::AssemblyItems const* items = _compiler.assemblyItems(_contract))
- {
- Gas gas = GasEstimator::functionalEstimation(*items);
- u256 bytecodeSize(_compiler.runtimeObject(_contract).bytecode.size());
- Json::Value creationGas(Json::arrayValue);
- creationGas[0] = gasToJson(gas);
- creationGas[1] = gasToJson(bytecodeSize * eth::GasCosts::createDataGas);
- gasEstimates["creation"] = creationGas;
- }
- if (eth::AssemblyItems const* items = _compiler.runtimeAssemblyItems(_contract))
+ Json::Value estimates = _compiler.gasEstimates(_contract);
+ Json::Value output(Json::objectValue);
+
+ if (estimates["creation"].isObject())
{
- ContractDefinition const& contract = _compiler.contractDefinition(_contract);
- Json::Value externalFunctions(Json::objectValue);
- for (auto it: contract.interfaceFunctions())
- {
- string sig = it.second->externalSignature();
- externalFunctions[sig] = gasToJson(GasEstimator::functionalEstimation(*items, sig));
- }
- if (contract.fallbackFunction())
- externalFunctions[""] = gasToJson(GasEstimator::functionalEstimation(*items, "INVALID"));
- gasEstimates["external"] = externalFunctions;
- Json::Value internalFunctions(Json::objectValue);
- for (auto const& it: contract.definedFunctions())
- {
- if (it->isPartOfExternalInterface() || it->isConstructor())
- continue;
- size_t entry = _compiler.functionEntryPoint(_contract, *it);
- GasEstimator::GasConsumption gas = GasEstimator::GasConsumption::infinite();
- if (entry > 0)
- gas = GasEstimator::functionalEstimation(*items, entry, *it);
- FunctionType type(*it);
- string sig = it->name() + "(";
- auto paramTypes = type.parameterTypes();
- for (auto it = paramTypes.begin(); it != paramTypes.end(); ++it)
- sig += (*it)->toString() + (it + 1 == paramTypes.end() ? "" : ",");
- sig += ")";
- internalFunctions[sig] = gasToJson(gas);
- }
- gasEstimates["internal"] = internalFunctions;
+ Json::Value creation(Json::arrayValue);
+ creation[0] = estimates["creation"]["executionCost"];
+ creation[1] = estimates["creation"]["codeDepositCost"];
+ output["creation"] = creation;
}
- return gasEstimates;
+ output["external"] = estimates["external"];
+ output["internal"] = estimates["internal"];
+
+ return output;
}
string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback _readCallback)