From dcee8e11adba5382d40a25b4e61b5b364d27ecb2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Jun 2018 16:59:35 +0200 Subject: [PATCH 1/2] Reorder some of the flow in CompilerStack::compileContract for readability --- libsolidity/interface/CompilerStack.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 47dc30cf6..a3646a3d9 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -711,9 +711,15 @@ void CompilerStack::compileContract( for (auto const* dependency: _contract.annotation().contractDependencies) compileContract(*dependency, _compiledContracts); - shared_ptr compiler = make_shared(m_evmVersion, m_optimize, m_optimizeRuns); Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName()); + + shared_ptr compiler = make_shared(m_evmVersion, m_optimize, m_optimizeRuns); + compiledContract.compiler = compiler; + string metadata = createMetadata(compiledContract); + compiledContract.metadata = metadata; + + // Prepare CBOR metadata for the bytecode bytes cborEncodedHash = // CBOR-encoding of the key "bzzr0" bytes{0x65, 'b', 'z', 'z', 'r', '0'}+ @@ -734,8 +740,9 @@ void CompilerStack::compileContract( solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large"); // 16-bit big endian length cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2); + + // Run optimiser and compile the contract. compiler->compileContract(_contract, _compiledContracts, cborEncodedMetadata); - compiledContract.compiler = compiler; try { @@ -763,7 +770,6 @@ void CompilerStack::compileContract( solAssert(false, "Assembly exception for deployed bytecode"); } - compiledContract.metadata = metadata; _compiledContracts[compiledContract.contract] = &compiler->assembly(); try From 0a632011be455d108eebc8a338346cfa2d40e527 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 20 Jun 2018 17:04:22 +0200 Subject: [PATCH 2/2] CompilerStack absolutePath/sanitizePath can be made static --- libsolidity/interface/CompilerStack.cpp | 2 +- libsolidity/interface/CompilerStack.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index a3646a3d9..a8668336c 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -669,7 +669,7 @@ void CompilerStack::resolveImports() swap(m_sourceOrder, sourceOrder); } -string CompilerStack::absolutePath(string const& _path, string const& _reference) const +string CompilerStack::absolutePath(string const& _path, string const& _reference) { using path = boost::filesystem::path; path p(_path); diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 13c9cc7a1..018c61ecb 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -273,9 +273,9 @@ private: std::string applyRemapping(std::string const& _path, std::string const& _context); void resolveImports(); /// @returns the absolute path corresponding to @a _path relative to @a _reference. - std::string absolutePath(std::string const& _path, std::string const& _reference) const; + static std::string absolutePath(std::string const& _path, std::string const& _reference); /// Helper function to return path converted strings. - std::string sanitizePath(std::string const& _path) const { return boost::filesystem::path(_path).generic_string(); } + static std::string sanitizePath(std::string const& _path) { return boost::filesystem::path(_path).generic_string(); } /// @returns true if the contract is requested to be compiled. bool isRequestedContract(ContractDefinition const& _contract) const;