2014-12-09 12:43:08 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2014-12-09 12:43:08 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-12-09 12:43:08 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-12-09 12:43:08 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-12-09 12:43:08 +00:00
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2014-12-09 12:43:08 +00:00
|
|
|
/**
|
|
|
|
* @author Lefteris <lefteris@ethdev.com>
|
|
|
|
* @date 2014
|
2014-12-09 16:39:34 +00:00
|
|
|
* Solidity command line interface.
|
2014-12-09 12:43:08 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-06-07 10:33:04 +00:00
|
|
|
#include <solc/CommandLineParser.h>
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
#include <libsolidity/interface/CompilerStack.h>
|
2019-09-18 14:44:36 +00:00
|
|
|
#include <libsolidity/interface/DebugSettings.h>
|
2021-04-06 14:12:06 +00:00
|
|
|
#include <libsolidity/interface/FileReader.h>
|
2019-02-13 11:07:20 +00:00
|
|
|
#include <libyul/AssemblyStack.h>
|
2017-01-26 12:47:57 +00:00
|
|
|
|
2021-06-10 18:08:53 +00:00
|
|
|
#include <iostream>
|
2017-01-26 12:47:57 +00:00
|
|
|
#include <memory>
|
2021-06-07 10:33:04 +00:00
|
|
|
#include <string>
|
2017-01-26 12:47:57 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2014-12-09 12:43:08 +00:00
|
|
|
{
|
|
|
|
|
2014-12-09 16:39:34 +00:00
|
|
|
class CommandLineInterface
|
2014-12-09 12:43:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-06-10 18:08:53 +00:00
|
|
|
explicit CommandLineInterface(
|
2021-06-16 19:12:27 +00:00
|
|
|
std::istream& _sin,
|
2021-06-10 18:08:53 +00:00
|
|
|
std::ostream& _sout,
|
|
|
|
std::ostream& _serr,
|
|
|
|
CommandLineOptions const& _options = CommandLineOptions{}
|
|
|
|
):
|
2021-06-16 19:12:27 +00:00
|
|
|
m_sin(_sin),
|
2021-06-10 18:08:53 +00:00
|
|
|
m_sout(_sout),
|
|
|
|
m_serr(_serr),
|
2021-06-07 10:33:04 +00:00
|
|
|
m_options(_options)
|
|
|
|
{}
|
|
|
|
|
2014-12-09 16:39:34 +00:00
|
|
|
/// Parse command line arguments and return false if we should not continue
|
2021-06-07 10:33:04 +00:00
|
|
|
bool parseArguments(int _argc, char const* const* _argv);
|
2021-06-13 13:53:16 +00:00
|
|
|
/// Read the content of all input files and initialize the file reader.
|
|
|
|
bool readInputFiles();
|
2014-12-09 16:39:34 +00:00
|
|
|
/// Parse the files and create source code objects
|
|
|
|
bool processInput();
|
|
|
|
/// Perform actions on the input depending on provided compiler arguments
|
2017-03-10 18:11:01 +00:00
|
|
|
/// @returns true on success.
|
|
|
|
bool actOnInput();
|
2014-12-09 12:43:08 +00:00
|
|
|
|
2021-06-07 10:33:04 +00:00
|
|
|
CommandLineOptions const& options() const { return m_options; }
|
|
|
|
FileReader const& fileReader() const { return m_fileReader; }
|
2021-06-13 13:53:16 +00:00
|
|
|
std::optional<std::string> const& standardJsonInput() const { return m_standardJsonInput; }
|
2021-06-07 10:33:04 +00:00
|
|
|
|
2014-12-09 12:43:08 +00:00
|
|
|
private:
|
2021-06-07 10:33:04 +00:00
|
|
|
bool compile();
|
2015-09-11 17:35:01 +00:00
|
|
|
bool link();
|
|
|
|
void writeLinkedFiles();
|
2018-10-04 12:55:02 +00:00
|
|
|
/// @returns the ``// <identifier> -> name`` hint for library placeholders.
|
|
|
|
static std::string libraryPlaceholderHint(std::string const& _libraryName);
|
|
|
|
/// @returns the full object with library placeholder hints in hex.
|
2019-12-11 16:31:36 +00:00
|
|
|
static std::string objectWithLinkRefsHex(evmasm::LinkerObject const& _obj);
|
2015-09-11 17:35:01 +00:00
|
|
|
|
2020-05-08 16:20:14 +00:00
|
|
|
bool assemble(
|
|
|
|
yul::AssemblyStack::Language _language,
|
|
|
|
yul::AssemblyStack::Machine _targetMachine,
|
|
|
|
bool _optimize,
|
2021-07-28 15:53:19 +00:00
|
|
|
std::optional<unsigned int> _expectedExecutionsPerDeployment = std::nullopt,
|
2020-05-08 16:20:14 +00:00
|
|
|
std::optional<std::string> _yulOptimiserSteps = std::nullopt
|
|
|
|
);
|
2016-02-22 01:13:41 +00:00
|
|
|
|
2015-09-11 17:35:01 +00:00
|
|
|
void outputCompilationResults();
|
|
|
|
|
2015-04-23 12:40:42 +00:00
|
|
|
void handleCombinedJSON();
|
2020-11-20 14:35:53 +00:00
|
|
|
void handleAst();
|
2014-12-09 19:29:29 +00:00
|
|
|
void handleBinary(std::string const& _contract);
|
|
|
|
void handleOpcode(std::string const& _contract);
|
2019-03-04 22:26:46 +00:00
|
|
|
void handleIR(std::string const& _contract);
|
2020-02-26 14:50:34 +00:00
|
|
|
void handleIROptimized(std::string const& _contract);
|
2019-12-09 16:36:12 +00:00
|
|
|
void handleEwasm(std::string const& _contract);
|
2014-12-09 19:29:29 +00:00
|
|
|
void handleBytecode(std::string const& _contract);
|
2015-05-04 14:21:44 +00:00
|
|
|
void handleSignatureHashes(std::string const& _contract);
|
2017-05-19 15:10:32 +00:00
|
|
|
void handleMetadata(std::string const& _contract);
|
2017-05-06 17:02:56 +00:00
|
|
|
void handleABI(std::string const& _contract);
|
2017-07-27 10:28:04 +00:00
|
|
|
void handleNatspec(bool _natspecDev, std::string const& _contract);
|
2015-05-22 12:19:58 +00:00
|
|
|
void handleGasEstimation(std::string const& _contract);
|
2020-03-24 12:22:25 +00:00
|
|
|
void handleStorageLayout(std::string const& _contract);
|
2014-12-09 12:43:08 +00:00
|
|
|
|
2019-09-11 19:16:35 +00:00
|
|
|
/// Tries to read @ m_sourceCodes as a JSONs holding ASTs
|
|
|
|
/// such that they can be imported into the compiler (importASTs())
|
|
|
|
/// (produced by --combined-json ast,compact-format <file.sol>
|
|
|
|
/// or standard-json output
|
|
|
|
std::map<std::string, Json::Value> parseAstFromInput();
|
|
|
|
|
2015-07-20 16:14:25 +00:00
|
|
|
/// Create a file in the given directory
|
|
|
|
/// @arg _fileName the name of the file
|
|
|
|
/// @arg _data to be written
|
2015-07-21 13:29:15 +00:00
|
|
|
void createFile(std::string const& _fileName, std::string const& _data);
|
2015-07-20 16:14:25 +00:00
|
|
|
|
2017-05-22 20:39:38 +00:00
|
|
|
/// Create a json file in the given directory
|
|
|
|
/// @arg _fileName the name of the file (the extension will be replaced with .json)
|
2017-07-03 23:46:30 +00:00
|
|
|
/// @arg _json json string to be written
|
|
|
|
void createJson(std::string const& _fileName, std::string const& _json);
|
2017-05-22 20:39:38 +00:00
|
|
|
|
2021-06-10 18:08:53 +00:00
|
|
|
/// Returns the stream that should receive normal output. Sets m_hasOutput to true if the
|
|
|
|
/// stream has ever been used unless @arg _markAsUsed is set to false.
|
|
|
|
std::ostream& sout(bool _markAsUsed = true);
|
|
|
|
|
|
|
|
/// Returns the stream that should receive error output. Sets m_hasOutput to true if the
|
|
|
|
/// stream has ever been used unless @arg _markAsUsed is set to false.
|
|
|
|
std::ostream& serr(bool _markAsUsed = true);
|
|
|
|
|
2021-06-16 19:12:27 +00:00
|
|
|
std::istream& m_sin;
|
2021-06-10 18:08:53 +00:00
|
|
|
std::ostream& m_sout;
|
|
|
|
std::ostream& m_serr;
|
|
|
|
bool m_hasOutput = false;
|
2017-03-10 18:11:01 +00:00
|
|
|
bool m_error = false; ///< If true, some error occurred.
|
2021-04-06 14:12:06 +00:00
|
|
|
FileReader m_fileReader;
|
2021-06-13 13:53:16 +00:00
|
|
|
std::optional<std::string> m_standardJsonInput;
|
2019-12-11 16:31:36 +00:00
|
|
|
std::unique_ptr<frontend::CompilerStack> m_compiler;
|
2021-06-07 10:33:04 +00:00
|
|
|
CommandLineOptions m_options;
|
2014-12-09 12:43:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|