diff options
author | Christian <c@ethdev.com> | 2014-11-06 23:30:50 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-11-07 05:55:42 +0800 |
commit | 225fc8e1b31860ab002c38fb9ff326f20b76965f (patch) | |
tree | bfe0ff0dafcabe113a768fb6377f7481be3e6226 | |
parent | 04726a4ee4bf982389a310d45e5751b974d93655 (diff) | |
download | dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.tar dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.tar.gz dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.tar.bz2 dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.tar.lz dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.tar.xz dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.tar.zst dexon-solidity-225fc8e1b31860ab002c38fb9ff326f20b76965f.zip |
Option to activate the optimizer for solidity.
-rw-r--r-- | Compiler.cpp | 4 | ||||
-rw-r--r-- | Compiler.h | 4 | ||||
-rw-r--r-- | CompilerContext.h | 2 | ||||
-rw-r--r-- | CompilerStack.cpp | 5 | ||||
-rw-r--r-- | CompilerStack.h | 2 |
5 files changed, 9 insertions, 8 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index d05552b9..571a62d7 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -30,11 +30,11 @@ using namespace std; namespace dev { namespace solidity { -bytes Compiler::compile(ContractDefinition& _contract) +bytes Compiler::compile(ContractDefinition& _contract, bool _optimize) { Compiler compiler; compiler.compileContract(_contract); - return compiler.m_context.getAssembledBytecode(); + return compiler.m_context.getAssembledBytecode(_optimize); } void Compiler::compileContract(ContractDefinition& _contract) @@ -33,11 +33,11 @@ public: Compiler(): m_returnTag(m_context.newTag()) {} void compileContract(ContractDefinition& _contract); - bytes getAssembledBytecode() { return m_context.getAssembledBytecode(); } + bytes getAssembledBytecode(bool _optimize = false) { return m_context.getAssembledBytecode(_optimize); } void streamAssembly(std::ostream& _stream) const { m_context.streamAssembly(_stream); } /// Compile the given contract and return the EVM bytecode. - static bytes compile(ContractDefinition& _contract); + static bytes compile(ContractDefinition& _contract, bool _optimize); private: /// Creates a new compiler context / assembly and packs the current code into the data part. diff --git a/CompilerContext.h b/CompilerContext.h index 088ef43b..866c621d 100644 --- a/CompilerContext.h +++ b/CompilerContext.h @@ -75,7 +75,7 @@ public: eth::Assembly const& getAssembly() const { return m_asm; } void streamAssembly(std::ostream& _stream) const { _stream << m_asm; } - bytes getAssembledBytecode() const { return m_asm.assemble(); } + bytes getAssembledBytecode(bool _optimize = false) { return m_asm.optimise(_optimize).assemble(); } private: eth::Assembly m_asm; diff --git a/CompilerStack.cpp b/CompilerStack.cpp index bbd693ae..c991171a 100644 --- a/CompilerStack.cpp +++ b/CompilerStack.cpp @@ -34,7 +34,8 @@ namespace dev namespace solidity { -bytes CompilerStack::compile(std::string const& _sourceCode, shared_ptr<Scanner> _scanner) +bytes CompilerStack::compile(std::string const& _sourceCode, shared_ptr<Scanner> _scanner, + bool _optimize) { if (!_scanner) _scanner = make_shared<Scanner>(); @@ -42,7 +43,7 @@ bytes CompilerStack::compile(std::string const& _sourceCode, shared_ptr<Scanner> ASTPointer<ContractDefinition> contract = Parser().parse(_scanner); NameAndTypeResolver().resolveNamesAndTypes(*contract); - return Compiler::compile(*contract); + return Compiler::compile(*contract, _optimize); } } diff --git a/CompilerStack.h b/CompilerStack.h index 9f3f81c0..b003745d 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -36,7 +36,7 @@ class CompilerStack public: /// Compile the given @a _sourceCode to bytecode. If a scanner is provided, it is used for /// scanning the source code - this is useful for printing exception information. - static bytes compile(std::string const& _sourceCode, std::shared_ptr<Scanner> _scanner = std::shared_ptr<Scanner>()); + static bytes compile(std::string const& _sourceCode, std::shared_ptr<Scanner> _scanner = std::shared_ptr<Scanner>(), bool _optimize = false); }; } |