aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/CompilerStack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/interface/CompilerStack.cpp')
-rw-r--r--libsolidity/interface/CompilerStack.cpp77
1 files changed, 46 insertions, 31 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 47dc30cf..aa33bad8 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);
@@ -711,39 +711,33 @@ void CompilerStack::compileContract(
for (auto const* dependency: _contract.annotation().contractDependencies)
compileContract(*dependency, _compiledContracts);
- shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimize, m_optimizeRuns);
Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName());
- string metadata = createMetadata(compiledContract);
- bytes cborEncodedHash =
- // CBOR-encoding of the key "bzzr0"
- bytes{0x65, 'b', 'z', 'z', 'r', '0'}+
- // CBOR-encoding of the hash
- bytes{0x58, 0x20} + dev::swarmHash(metadata).asBytes();
- bytes cborEncodedMetadata;
- if (onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures))
- cborEncodedMetadata =
- // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)}
- bytes{0xa1} +
- cborEncodedHash;
- else
- cborEncodedMetadata =
- // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true}
- bytes{0xa2} +
- cborEncodedHash +
- bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5};
- solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large");
- // 16-bit big endian length
- cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2);
- compiler->compileContract(_contract, _compiledContracts, cborEncodedMetadata);
+
+ shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimize, m_optimizeRuns);
compiledContract.compiler = compiler;
+ string metadata = createMetadata(compiledContract);
+ compiledContract.metadata = metadata;
+
+ bytes cborEncodedMetadata = createCBORMetadata(
+ metadata,
+ !onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)
+ );
+
try
{
- compiledContract.object = compiler->assembledObject();
+ // Run optimiser and compile the contract.
+ compiler->compileContract(_contract, _compiledContracts, cborEncodedMetadata);
}
catch(eth::OptimizerException const&)
{
- solAssert(false, "Assembly optimizer exception for bytecode");
+ solAssert(false, "Optimizer exception during compilation");
+ }
+
+ try
+ {
+ // Assemble deployment (incl. runtime) object.
+ compiledContract.object = compiler->assembledObject();
}
catch(eth::AssemblyException const&)
{
@@ -752,18 +746,14 @@ void CompilerStack::compileContract(
try
{
+ // Assemble runtime object.
compiledContract.runtimeObject = compiler->runtimeObject();
}
- catch(eth::OptimizerException const&)
- {
- solAssert(false, "Assembly optimizer exception for deployed bytecode");
- }
catch(eth::AssemblyException const&)
{
solAssert(false, "Assembly exception for deployed bytecode");
}
- compiledContract.metadata = metadata;
_compiledContracts[compiledContract.contract] = &compiler->assembly();
try
@@ -894,6 +884,31 @@ string CompilerStack::createMetadata(Contract const& _contract) const
return jsonCompactPrint(meta);
}
+bytes CompilerStack::createCBORMetadata(string _metadata, bool _experimentalMode)
+{
+ bytes cborEncodedHash =
+ // CBOR-encoding of the key "bzzr0"
+ bytes{0x65, 'b', 'z', 'z', 'r', '0'}+
+ // CBOR-encoding of the hash
+ bytes{0x58, 0x20} + dev::swarmHash(_metadata).asBytes();
+ bytes cborEncodedMetadata;
+ if (_experimentalMode)
+ cborEncodedMetadata =
+ // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true}
+ bytes{0xa2} +
+ cborEncodedHash +
+ bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5};
+ else
+ cborEncodedMetadata =
+ // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)}
+ bytes{0xa1} +
+ cborEncodedHash;
+ solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large");
+ // 16-bit big endian length
+ cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2);
+ return cborEncodedMetadata;
+}
+
string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) const
{
string ret;