mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
CommandLineInterface: Add asserts documenting which function is expected to work in which input modes
This commit is contained in:
parent
d7ddfcc665
commit
13571f4a67
@ -154,6 +154,8 @@ static bool coloredOutput(CommandLineOptions const& _options)
|
|||||||
|
|
||||||
void CommandLineInterface::handleBinary(string const& _contract)
|
void CommandLineInterface::handleBinary(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (m_options.compiler.outputs.binary)
|
if (m_options.compiler.outputs.binary)
|
||||||
{
|
{
|
||||||
if (!m_options.output.dir.empty())
|
if (!m_options.output.dir.empty())
|
||||||
@ -178,6 +180,8 @@ void CommandLineInterface::handleBinary(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleOpcode(string const& _contract)
|
void CommandLineInterface::handleOpcode(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.output.dir.empty())
|
if (!m_options.output.dir.empty())
|
||||||
createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", evmasm::disassemble(m_compiler->object(_contract).bytecode));
|
createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", evmasm::disassemble(m_compiler->object(_contract).bytecode));
|
||||||
else
|
else
|
||||||
@ -190,6 +194,8 @@ void CommandLineInterface::handleOpcode(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleIR(string const& _contractName)
|
void CommandLineInterface::handleIR(string const& _contractName)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.ir)
|
if (!m_options.compiler.outputs.ir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -204,6 +210,8 @@ void CommandLineInterface::handleIR(string const& _contractName)
|
|||||||
|
|
||||||
void CommandLineInterface::handleIROptimized(string const& _contractName)
|
void CommandLineInterface::handleIROptimized(string const& _contractName)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.irOptimized)
|
if (!m_options.compiler.outputs.irOptimized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -218,6 +226,8 @@ void CommandLineInterface::handleIROptimized(string const& _contractName)
|
|||||||
|
|
||||||
void CommandLineInterface::handleEwasm(string const& _contractName)
|
void CommandLineInterface::handleEwasm(string const& _contractName)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.ewasm)
|
if (!m_options.compiler.outputs.ewasm)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -239,6 +249,8 @@ void CommandLineInterface::handleEwasm(string const& _contractName)
|
|||||||
|
|
||||||
void CommandLineInterface::handleBytecode(string const& _contract)
|
void CommandLineInterface::handleBytecode(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (m_options.compiler.outputs.opcodes)
|
if (m_options.compiler.outputs.opcodes)
|
||||||
handleOpcode(_contract);
|
handleOpcode(_contract);
|
||||||
if (m_options.compiler.outputs.binary || m_options.compiler.outputs.binaryRuntime)
|
if (m_options.compiler.outputs.binary || m_options.compiler.outputs.binaryRuntime)
|
||||||
@ -247,6 +259,8 @@ void CommandLineInterface::handleBytecode(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleSignatureHashes(string const& _contract)
|
void CommandLineInterface::handleSignatureHashes(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.signatureHashes)
|
if (!m_options.compiler.outputs.signatureHashes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -263,6 +277,8 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleMetadata(string const& _contract)
|
void CommandLineInterface::handleMetadata(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.metadata)
|
if (!m_options.compiler.outputs.metadata)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -275,6 +291,8 @@ void CommandLineInterface::handleMetadata(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleABI(string const& _contract)
|
void CommandLineInterface::handleABI(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.abi)
|
if (!m_options.compiler.outputs.abi)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -287,6 +305,8 @@ void CommandLineInterface::handleABI(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleStorageLayout(string const& _contract)
|
void CommandLineInterface::handleStorageLayout(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.storageLayout)
|
if (!m_options.compiler.outputs.storageLayout)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -299,6 +319,8 @@ void CommandLineInterface::handleStorageLayout(string const& _contract)
|
|||||||
|
|
||||||
void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contract)
|
void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
std::string suffix;
|
std::string suffix;
|
||||||
std::string title;
|
std::string title;
|
||||||
@ -339,6 +361,8 @@ void CommandLineInterface::handleNatspec(bool _natspecDev, string const& _contra
|
|||||||
|
|
||||||
void CommandLineInterface::handleGasEstimation(string const& _contract)
|
void CommandLineInterface::handleGasEstimation(string const& _contract)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
Json::Value estimates = m_compiler->gasEstimates(_contract);
|
Json::Value estimates = m_compiler->gasEstimates(_contract);
|
||||||
sout() << "Gas estimation:" << endl;
|
sout() << "Gas estimation:" << endl;
|
||||||
|
|
||||||
@ -465,6 +489,8 @@ bool CommandLineInterface::readInputFiles()
|
|||||||
|
|
||||||
map<string, Json::Value> CommandLineInterface::parseAstFromInput()
|
map<string, Json::Value> CommandLineInterface::parseAstFromInput()
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
map<string, Json::Value> sourceJsons;
|
map<string, Json::Value> sourceJsons;
|
||||||
map<string, string> tmpSources;
|
map<string, string> tmpSources;
|
||||||
|
|
||||||
@ -711,6 +737,8 @@ bool CommandLineInterface::compile()
|
|||||||
|
|
||||||
void CommandLineInterface::handleCombinedJSON()
|
void CommandLineInterface::handleCombinedJSON()
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.combinedJsonRequests.has_value())
|
if (!m_options.compiler.combinedJsonRequests.has_value())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -801,6 +829,8 @@ void CommandLineInterface::handleCombinedJSON()
|
|||||||
|
|
||||||
void CommandLineInterface::handleAst()
|
void CommandLineInterface::handleAst()
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
if (!m_options.compiler.outputs.astCompactJson)
|
if (!m_options.compiler.outputs.astCompactJson)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -848,6 +878,8 @@ bool CommandLineInterface::actOnInput()
|
|||||||
|
|
||||||
bool CommandLineInterface::link()
|
bool CommandLineInterface::link()
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Linker, "");
|
||||||
|
|
||||||
// Map from how the libraries will be named inside the bytecode to their addresses.
|
// Map from how the libraries will be named inside the bytecode to their addresses.
|
||||||
map<string, h160> librariesReplacements;
|
map<string, h160> librariesReplacements;
|
||||||
int const placeholderSize = 40; // 20 bytes or 40 hex characters
|
int const placeholderSize = 40; // 20 bytes or 40 hex characters
|
||||||
@ -911,6 +943,8 @@ bool CommandLineInterface::link()
|
|||||||
|
|
||||||
void CommandLineInterface::writeLinkedFiles()
|
void CommandLineInterface::writeLinkedFiles()
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Linker, "");
|
||||||
|
|
||||||
for (auto const& src: m_fileReader.sourceCodes())
|
for (auto const& src: m_fileReader.sourceCodes())
|
||||||
if (src.first == g_stdinFileName)
|
if (src.first == g_stdinFileName)
|
||||||
sout() << src.second << endl;
|
sout() << src.second << endl;
|
||||||
@ -946,6 +980,8 @@ string CommandLineInterface::objectWithLinkRefsHex(evmasm::LinkerObject const& _
|
|||||||
|
|
||||||
bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine)
|
bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine)
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Assembler, "");
|
||||||
|
|
||||||
bool successful = true;
|
bool successful = true;
|
||||||
map<string, yul::AssemblyStack> assemblyStacks;
|
map<string, yul::AssemblyStack> assemblyStacks;
|
||||||
for (auto const& src: m_fileReader.sourceCodes())
|
for (auto const& src: m_fileReader.sourceCodes())
|
||||||
@ -1088,6 +1124,8 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
|
|||||||
|
|
||||||
void CommandLineInterface::outputCompilationResults()
|
void CommandLineInterface::outputCompilationResults()
|
||||||
{
|
{
|
||||||
|
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, "");
|
||||||
|
|
||||||
handleCombinedJSON();
|
handleCombinedJSON();
|
||||||
|
|
||||||
// do we need AST output?
|
// do we need AST output?
|
||||||
|
Loading…
Reference in New Issue
Block a user