mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add CompilerStack::setOptimiserSettings
This commit is contained in:
parent
6848199b66
commit
30012db396
@ -262,15 +262,12 @@ vector<string> CompilerStack::contractNames() const
|
|||||||
return contractNames;
|
return contractNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerStack::compile(bool _optimize, unsigned _runs)
|
bool CompilerStack::compile()
|
||||||
{
|
{
|
||||||
if (m_stackState < AnalysisSuccessful)
|
if (m_stackState < AnalysisSuccessful)
|
||||||
if (!parseAndAnalyze())
|
if (!parseAndAnalyze())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_optimize = _optimize;
|
|
||||||
m_optimizeRuns = _runs;
|
|
||||||
|
|
||||||
map<ContractDefinition const*, eth::Assembly const*> compiledContracts;
|
map<ContractDefinition const*, eth::Assembly const*> compiledContracts;
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
|
@ -103,6 +103,14 @@ public:
|
|||||||
m_libraries = _libraries;
|
m_libraries = _libraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Changes the optimiser settings.
|
||||||
|
/// Will not take effect before running compile.
|
||||||
|
void setOptimiserSettings(bool _optimize, unsigned _runs = 200)
|
||||||
|
{
|
||||||
|
m_optimize = _optimize;
|
||||||
|
m_optimizeRuns = _runs;
|
||||||
|
}
|
||||||
|
|
||||||
/// Resets the compiler to a state where the sources are not parsed or even removed.
|
/// Resets the compiler to a state where the sources are not parsed or even removed.
|
||||||
/// Sets the state to SourcesSet if @a _keepSources is true, otherwise to Empty.
|
/// Sets the state to SourcesSet if @a _keepSources is true, otherwise to Empty.
|
||||||
/// All settings, with the exception of remappings, are reset.
|
/// All settings, with the exception of remappings, are reset.
|
||||||
@ -126,10 +134,7 @@ public:
|
|||||||
|
|
||||||
/// Compiles the source units that were previously added and parsed.
|
/// Compiles the source units that were previously added and parsed.
|
||||||
/// @returns false on error.
|
/// @returns false on error.
|
||||||
bool compile(
|
bool compile();
|
||||||
bool _optimize = false,
|
|
||||||
unsigned _runs = 200
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @returns the assembled object for a contract.
|
/// @returns the assembled object for a contract.
|
||||||
eth::LinkerObject const& object(std::string const& _contractName = "") const;
|
eth::LinkerObject const& object(std::string const& _contractName = "") const;
|
||||||
|
@ -249,6 +249,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
|
|||||||
Json::Value optimizerSettings = settings.get("optimizer", Json::Value());
|
Json::Value optimizerSettings = settings.get("optimizer", Json::Value());
|
||||||
bool const optimize = optimizerSettings.get("enabled", Json::Value(false)).asBool();
|
bool const optimize = optimizerSettings.get("enabled", Json::Value(false)).asBool();
|
||||||
unsigned const optimizeRuns = optimizerSettings.get("runs", Json::Value(200u)).asUInt();
|
unsigned const optimizeRuns = optimizerSettings.get("runs", Json::Value(200u)).asUInt();
|
||||||
|
m_compilerStack.setOptimiserSettings(optimize, optimizeRuns);
|
||||||
|
|
||||||
map<string, h160> libraries;
|
map<string, h160> libraries;
|
||||||
Json::Value jsonLibraries = settings.get("libraries", Json::Value());
|
Json::Value jsonLibraries = settings.get("libraries", Json::Value());
|
||||||
@ -268,7 +269,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_compilerStack.compile(optimize, optimizeRuns);
|
m_compilerStack.compile();
|
||||||
|
|
||||||
for (auto const& error: m_compilerStack.errors())
|
for (auto const& error: m_compilerStack.errors())
|
||||||
{
|
{
|
||||||
|
@ -779,7 +779,9 @@ bool CommandLineInterface::processInput()
|
|||||||
// TODO: Perhaps we should not compile unless requested
|
// TODO: Perhaps we should not compile unless requested
|
||||||
bool optimize = m_args.count(g_argOptimize) > 0;
|
bool optimize = m_args.count(g_argOptimize) > 0;
|
||||||
unsigned runs = m_args[g_argOptimizeRuns].as<unsigned>();
|
unsigned runs = m_args[g_argOptimizeRuns].as<unsigned>();
|
||||||
bool successful = m_compiler->compile(optimize, runs);
|
m_compiler->setOptimiserSettings(optimize, runs);
|
||||||
|
|
||||||
|
bool successful = m_compiler->compile();
|
||||||
|
|
||||||
for (auto const& error: m_compiler->errors())
|
for (auto const& error: m_compiler->errors())
|
||||||
SourceReferenceFormatter::printExceptionInformation(
|
SourceReferenceFormatter::printExceptionInformation(
|
||||||
|
@ -223,7 +223,8 @@ protected:
|
|||||||
{
|
{
|
||||||
m_compiler.reset(false);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", registrarCode);
|
m_compiler.addSource("", registrarCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns);
|
||||||
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed");
|
||||||
s_compiledRegistrar.reset(new bytes(m_compiler.object("GlobalRegistrar").bytecode));
|
s_compiledRegistrar.reset(new bytes(m_compiler.object("GlobalRegistrar").bytecode));
|
||||||
}
|
}
|
||||||
sendMessage(*s_compiledRegistrar, true);
|
sendMessage(*s_compiledRegistrar, true);
|
||||||
|
@ -135,7 +135,8 @@ protected:
|
|||||||
{
|
{
|
||||||
m_compiler.reset(false);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", registrarCode);
|
m_compiler.addSource("", registrarCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns);
|
||||||
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed");
|
||||||
s_compiledRegistrar.reset(new bytes(m_compiler.object("FixedFeeRegistrar").bytecode));
|
s_compiledRegistrar.reset(new bytes(m_compiler.object("FixedFeeRegistrar").bytecode));
|
||||||
}
|
}
|
||||||
sendMessage(*s_compiledRegistrar, true);
|
sendMessage(*s_compiledRegistrar, true);
|
||||||
|
@ -450,7 +450,8 @@ protected:
|
|||||||
{
|
{
|
||||||
m_compiler.reset(false);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", walletCode);
|
m_compiler.addSource("", walletCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns);
|
||||||
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed");
|
||||||
s_compiledWallet.reset(new bytes(m_compiler.object("Wallet").bytecode));
|
s_compiledWallet.reset(new bytes(m_compiler.object("Wallet").bytecode));
|
||||||
}
|
}
|
||||||
bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners);
|
bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners);
|
||||||
|
@ -49,7 +49,8 @@ public:
|
|||||||
{
|
{
|
||||||
m_compiler.reset(false);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", "pragma solidity >=0.0;\n" + _sourceCode);
|
m_compiler.addSource("", "pragma solidity >=0.0;\n" + _sourceCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(dev::test::Options::get().optimize), "Compiling contract failed");
|
m_compiler.setOptimiserSettings(dev::test::Options::get().optimize);
|
||||||
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(), "Compiling contract failed");
|
||||||
|
|
||||||
AssemblyItems const* items = m_compiler.runtimeAssemblyItems("");
|
AssemblyItems const* items = m_compiler.runtimeAssemblyItems("");
|
||||||
ASTNode const& sourceUnit = m_compiler.ast();
|
ASTNode const& sourceUnit = m_compiler.ast();
|
||||||
|
@ -44,7 +44,8 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
)";
|
)";
|
||||||
CompilerStack compilerStack;
|
CompilerStack compilerStack;
|
||||||
compilerStack.addSource("", std::string(sourceCode));
|
compilerStack.addSource("", std::string(sourceCode));
|
||||||
ETH_TEST_REQUIRE_NO_THROW(compilerStack.compile(dev::test::Options::get().optimize), "Compiling contract failed");
|
compilerStack.setOptimiserSettings(dev::test::Options::get().optimize);
|
||||||
|
ETH_TEST_REQUIRE_NO_THROW(compilerStack.compile(), "Compiling contract failed");
|
||||||
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
|
||||||
std::string const& metadata = compilerStack.metadata("test");
|
std::string const& metadata = compilerStack.metadata("test");
|
||||||
BOOST_CHECK(dev::test::isValidMetadata(metadata));
|
BOOST_CHECK(dev::test::isValidMetadata(metadata));
|
||||||
|
@ -57,7 +57,8 @@ public:
|
|||||||
m_compiler.reset(false);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", sourceCode);
|
m_compiler.addSource("", sourceCode);
|
||||||
m_compiler.setLibraries(_libraryAddresses);
|
m_compiler.setLibraries(_libraryAddresses);
|
||||||
if (!m_compiler.compile(m_optimize, m_optimizeRuns))
|
m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns);
|
||||||
|
if (!m_compiler.compile())
|
||||||
{
|
{
|
||||||
for (auto const& error: m_compiler.errors())
|
for (auto const& error: m_compiler.errors())
|
||||||
SourceReferenceFormatter::printExceptionInformation(
|
SourceReferenceFormatter::printExceptionInformation(
|
||||||
|
Loading…
Reference in New Issue
Block a user