From db5ea8ec0325512af3238918ca0ea297488a5c5d Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Tue, 24 Apr 2018 15:18:12 +0200 Subject: Read from stdin only if - is explicitly given --- solc/CommandLineInterface.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 1f04c68a..89ac8806 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -404,9 +404,7 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() { bool ignoreMissing = m_args.count(g_argIgnoreMissingFiles); bool addStdin = false; - if (!m_args.count(g_argInputFile)) - addStdin = true; - else + if (m_args.count(g_argInputFile)) for (string path: m_args[g_argInputFile].as>()) { auto eq = find(path.begin(), path.end(), '='); @@ -450,6 +448,11 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() } if (addStdin) m_sourceCodes[g_stdinFileName] = dev::readStandardInput(); + if (m_sourceCodes.size() == 0) + { + cerr << "No input files given. If you wish to use the standard input please specify \"-\" explicity." << endl; + return false; + } return true; } -- cgit v1.2.3 From 53eafff4bb3b827d6e2b1d72e290ca9a2969e757 Mon Sep 17 00:00:00 2001 From: alibabe Date: Mon, 21 May 2018 02:21:44 +0000 Subject: Fixes #3718 by creating a local variable for the result of `GasEstimator::breakToStatementLevel` and then assign it back to gasCoast. --- solc/CommandLineInterface.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 89ac8806..5fe75a14 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -990,10 +990,15 @@ void CommandLineInterface::handleAst(string const& _argStr) map gasCosts; // FIXME: shouldn't this be done for every contract? if (m_compiler->runtimeAssemblyItems(m_compiler->lastContractName())) - gasCosts = GasEstimator::breakToStatementLevel( + { + //NOTE: keep the local variable `ret` to prevent a Heisenbug that could happen on certain mac os platform. + //See: https://github.com/ethereum/solidity/issues/3718 for details. + auto ret = GasEstimator::breakToStatementLevel( GasEstimator(m_evmVersion).structuralEstimation(*m_compiler->runtimeAssemblyItems(m_compiler->lastContractName()), asts), asts ); + gasCosts = ret; + } bool legacyFormat = !m_args.count(g_argAstCompactJson); if (m_args.count(g_argOutputDir)) -- cgit v1.2.3 From 2625f282b99076eee6853381cc5d1560241e1988 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 13 Jun 2018 01:00:51 +0100 Subject: Remove obsolete --formal option from CLI --- solc/CommandLineInterface.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 89ac8806..2e4b70e6 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -88,7 +88,6 @@ static string const g_strEVM = "evm"; static string const g_strEVM15 = "evm15"; static string const g_strEVMVersion = "evm-version"; static string const g_streWasm = "ewasm"; -static string const g_strFormal = "formal"; static string const g_strGas = "gas"; static string const g_strHelp = "help"; static string const g_strInputFile = "input-file"; @@ -132,7 +131,6 @@ static string const g_argBinaryRuntime = g_strBinaryRuntime; static string const g_argCloneBinary = g_strCloneBinary; static string const g_argCombinedJson = g_strCombinedJson; static string const g_argCompactJSON = g_strCompactJSON; -static string const g_argFormal = g_strFormal; static string const g_argGas = g_strGas; static string const g_argHelp = g_strHelp; static string const g_argInputFile = g_strInputFile; @@ -216,7 +214,6 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) g_argBinary, g_argBinaryRuntime, g_argCloneBinary, - g_argFormal, g_argMetadata, g_argNatspecUser, g_argNatspecDev, @@ -639,8 +636,7 @@ Allowed options)", (g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.") (g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.") (g_argNatspecDev.c_str(), "Natspec developer documentation of all contracts.") - (g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain.") - (g_argFormal.c_str(), "Translated source suitable for formal analysis. (Deprecated)"); + (g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain."); desc.add(outputComponents); po::options_description allOptions = desc; @@ -1236,9 +1232,6 @@ void CommandLineInterface::outputCompilationResults() handleNatspec(true, contract); handleNatspec(false, contract); } // end of contracts iteration - - if (m_args.count(g_argFormal)) - cerr << "Support for the Why3 output was removed." << endl; } } -- cgit v1.2.3 From ba2a7294d87e8f86d00ddf2755013e96cc320485 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 Jun 2018 18:42:12 +0100 Subject: Renamed the --julia CLI option to --yul --- solc/CommandLineInterface.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 2e4b70e6..4ee939d8 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -92,7 +92,7 @@ static string const g_strGas = "gas"; static string const g_strHelp = "help"; static string const g_strInputFile = "input-file"; static string const g_strInterface = "interface"; -static string const g_strJulia = "julia"; +static string const g_strYul = "yul"; static string const g_strLicense = "license"; static string const g_strLibraries = "libraries"; static string const g_strLink = "link"; @@ -134,7 +134,7 @@ static string const g_argCompactJSON = g_strCompactJSON; static string const g_argGas = g_strGas; static string const g_argHelp = g_strHelp; static string const g_argInputFile = g_strInputFile; -static string const g_argJulia = g_strJulia; +static string const g_argYul = g_strYul; static string const g_argLibraries = g_strLibraries; static string const g_argLink = g_strLink; static string const g_argMachine = g_strMachine; @@ -597,8 +597,8 @@ Allowed options)", "Switch to assembly mode, ignoring all options except --machine and assumes input is assembly." ) ( - g_argJulia.c_str(), - "Switch to JULIA mode, ignoring all options except --machine and assumes input is JULIA." + g_argYul.c_str(), + "Switch to Yul mode, ignoring all options except --machine and assumes input is Yul." ) ( g_argStrictAssembly.c_str(), @@ -607,7 +607,7 @@ Allowed options)", ( g_argMachine.c_str(), po::value()->value_name(boost::join(g_machineArgs, ",")), - "Target machine in assembly or JULIA mode." + "Target machine in assembly or Yul mode." ) ( g_argLink.c_str(), @@ -781,13 +781,13 @@ bool CommandLineInterface::processInput() m_evmVersion = *versionOption; } - if (m_args.count(g_argAssemble) || m_args.count(g_argStrictAssembly) || m_args.count(g_argJulia)) + if (m_args.count(g_argAssemble) || m_args.count(g_argStrictAssembly) || m_args.count(g_argYul)) { // switch to assembly mode m_onlyAssemble = true; using Input = AssemblyStack::Language; using Machine = AssemblyStack::Machine; - Input inputLanguage = m_args.count(g_argJulia) ? Input::JULIA : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly); + Input inputLanguage = m_args.count(g_argYul) ? Input::JULIA : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly); Machine targetMachine = Machine::EVM; if (m_args.count(g_argMachine)) { -- cgit v1.2.3 From 782bc41dbd34a3ed2c5c7074647f039f7a974cdf Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 Jun 2018 18:36:38 +0100 Subject: Rename JULIA/IULIA to Yul in assembly interface --- solc/CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 4ee939d8..8b331c75 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -787,7 +787,7 @@ bool CommandLineInterface::processInput() m_onlyAssemble = true; using Input = AssemblyStack::Language; using Machine = AssemblyStack::Machine; - Input inputLanguage = m_args.count(g_argYul) ? Input::JULIA : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly); + Input inputLanguage = m_args.count(g_argYul) ? Input::Yul : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly); Machine targetMachine = Machine::EVM; if (m_args.count(g_argMachine)) { -- cgit v1.2.3 From 140dbfdbd8f4319d1d02339feea0a8636a3738e5 Mon Sep 17 00:00:00 2001 From: Cryptomental Date: Tue, 10 Jul 2018 09:18:59 +0200 Subject: Code, Changelog, ReleaseChecklist: Fix typos. Refs: #4442 --- solc/CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8b331c75..4811f767 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -447,7 +447,7 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() m_sourceCodes[g_stdinFileName] = dev::readStandardInput(); if (m_sourceCodes.size() == 0) { - cerr << "No input files given. If you wish to use the standard input please specify \"-\" explicity." << endl; + cerr << "No input files given. If you wish to use the standard input please specify \"-\" explicitly." << endl; return false; } -- cgit v1.2.3 From fba7b7c204de14605432ef9669c737eb833cac13 Mon Sep 17 00:00:00 2001 From: Asif Mallik Date: Fri, 27 Jul 2018 15:49:51 +0900 Subject: Fix backslash bug --- solc/CommandLineInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 6a768a00..9bfcc4ef 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -438,7 +438,7 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() continue; } - m_sourceCodes[infile.string()] = dev::readFileAsString(infile.string()); + m_sourceCodes[infile.generic_string()] = dev::readFileAsString(infile.string()); path = boost::filesystem::canonical(infile).string(); } m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename()); @@ -724,7 +724,7 @@ bool CommandLineInterface::processInput() return ReadCallback::Result{false, "Not a valid file."}; auto contents = dev::readFileAsString(canonicalPath.string()); - m_sourceCodes[path.string()] = contents; + m_sourceCodes[path.generic_string()] = contents; return ReadCallback::Result{true, contents}; } catch (Exception const& _exception) -- cgit v1.2.3 From 71e26f6adb7d6b28400a6607570bb1e17da24feb Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Aug 2018 18:32:18 +0200 Subject: Remove clone feature. --- solc/CommandLineInterface.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 6a768a00..55086e9f 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -80,7 +80,6 @@ static string const g_strAstJson = "ast-json"; static string const g_strAstCompactJson = "ast-compact-json"; static string const g_strBinary = "bin"; static string const g_strBinaryRuntime = "bin-runtime"; -static string const g_strCloneBinary = "clone-bin"; static string const g_strCombinedJson = "combined-json"; static string const g_strCompactJSON = "compact-format"; static string const g_strContracts = "contracts"; @@ -128,7 +127,6 @@ static string const g_argAstCompactJson = g_strAstCompactJson; static string const g_argAstJson = g_strAstJson; static string const g_argBinary = g_strBinary; static string const g_argBinaryRuntime = g_strBinaryRuntime; -static string const g_argCloneBinary = g_strCloneBinary; static string const g_argCombinedJson = g_strCombinedJson; static string const g_argCompactJSON = g_strCompactJSON; static string const g_argGas = g_strGas; @@ -161,7 +159,6 @@ static set const g_combinedJsonArgs g_strAst, g_strBinary, g_strBinaryRuntime, - g_strCloneBinary, g_strCompactJSON, g_strInterface, g_strMetadata, @@ -213,7 +210,6 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) g_argAstJson, g_argBinary, g_argBinaryRuntime, - g_argCloneBinary, g_argMetadata, g_argNatspecUser, g_argNatspecDev, @@ -237,16 +233,6 @@ void CommandLineInterface::handleBinary(string const& _contract) cout << m_compiler->object(_contract).toHex() << endl; } } - if (m_args.count(g_argCloneBinary)) - { - if (m_args.count(g_argOutputDir)) - createFile(m_compiler->filesystemFriendlyName(_contract) + ".clone_bin", m_compiler->cloneObject(_contract).toHex()); - else - { - cout << "Clone Binary: " << endl; - cout << m_compiler->cloneObject(_contract).toHex() << endl; - } - } if (m_args.count(g_argBinaryRuntime)) { if (m_args.count(g_argOutputDir)) @@ -275,7 +261,7 @@ void CommandLineInterface::handleBytecode(string const& _contract) { if (m_args.count(g_argOpcodes)) handleOpcode(_contract); - if (m_args.count(g_argBinary) || m_args.count(g_argCloneBinary) || m_args.count(g_argBinaryRuntime)) + if (m_args.count(g_argBinary) || m_args.count(g_argBinaryRuntime)) handleBinary(_contract); } @@ -631,7 +617,6 @@ Allowed options)", (g_argOpcodes.c_str(), "Opcodes of the contracts.") (g_argBinary.c_str(), "Binary of the contracts in hex.") (g_argBinaryRuntime.c_str(), "Binary of the runtime part of the contracts in hex.") - (g_argCloneBinary.c_str(), "Binary of the clone contracts in hex.") (g_argAbi.c_str(), "ABI specification of the contracts.") (g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.") (g_argNatspecUser.c_str(), "Natspec user documentation of all contracts.") @@ -910,8 +895,6 @@ void CommandLineInterface::handleCombinedJSON() contractData[g_strBinary] = m_compiler->object(contractName).toHex(); if (requests.count(g_strBinaryRuntime)) contractData[g_strBinaryRuntime] = m_compiler->runtimeObject(contractName).toHex(); - if (requests.count(g_strCloneBinary)) - contractData[g_strCloneBinary] = m_compiler->cloneObject(contractName).toHex(); if (requests.count(g_strOpcodes)) contractData[g_strOpcodes] = solidity::disassemble(m_compiler->object(contractName).bytecode); if (requests.count(g_strAsm)) -- cgit v1.2.3 From 39ffd7500e68e1603cead1a8473c1fb990fbab8f Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 6 Aug 2018 18:52:49 +0200 Subject: solc: Fixes double-quoting path names on stderr and adds tests for it. Before it was possible to get a failure message, such as: ""notfound.sol"" is not found whereas it should be: "notfound.sol" is not found. --- solc/CommandLineInterface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 6a768a00..6dd8fac0 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -416,11 +416,11 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() { if (!ignoreMissing) { - cerr << "\"" << infile << "\" is not found" << endl; + cerr << infile << " is not found." << endl; return false; } else - cerr << "\"" << infile << "\" is not found. Skipping." << endl; + cerr << infile << " is not found. Skipping." << endl; continue; } @@ -429,11 +429,11 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() { if (!ignoreMissing) { - cerr << "\"" << infile << "\" is not a valid file" << endl; + cerr << infile << " is not a valid file." << endl; return false; } else - cerr << "\"" << infile << "\" is not a valid file. Skipping." << endl; + cerr << infile << " is not a valid file. Skipping." << endl; continue; } -- cgit v1.2.3 From 954d7433bd8c10bce917326f70070077f0cfc165 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 9 Aug 2018 20:37:49 +0200 Subject: Disallow remappings with empty prefix. --- solc/CommandLineInterface.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 429bd637..f7d1c748 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -392,7 +392,18 @@ bool CommandLineInterface::readInputFilesAndConfigureRemappings() { auto eq = find(path.begin(), path.end(), '='); if (eq != path.end()) - path = string(eq + 1, path.end()); + { + if (auto r = CompilerStack::parseRemapping(path)) + { + m_remappings.emplace_back(std::move(*r)); + path = string(eq + 1, path.end()); + } + else + { + cerr << "Invalid remapping: \"" << path << "\"." << endl; + return false; + } + } else if (path == "-") addStdin = true; else @@ -808,7 +819,7 @@ bool CommandLineInterface::processInput() if (m_args.count(g_argMetadataLiteral) > 0) m_compiler->useMetadataLiteralSources(true); if (m_args.count(g_argInputFile)) - m_compiler->setRemappings(m_args[g_argInputFile].as>()); + m_compiler->setRemappings(m_remappings); for (auto const& sourceCode: m_sourceCodes) m_compiler->addSource(sourceCode.first, sourceCode.second); if (m_args.count(g_argLibraries)) -- cgit v1.2.3 From 24e5dcc352e9ce9569138dfa5af96fbf72ad3604 Mon Sep 17 00:00:00 2001 From: liangdzou Date: Wed, 19 Sep 2018 00:04:11 +0800 Subject: fix code format problems --- solc/CommandLineInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index f7d1c748..a43e789e 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -742,7 +742,8 @@ bool CommandLineInterface::processInput() // path will have it's last component set to '.'. This breaks // path comparison in later parts of the code, so we need to strip // it. - if (filesystem_path.filename() == ".") { + if (filesystem_path.filename() == ".") + { filesystem_path.remove_filename(); } m_allowedDirectories.push_back(filesystem_path); -- cgit v1.2.3 From 6f7ff2dcd4e4cc83a76c8e79993682408da0b774 Mon Sep 17 00:00:00 2001 From: liangdzou Date: Thu, 20 Sep 2018 17:41:59 +0800 Subject: fix format issue for source files --- solc/CommandLineInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index a43e789e..8fd0d6ef 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -736,7 +736,8 @@ bool CommandLineInterface::processInput() if (m_args.count(g_argAllowPaths)) { vector paths; - for (string const& path: boost::split(paths, m_args[g_argAllowPaths].as(), boost::is_any_of(","))) { + for (string const& path: boost::split(paths, m_args[g_argAllowPaths].as(), boost::is_any_of(","))) + { auto filesystem_path = boost::filesystem::path(path); // If the given path had a trailing slash, the Boost filesystem // path will have it's last component set to '.'. This breaks -- cgit v1.2.3 From 6daeb39ecc7ffd0e834e63f6495442c4211c5c1c Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 4 Oct 2018 14:55:02 +0200 Subject: Use hash for library placeholders. --- solc/CommandLineInterface.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8fd0d6ef..7ab76c12 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -226,21 +226,21 @@ void CommandLineInterface::handleBinary(string const& _contract) if (m_args.count(g_argBinary)) { if (m_args.count(g_argOutputDir)) - createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin", m_compiler->object(_contract).toHex()); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin", objectWithLinkRefsHex(m_compiler->object(_contract))); else { cout << "Binary: " << endl; - cout << m_compiler->object(_contract).toHex() << endl; + cout << objectWithLinkRefsHex(m_compiler->object(_contract)) << endl; } } if (m_args.count(g_argBinaryRuntime)) { if (m_args.count(g_argOutputDir)) - createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin-runtime", m_compiler->runtimeObject(_contract).toHex()); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin-runtime", objectWithLinkRefsHex(m_compiler->runtimeObject(_contract))); else { cout << "Binary of the runtime part: " << endl; - cout << m_compiler->runtimeObject(_contract).toHex() << endl; + cout << objectWithLinkRefsHex(m_compiler->runtimeObject(_contract)) << endl; } } } @@ -1056,8 +1056,12 @@ bool CommandLineInterface::link() { string const& name = library.first; // Library placeholders are 40 hex digits (20 bytes) that start and end with '__'. - // This leaves 36 characters for the library name, while too short library names are - // padded on the right with '_' and too long names are truncated. + // This leaves 36 characters for the library identifier. The identifier used to + // be just the cropped or '_'-padded library name, but this changed to + // the cropped hex representation of the hash of the library name. + // We support both ways of linking here. + librariesReplacements["__" + eth::LinkerObject::libraryPlaceholder(name) + "__"] = library.second; + string replacement = "__"; for (size_t i = 0; i < placeholderSize - 4; ++i) replacement.push_back(i < name.size() ? name[i] : '_'); @@ -1087,6 +1091,11 @@ bool CommandLineInterface::link() cerr << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl; it += placeholderSize; } + // Remove hints for resolved libraries. + for (auto const& library: m_libraries) + boost::algorithm::erase_all(src.second, "\n" + libraryPlaceholderHint(library.first)); + while (!src.second.empty() && *prev(src.second.end()) == '\n') + src.second.resize(src.second.size() - 1); } return true; } @@ -1100,6 +1109,23 @@ void CommandLineInterface::writeLinkedFiles() writeFile(src.first, src.second); } +string CommandLineInterface::libraryPlaceholderHint(string const& _libraryName) +{ + return "// " + eth::LinkerObject::libraryPlaceholder(_libraryName) + " -> " + _libraryName; +} + +string CommandLineInterface::objectWithLinkRefsHex(eth::LinkerObject const& _obj) +{ + string out = _obj.toHex(); + if (!_obj.linkReferences.empty()) + { + out += "\n"; + for (auto const& linkRef: _obj.linkReferences) + out += "\n" + libraryPlaceholderHint(linkRef.second); + } + return out; +} + bool CommandLineInterface::assemble( AssemblyStack::Language _language, AssemblyStack::Machine _targetMachine -- cgit v1.2.3 From 95d3e7feb39e896bf499e816a8cf037b7fdff62d Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 8 Oct 2018 22:31:08 +0200 Subject: More helpful error messages for linker. --- solc/CommandLineInterface.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 7ab76c12..4052ed13 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -482,9 +482,23 @@ bool CommandLineInterface::parseLibraryOption(string const& _input) string addrString(lib.begin() + colon + 1, lib.end()); boost::trim(libName); boost::trim(addrString); + if (addrString.substr(0, 2) == "0x") + addrString = addrString.substr(2); + if (addrString.empty()) + { + cerr << "Empty address provided for library \"" << libName << "\": " << endl; + cerr << "Note that there should not be any whitespace after the colon." << endl; + return false; + } + else if (addrString.length() != 40) + { + cerr << "Invalid length for address for library \"" << libName << "\": " << addrString.length() << " instead of 40 characters." << endl; + return false; + } if (!passesAddressChecksum(addrString, false)) { - cerr << "Invalid checksum on library address \"" << libName << "\": " << addrString << endl; + cerr << "Invalid checksum on address for library \"" << libName << "\": " << addrString << endl; + cerr << "The correct checksum is " << dev::getChecksummedAddress(addrString) << endl; return false; } bytes binAddr = fromHex(addrString); @@ -569,7 +583,7 @@ Allowed options)", g_argLibraries.c_str(), po::value>()->value_name("libs"), "Direct string or file containing library addresses. Syntax: " - ":
[, or whitespace] ...\n" + ":
[, or whitespace] ...\n" "Address is interpreted as a hex string optionally prefixed by 0x." ) ( -- cgit v1.2.3 From 9f9d6fdcc48bfbc1c039c903d60aa38a166c1850 Mon Sep 17 00:00:00 2001 From: mestorlx Date: Mon, 15 Oct 2018 12:54:48 -0300 Subject: fix issue##5007 --- solc/CommandLineInterface.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 4052ed13..e0c6a2b6 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -994,16 +994,14 @@ void CommandLineInterface::handleAst(string const& _argStr) for (auto const& sourceCode: m_sourceCodes) asts.push_back(&m_compiler->ast(sourceCode.first)); map gasCosts; - // FIXME: shouldn't this be done for every contract? - if (m_compiler->runtimeAssemblyItems(m_compiler->lastContractName())) + for (auto const& contract : m_compiler->contractNames()) { - //NOTE: keep the local variable `ret` to prevent a Heisenbug that could happen on certain mac os platform. - //See: https://github.com/ethereum/solidity/issues/3718 for details. auto ret = GasEstimator::breakToStatementLevel( - GasEstimator(m_evmVersion).structuralEstimation(*m_compiler->runtimeAssemblyItems(m_compiler->lastContractName()), asts), + GasEstimator(m_evmVersion).structuralEstimation(*m_compiler->runtimeAssemblyItems(contract), asts), asts ); - gasCosts = ret; + for (auto const& it: ret) + gasCosts[it.first] += it.second; } bool legacyFormat = !m_args.count(g_argAstCompactJson); -- cgit v1.2.3 From 0690aae09d1591b65d6808e6c6c547b63ddb3ce9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 18 Oct 2018 00:48:07 +0200 Subject: Remove mostly unused writeFile implementation. --- solc/CommandLineInterface.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'solc/CommandLineInterface.cpp') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index e0c6a2b6..844cef90 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1118,7 +1118,15 @@ void CommandLineInterface::writeLinkedFiles() if (src.first == g_stdinFileName) cout << src.second << endl; else - writeFile(src.first, src.second); + { + ofstream outFile(src.first); + outFile << src.second; + if (!outFile) + { + cerr << "Could not write to file " << src.first << ". Aborting." << endl; + return; + } + } } string CommandLineInterface::libraryPlaceholderHint(string const& _libraryName) -- cgit v1.2.3