From d6b28af7e2aff0c978bb1d612ad75972b32a56a1 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 16 Jul 2015 15:51:05 +0200 Subject: [PATCH 01/13] added -o flag. todo: options should be removed from the components --- CommandLineInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index e579d8839..8d76df4a5 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -335,8 +335,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) po::value()->value_name(boost::join(g_combinedJsonArgs, ",")), "Output a single json document containing the specified information, can be combined." ) - (g_argAstStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the AST of the contract.") + ("output-dir,o", po::value>()->composing(), "Output directory path") + (g_argAstStr.c_str(), "Request to output the AST of the contract.") (g_argAstJson.c_str(), po::value()->value_name("stdout|file|both"), "Request to output the AST of the contract in JSON format.") (g_argAsmStr.c_str(), po::value()->value_name("stdout|file|both"), From 286473247eccd4fb6b5e57be1bec3861c4c1bf2d Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 12:40:02 +0200 Subject: [PATCH 02/13] added -o option to cmd compiler Conflicts: solc/CommandLineInterface.cpp --- CommandLineInterface.cpp | 201 +++++++++++++++++---------------------- 1 file changed, 86 insertions(+), 115 deletions(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index 8d76df4a5..2b00e7c9f 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -95,7 +95,7 @@ static void version() static inline bool humanTargetedStdout(po::variables_map const& _args, string const& _name) { - return _args.count(_name) && _args[_name].as() != OutputType::FILE; + return _args.count(_name) && !(_args.count("output-dir")); } static bool needsHumanTargetedStdout(po::variables_map const& _args) @@ -116,79 +116,62 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) humanTargetedStdout(_args, g_argCloneBinaryStr); } -static inline bool outputToFile(OutputType type) -{ - return type == OutputType::FILE || type == OutputType::BOTH; -} - -static inline bool outputToStdout(OutputType type) -{ - return type == OutputType::STDOUT || type == OutputType::BOTH; -} - -static std::istream& operator>>(std::istream& _in, OutputType& io_output) -{ - std::string token; - _in >> token; - if (token == "stdout") - io_output = OutputType::STDOUT; - else if (token == "file") - io_output = OutputType::FILE; - else if (token == "both") - io_output = OutputType::BOTH; - else - throw boost::program_options::invalid_option_value(token); - return _in; -} - void CommandLineInterface::handleBinary(string const& _contract) { if (m_args.count(g_argBinaryStr)) { - if (outputToStdout(m_args[g_argBinaryStr].as())) - { - cout << "Binary: " << endl; - cout << toHex(m_compiler->getBytecode(_contract)) << endl; - } - if (outputToFile(m_args[g_argBinaryStr].as())) + if (m_args.count("output-dir")) { ofstream outFile(_contract + ".binary"); outFile << toHex(m_compiler->getBytecode(_contract)); outFile.close(); } + else + { + cout << "Binary: " << endl; + cout << toHex(m_compiler->getBytecode(_contract)) << endl; + } + } if (m_args.count(g_argCloneBinaryStr)) { - if (outputToStdout(m_args[g_argCloneBinaryStr].as())) - { - cout << "Clone Binary: " << endl; - cout << toHex(m_compiler->getCloneBytecode(_contract)) << endl; - } if (outputToFile(m_args[g_argCloneBinaryStr].as())) { ofstream outFile(_contract + ".clone_binary"); outFile << toHex(m_compiler->getCloneBytecode(_contract)); outFile.close(); } + else + { + cout << "Clone Binary: " << endl; + cout << toHex(m_compiler->getCloneBytecode(_contract)) << endl; + } + } + else + { + cout << "Binary: " << endl; + cout << toHex(m_compiler->getBytecode(_contract)) << endl; + } + } void CommandLineInterface::handleOpcode(string const& _contract) { - auto choice = m_args[g_argOpcodesStr].as(); - if (outputToStdout(choice)) + //auto choice = m_args[g_argOpcodesStr].as(); + if (m_args.count("output-dir")) + { + ofstream outFile(_contract + ".opcode"); + outFile << eth::disassemble(m_compiler->getBytecode(_contract)); + outFile.close(); + } + else { cout << "Opcodes: " << endl; cout << eth::disassemble(m_compiler->getBytecode(_contract)); cout << endl; } - if (outputToFile(choice)) - { - ofstream outFile(_contract + ".opcode"); - outFile << eth::disassemble(m_compiler->getBytecode(_contract)); - outFile.close(); - } } void CommandLineInterface::handleBytecode(string const& _contract) @@ -208,16 +191,15 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract) for (auto const& it: m_compiler->getContractDefinition(_contract).getInterfaceFunctions()) out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n"; - auto choice = m_args[g_argSignatureHashes].as(); - if (outputToStdout(choice)) - cout << "Function signatures: " << endl << out; - - if (outputToFile(choice)) + //auto choice = m_args[g_argSignatureHashes].as(); + if (m_args.count("output-dir")) { ofstream outFile(_contract + ".signatures"); outFile << out; outFile.close(); } + else + cout << "Function signatures: " << endl << out; } void CommandLineInterface::handleMeta(DocumentationType _type, string const& _contract) @@ -254,19 +236,19 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co if (m_args.count(argName)) { - auto choice = m_args[argName].as(); - if (outputToStdout(choice)) - { - cout << title << endl; - cout << m_compiler->getMetadata(_contract, _type) << endl; - } - - if (outputToFile(choice)) + //auto choice = m_args[argName].as(); + if (m_args.count("output-dir")) { ofstream outFile(_contract + suffix); outFile << m_compiler->getMetadata(_contract, _type); outFile.close(); } + else + { + cout << title << endl; + cout << m_compiler->getMetadata(_contract, _type) << endl; + } + } } @@ -335,47 +317,36 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) po::value()->value_name(boost::join(g_combinedJsonArgs, ",")), "Output a single json document containing the specified information, can be combined." ) - ("output-dir,o", po::value>()->composing(), "Output directory path") + ("o,output-dir", po::value(), "Output directory path") (g_argAstStr.c_str(), "Request to output the AST of the contract.") - (g_argAstJson.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the AST of the contract in JSON format.") - (g_argAsmStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the EVM assembly of the contract.") - (g_argAsmJsonStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the EVM assembly of the contract in JSON format.") - (g_argOpcodesStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the Opcodes of the contract.") - (g_argBinaryStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract in binary (hexadecimal).") - (g_argCloneBinaryStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the clone contract in binary (hexadecimal).") - (g_argAbiStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's JSON ABI interface.") - (g_argSolAbiStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's Solidity ABI interface.") - (g_argSignatureHashes.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's functions' signature hashes.") - (g_argGas.c_str(), - "Request to output an estimate for each function's maximal gas usage.") - (g_argNatspecUserStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's Natspec user documentation.") - (g_argNatspecDevStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's Natspec developer documentation."); + (g_argAstJson.c_str(), "Request to output the AST of the contract in JSON format.") + (g_argAsmStr.c_str(), "Request to output the EVM assembly of the contract.") + (g_argAsmJsonStr.c_str(), "Request to output the EVM assembly of the contract in JSON format.") + (g_argOpcodesStr.c_str(), "Request to output the Opcodes of the contract.") + (g_argBinaryStr.c_str(), "Request to output the contract in binary (hexadecimal).") + (g_argCloneBinaryStr.c_str(), "Request to output the clone contract in binary (hexadecimal).") + (g_argAbiStr.c_str(), "Request to output the contract's JSON ABI interface.") + (g_argSolAbiStr.c_str(), "Request to output the contract's Solidity ABI interface.") + (g_argSignatureHashes.c_str(), "Request to output the contract's functions' signature hashes.") + (g_argGas.c_str(), "Request to output an estimate for each function's maximal gas usage.") + (g_argNatspecUserStr.c_str(), "Request to output the contract's Natspec user documentation.") + (g_argNatspecDevStr.c_str(), "Request to output the contract's Natspec developer documentation."); // All positional options should be interpreted as input files - po::positional_options_description p; - p.add("input-file", -1); + po::positional_options_description inputFileNamePosition; + inputFileNamePosition.add("input-file", -1); // parse the compiler arguments try { - po::store(po::command_line_parser(argc, argv).options(desc).positional(p).allow_unregistered().run(), m_args); + po::store(po::command_line_parser(argc, argv).options(desc).positional(inputFileNamePosition).allow_unregistered().run(), m_args); } catch (po::error const& _exception) { cerr << _exception.what() << endl; return false; } + if (m_args.count("combined-json")) { vector requests; @@ -563,8 +534,28 @@ void CommandLineInterface::handleAst(string const& _argStr) asts ); - auto choice = m_args[_argStr].as(); - if (outputToStdout(choice)) +// auto choice = m_args[_argStr].as(); + + if (m_args.count("output-dir")) + { + for (auto const& sourceCode: m_sourceCodes) + { + boost::filesystem::path p(sourceCode.first); + ofstream outFile(p.stem().string() + ".ast"); + if (_argStr == g_argAstStr) + { + ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second); + printer.print(outFile); + } + else + { + ASTJsonConverter converter(m_compiler->getAST(sourceCode.first)); + converter.print(outFile); + } + outFile.close(); + } + } + else { cout << title << endl << endl; for (auto const& sourceCode: m_sourceCodes) @@ -586,26 +577,6 @@ void CommandLineInterface::handleAst(string const& _argStr) } } } - - if (outputToFile(choice)) - { - for (auto const& sourceCode: m_sourceCodes) - { - boost::filesystem::path p(sourceCode.first); - ofstream outFile(p.stem().string() + ".ast"); - if (_argStr == g_argAstStr) - { - ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second); - printer.print(outFile); - } - else - { - ASTJsonConverter converter(m_compiler->getAST(sourceCode.first)); - converter.print(outFile); - } - outFile.close(); - } - } } } @@ -626,19 +597,19 @@ void CommandLineInterface::actOnInput() // do we need EVM assembly? if (m_args.count(g_argAsmStr) || m_args.count(g_argAsmJsonStr)) { - auto choice = m_args.count(g_argAsmStr) ? m_args[g_argAsmStr].as() : m_args[g_argAsmJsonStr].as(); - if (outputToStdout(choice)) - { - cout << "EVM assembly:" << endl; - m_compiler->streamAssembly(cout, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); - } + //auto choice = m_args.count(g_argAsmStr) ? m_args[g_argAsmStr].as() : m_args[g_argAsmJsonStr].as(); - if (outputToFile(choice)) + if (m_args.count("output-dir")) { ofstream outFile(contract + (m_args.count(g_argAsmJsonStr) ? "_evm.json" : ".evm")); m_compiler->streamAssembly(outFile, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); outFile.close(); } + else + { + cout << "EVM assembly:" << endl; + m_compiler->streamAssembly(cout, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); + } } if (m_args.count(g_argGas)) From 1c7354ed0f28ddf74c70eea40a2cf230320783fe Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 17 Jul 2015 17:58:21 +0200 Subject: [PATCH 03/13] added -o option to cmd compiler --- CommandLineInterface.h | 1 - 1 file changed, 1 deletion(-) diff --git a/CommandLineInterface.h b/CommandLineInterface.h index 46b9b1e22..ab389ed08 100644 --- a/CommandLineInterface.h +++ b/CommandLineInterface.h @@ -37,7 +37,6 @@ enum class OutputType: uint8_t { STDOUT, FILE, - BOTH }; class CommandLineInterface From 6f97fb257680a20050580f4feb4c350634052f95 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 12:44:59 +0200 Subject: [PATCH 04/13] changed output method for all components Conflicts: solc/CommandLineInterface.cpp --- CommandLineInterface.cpp | 80 ++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index 2b00e7c9f..5bd4d3d1b 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -118,13 +118,14 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) void CommandLineInterface::handleBinary(string const& _contract) { +<<<<<<< HEAD if (m_args.count(g_argBinaryStr)) { if (m_args.count("output-dir")) { - ofstream outFile(_contract + ".binary"); - outFile << toHex(m_compiler->getBytecode(_contract)); - outFile.close(); + stringstream data; + data << toHex(m_compiler->getBytecode(_contract)); + createFile(_contract + ".binary", data.str()); } else { @@ -137,16 +138,15 @@ void CommandLineInterface::handleBinary(string const& _contract) { if (outputToFile(m_args[g_argCloneBinaryStr].as())) { - ofstream outFile(_contract + ".clone_binary"); - outFile << toHex(m_compiler->getCloneBytecode(_contract)); - outFile.close(); + stringstream data; + data << toHex(m_compiler->getCloneBytecode(_contract)); + createFile(_contract + ".clone_binary", data.str()); } else { cout << "Clone Binary: " << endl; cout << toHex(m_compiler->getCloneBytecode(_contract)) << endl; } - } else { @@ -158,12 +158,11 @@ void CommandLineInterface::handleBinary(string const& _contract) void CommandLineInterface::handleOpcode(string const& _contract) { - //auto choice = m_args[g_argOpcodesStr].as(); if (m_args.count("output-dir")) { - ofstream outFile(_contract + ".opcode"); - outFile << eth::disassemble(m_compiler->getBytecode(_contract)); - outFile.close(); + stringstream data; + data << eth::disassemble(m_compiler->getBytecode(_contract)); + createFile(_contract + ".opcode", data.str()); } else { @@ -191,12 +190,11 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract) for (auto const& it: m_compiler->getContractDefinition(_contract).getInterfaceFunctions()) out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n"; - //auto choice = m_args[g_argSignatureHashes].as(); if (m_args.count("output-dir")) { - ofstream outFile(_contract + ".signatures"); - outFile << out; - outFile.close(); + stringstream data; + data << out; + createFile(_contract + ".signatures", data.str()); } else cout << "Function signatures: " << endl << out; @@ -236,12 +234,11 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co if (m_args.count(argName)) { - //auto choice = m_args[argName].as(); if (m_args.count("output-dir")) { - ofstream outFile(_contract + suffix); - outFile << m_compiler->getMetadata(_contract, _type); - outFile.close(); + stringstream data; + data << m_compiler->getMetadata(_contract, _type); + createFile(_contract + suffix, data.str()); } else { @@ -301,7 +298,21 @@ void CommandLineInterface::handleGasEstimation(string const& _contract) } } -bool CommandLineInterface::parseArguments(int argc, char** argv) +void CommandLineInterface::createFile(string const& _fileName, string const& _data) +{ + namespace fs = boost::filesystem; + // create directory if not existent + fs::path p(m_args["output-dir"].as()); + fs::create_directories(p); + ofstream outFile(m_args["output-dir"].as() + "/" + _fileName); + if (!_data.empty()) + outFile << _data; + if (!outFile) + BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _fileName)); + outFile.close(); +} + +bool CommandLineInterface::parseArguments(int _argc, char** _argv) { // Declare the supported options. po::options_description desc("Allowed options"); @@ -317,7 +328,7 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) po::value()->value_name(boost::join(g_combinedJsonArgs, ",")), "Output a single json document containing the specified information, can be combined." ) - ("o,output-dir", po::value(), "Output directory path") + ("output-dir,o", po::value(), "Output directory path") (g_argAstStr.c_str(), "Request to output the AST of the contract.") (g_argAstJson.c_str(), "Request to output the AST of the contract in JSON format.") (g_argAsmStr.c_str(), "Request to output the EVM assembly of the contract.") @@ -333,13 +344,15 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) (g_argNatspecDevStr.c_str(), "Request to output the contract's Natspec developer documentation."); // All positional options should be interpreted as input files - po::positional_options_description inputFileNamePosition; - inputFileNamePosition.add("input-file", -1); + po::positional_options_description filesPositions; + filesPositions.add("output-dir", 1); + filesPositions.add("input-file", -1); // parse the compiler arguments try { - po::store(po::command_line_parser(argc, argv).options(desc).positional(inputFileNamePosition).allow_unregistered().run(), m_args); + po::store(po::command_line_parser(_argc, _argv).options(desc).positional(filesPositions).allow_unregistered().run(), m_args); + } catch (po::error const& _exception) { @@ -534,25 +547,22 @@ void CommandLineInterface::handleAst(string const& _argStr) asts ); -// auto choice = m_args[_argStr].as(); - if (m_args.count("output-dir")) { for (auto const& sourceCode: m_sourceCodes) { - boost::filesystem::path p(sourceCode.first); - ofstream outFile(p.stem().string() + ".ast"); + stringstream data; if (_argStr == g_argAstStr) { ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second); - printer.print(outFile); + printer.print(data); } else { ASTJsonConverter converter(m_compiler->getAST(sourceCode.first)); - converter.print(outFile); + converter.print(data); } - outFile.close(); + createFile(sourceCode.first + ".ast", data.str()); } } else @@ -597,13 +607,11 @@ void CommandLineInterface::actOnInput() // do we need EVM assembly? if (m_args.count(g_argAsmStr) || m_args.count(g_argAsmJsonStr)) { - //auto choice = m_args.count(g_argAsmStr) ? m_args[g_argAsmStr].as() : m_args[g_argAsmJsonStr].as(); - if (m_args.count("output-dir")) { - ofstream outFile(contract + (m_args.count(g_argAsmJsonStr) ? "_evm.json" : ".evm")); - m_compiler->streamAssembly(outFile, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); - outFile.close(); + stringstream data; + m_compiler->streamAssembly(data, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); + createFile(contract + (m_args.count(g_argAsmJsonStr) ? "_evm.json" : ".evm"), data.str()); } else { From 96fb0f4534d0fe031747b0481bc51bb85c8d202c Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 20 Jul 2015 18:14:25 +0200 Subject: [PATCH 05/13] changed output method for all components --- CommandLineInterface.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CommandLineInterface.h b/CommandLineInterface.h index ab389ed08..715f381ba 100644 --- a/CommandLineInterface.h +++ b/CommandLineInterface.h @@ -45,7 +45,7 @@ public: CommandLineInterface() {} /// Parse command line arguments and return false if we should not continue - bool parseArguments(int argc, char** argv); + bool parseArguments(int _argc, char** _argv); /// Parse the files and create source code objects bool processInput(); /// Perform actions on the input depending on provided compiler arguments @@ -62,6 +62,12 @@ private: std::string const& _contract); void handleGasEstimation(std::string const& _contract); + + /// Create a file in the given directory + /// @arg _fileName the name of the file + /// @arg _data to be written + void createFile(std::string const& _fileName, std::string const& _data = ""); + /// Compiler arguments variable map boost::program_options::variables_map m_args; /// map of input files to source code strings From 5cb639d3e02d10abb0c1b7d056b90c35063405e7 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 12:49:28 +0200 Subject: [PATCH 06/13] renamed extensions for output files Conflicts: solc/CommandLineInterface.cpp --- CommandLineInterface.cpp | 61 ++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index 5bd4d3d1b..609678952 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -54,32 +54,32 @@ namespace dev namespace solidity { -static string const g_argAbiStr = "json-abi"; -static string const g_argSolAbiStr = "sol-abi"; +static string const g_argAbiStr = "abi"; +static string const g_argSolAbiStr = "interface"; static string const g_argSignatureHashes = "hashes"; static string const g_argGas = "gas"; static string const g_argAsmStr = "asm"; static string const g_argAsmJsonStr = "asm-json"; static string const g_argAstStr = "ast"; static string const g_argAstJson = "ast-json"; -static string const g_argBinaryStr = "binary"; -static string const g_argCloneBinaryStr = "clone-binary"; +static string const g_argBinaryStr = "bin"; +static string const g_argCloneBinaryStr = "clone-bin"; static string const g_argOpcodesStr = "opcodes"; -static string const g_argNatspecDevStr = "natspec-dev"; -static string const g_argNatspecUserStr = "natspec-user"; +static string const g_argNatspecDevStr = "devdoc"; +static string const g_argNatspecUserStr = "userdoc"; static string const g_argAddStandard = "add-std"; /// Possible arguments to for --combined-json static set const g_combinedJsonArgs{ - "binary", - "clone-binary", + "bin", + "clone-bin", "opcodes", - "json-abi", - "sol-abi", + "abi", + "interface", "asm", "ast", - "natspec-user", - "natspec-dev" + "userdoc", + "devdoc" }; static void version() @@ -118,14 +118,13 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) void CommandLineInterface::handleBinary(string const& _contract) { -<<<<<<< HEAD if (m_args.count(g_argBinaryStr)) { if (m_args.count("output-dir")) { stringstream data; data << toHex(m_compiler->getBytecode(_contract)); - createFile(_contract + ".binary", data.str()); + createFile(_contract + ".bin", data.str()); } else { @@ -140,7 +139,7 @@ void CommandLineInterface::handleBinary(string const& _contract) { stringstream data; data << toHex(m_compiler->getCloneBytecode(_contract)); - createFile(_contract + ".clone_binary", data.str()); + createFile(_contract + ".clone_bin", data.str()); } else { @@ -214,7 +213,7 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co break; case DocumentationType::ABISolidityInterface: argName = g_argSolAbiStr; - suffix = ".sol"; + suffix = "_interface.sol"; title = "Contract Solidity ABI"; break; case DocumentationType::NatspecUser: @@ -323,12 +322,12 @@ bool CommandLineInterface::parseArguments(int _argc, char** _argv) ("optimize-runs", po::value()->default_value(200), "Estimated number of contract runs for optimizer.") ("add-std", po::value()->default_value(false), "Add standard contracts") ("input-file", po::value>(), "input file") + ("output-dir,o", po::value(), "Output directory path") ( "combined-json", po::value()->value_name(boost::join(g_combinedJsonArgs, ",")), "Output a single json document containing the specified information, can be combined." ) - ("output-dir,o", po::value(), "Output directory path") (g_argAstStr.c_str(), "Request to output the AST of the contract.") (g_argAstJson.c_str(), "Request to output the AST of the contract in JSON format.") (g_argAsmStr.c_str(), "Request to output the EVM assembly of the contract.") @@ -488,14 +487,14 @@ void CommandLineInterface::handleCombinedJSON() for (string const& contractName: contracts) { Json::Value contractData(Json::objectValue); - if (requests.count("sol-abi")) - contractData["sol-abi"] = m_compiler->getSolidityInterface(contractName); - if (requests.count("json-abi")) - contractData["json-abi"] = m_compiler->getInterface(contractName); - if (requests.count("binary")) - contractData["binary"] = toHex(m_compiler->getBytecode(contractName)); - if (requests.count("clone-binary")) - contractData["clone-binary"] = toHex(m_compiler->getCloneBytecode(contractName)); + if (requests.count("interface")) + contractData["interface"] = m_compiler->getSolidityInterface(contractName); + if (requests.count("abi")) + contractData["abi"] = m_compiler->getInterface(contractName); + if (requests.count("bin")) + contractData["bin"] = toHex(m_compiler->getBytecode(contractName)); + if (requests.count("clone-bin")) + contractData["clone-bin"] = toHex(m_compiler->getCloneBytecode(contractName)); if (requests.count("opcodes")) contractData["opcodes"] = eth::disassemble(m_compiler->getBytecode(contractName)); if (requests.count("asm")) @@ -503,10 +502,10 @@ void CommandLineInterface::handleCombinedJSON() ostringstream unused; contractData["asm"] = m_compiler->streamAssembly(unused, contractName, m_sourceCodes, true); } - if (requests.count("natspec-dev")) - contractData["natspec-dev"] = m_compiler->getMetadata(contractName, DocumentationType::NatspecDev); - if (requests.count("natspec-user")) - contractData["natspec-user"] = m_compiler->getMetadata(contractName, DocumentationType::NatspecUser); + if (requests.count("devdoc")) + contractData["devdoc"] = m_compiler->getMetadata(contractName, DocumentationType::NatspecDev); + if (requests.count("userdoc")) + contractData["userdoc"] = m_compiler->getMetadata(contractName, DocumentationType::NatspecUser); output["contracts"][contractName] = contractData; } @@ -552,6 +551,7 @@ void CommandLineInterface::handleAst(string const& _argStr) for (auto const& sourceCode: m_sourceCodes) { stringstream data; + string postfix = ""; if (_argStr == g_argAstStr) { ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second); @@ -561,8 +561,9 @@ void CommandLineInterface::handleAst(string const& _argStr) { ASTJsonConverter converter(m_compiler->getAST(sourceCode.first)); converter.print(data); + postfix += "_json"; } - createFile(sourceCode.first + ".ast", data.str()); + createFile(sourceCode.first + postfix + ".ast", data.str()); } } else From 0d163aaff14cc1df8aabea9f12599fd2b38971cd Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 21 Jul 2015 15:29:15 +0200 Subject: [PATCH 07/13] clean up --- CommandLineInterface.cpp | 3 +-- CommandLineInterface.h | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index 609678952..f13500142 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -304,8 +304,7 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da fs::path p(m_args["output-dir"].as()); fs::create_directories(p); ofstream outFile(m_args["output-dir"].as() + "/" + _fileName); - if (!_data.empty()) - outFile << _data; + outFile << _data; if (!outFile) BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _fileName)); outFile.close(); diff --git a/CommandLineInterface.h b/CommandLineInterface.h index 715f381ba..f79bc0be4 100644 --- a/CommandLineInterface.h +++ b/CommandLineInterface.h @@ -33,12 +33,6 @@ namespace solidity //forward declaration enum class DocumentationType: uint8_t; -enum class OutputType: uint8_t -{ - STDOUT, - FILE, -}; - class CommandLineInterface { public: @@ -66,7 +60,7 @@ private: /// Create a file in the given directory /// @arg _fileName the name of the file /// @arg _data to be written - void createFile(std::string const& _fileName, std::string const& _data = ""); + void createFile(std::string const& _fileName, std::string const& _data); /// Compiler arguments variable map boost::program_options::variables_map m_args; From 9853871b1a49d868428c11a63d30e26f779c2826 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 12:51:23 +0200 Subject: [PATCH 08/13] cosmetic changes Conflicts: solc/CommandLineInterface.cpp --- CommandLineInterface.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index f13500142..e1980cda4 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -55,7 +55,7 @@ namespace solidity { static string const g_argAbiStr = "abi"; -static string const g_argSolAbiStr = "interface"; +static string const g_argSolInterfaceStr = "interface"; static string const g_argSignatureHashes = "hashes"; static string const g_argGas = "gas"; static string const g_argAsmStr = "asm"; @@ -104,7 +104,7 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) return _args.count(g_argGas) || humanTargetedStdout(_args, g_argAbiStr) || - humanTargetedStdout(_args, g_argSolAbiStr) || + humanTargetedStdout(_args, g_argSolInterfaceStr) || humanTargetedStdout(_args, g_argSignatureHashes) || humanTargetedStdout(_args, g_argNatspecUserStr) || humanTargetedStdout(_args, g_argAstJson) || @@ -212,7 +212,7 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co title = "Contract JSON ABI"; break; case DocumentationType::ABISolidityInterface: - argName = g_argSolAbiStr; + argName = g_argSolInterfaceStr; suffix = "_interface.sol"; title = "Contract Solidity ABI"; break; @@ -327,19 +327,19 @@ bool CommandLineInterface::parseArguments(int _argc, char** _argv) po::value()->value_name(boost::join(g_combinedJsonArgs, ",")), "Output a single json document containing the specified information, can be combined." ) - (g_argAstStr.c_str(), "Request to output the AST of the contract.") - (g_argAstJson.c_str(), "Request to output the AST of the contract in JSON format.") - (g_argAsmStr.c_str(), "Request to output the EVM assembly of the contract.") - (g_argAsmJsonStr.c_str(), "Request to output the EVM assembly of the contract in JSON format.") - (g_argOpcodesStr.c_str(), "Request to output the Opcodes of the contract.") - (g_argBinaryStr.c_str(), "Request to output the contract in binary (hexadecimal).") - (g_argCloneBinaryStr.c_str(), "Request to output the clone contract in binary (hexadecimal).") - (g_argAbiStr.c_str(), "Request to output the contract's JSON ABI interface.") - (g_argSolAbiStr.c_str(), "Request to output the contract's Solidity ABI interface.") - (g_argSignatureHashes.c_str(), "Request to output the contract's functions' signature hashes.") - (g_argGas.c_str(), "Request to output an estimate for each function's maximal gas usage.") - (g_argNatspecUserStr.c_str(), "Request to output the contract's Natspec user documentation.") - (g_argNatspecDevStr.c_str(), "Request to output the contract's Natspec developer documentation."); + (g_argAstStr.c_str(), "Outputs the AST of the contract.") + (g_argAstJson.c_str(), "Outputs the AST of the contract in JSON format.") + (g_argAsmStr.c_str(), "Outputs the EVM assembly of the contract.") + (g_argAsmJsonStr.c_str(), "Outputs the EVM assembly of the contract in JSON format.") + (g_argOpcodesStr.c_str(), "Outputs the Opcodes of the contract.") + (g_argBinaryStr.c_str(), "Outputs the contract in binary (hexadecimal).") + (g_argCloneBinaryStr.c_str(), "Output the clone contract in binary (hexadecimal).") + (g_argAbiStr.c_str(), "Outputs the contract's JSON ABI interface.") + (g_argSolInterfaceStr.c_str(), "Outputs the contract's Solidity interface.") + (g_argSignatureHashes.c_str(), "Outputs the contract's functions' signature hashes.") + (g_argGas.c_str(), "Outputs an estimate for each function's maximal gas usage.") + (g_argNatspecUserStr.c_str(), "Outputs the contract's Natspec user documentation.") + (g_argNatspecDevStr.c_str(), "Outputs the contract's Natspec developer documentation."); // All positional options should be interpreted as input files po::positional_options_description filesPositions; From e946840b198d3756134b9d4f4ec832b300ba0256 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 13:01:28 +0200 Subject: [PATCH 09/13] fixed wrong resolving --- CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index e1980cda4..e9c9c256c 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -135,7 +135,7 @@ void CommandLineInterface::handleBinary(string const& _contract) } if (m_args.count(g_argCloneBinaryStr)) { - if (outputToFile(m_args[g_argCloneBinaryStr].as())) + if (m_args.count("output-dir")) { stringstream data; data << toHex(m_compiler->getCloneBytecode(_contract)); From f61107c1c9fccd7a4bededcf880b26644816737f Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 13:09:10 +0200 Subject: [PATCH 10/13] removed close for ofstream --- CommandLineInterface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index e9c9c256c..ff70616a2 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -307,7 +307,6 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da outFile << _data; if (!outFile) BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _fileName)); - outFile.close(); } bool CommandLineInterface::parseArguments(int _argc, char** _argv) From c4dee49b969f5fe539d9f68bc863e1cd58d54012 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 10 Aug 2015 14:17:32 +0200 Subject: [PATCH 11/13] changed file path to be multiplatform --- CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommandLineInterface.cpp b/CommandLineInterface.cpp index ff70616a2..a5ad07d7c 100644 --- a/CommandLineInterface.cpp +++ b/CommandLineInterface.cpp @@ -303,7 +303,7 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da // create directory if not existent fs::path p(m_args["output-dir"].as()); fs::create_directories(p); - ofstream outFile(m_args["output-dir"].as() + "/" + _fileName); + ofstream outFile((p / _fileName).string()); outFile << _data; if (!outFile) BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _fileName)); From b429a67a9ea1c7584539ee24040498e75aef2678 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 19 Aug 2015 13:02:21 +0200 Subject: [PATCH 12/13] Moved solc files. --- CMakeLists.txt => solc/CMakeLists.txt | 0 CommandLineInterface.cpp => solc/CommandLineInterface.cpp | 0 CommandLineInterface.h => solc/CommandLineInterface.h | 0 {docker_emscripten => solc/docker_emscripten}/Dockerfile | 0 jsonCompiler.cpp => solc/jsonCompiler.cpp | 0 main.cpp => solc/main.cpp | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename CMakeLists.txt => solc/CMakeLists.txt (100%) rename CommandLineInterface.cpp => solc/CommandLineInterface.cpp (100%) rename CommandLineInterface.h => solc/CommandLineInterface.h (100%) rename {docker_emscripten => solc/docker_emscripten}/Dockerfile (100%) rename jsonCompiler.cpp => solc/jsonCompiler.cpp (100%) rename main.cpp => solc/main.cpp (100%) diff --git a/CMakeLists.txt b/solc/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to solc/CMakeLists.txt diff --git a/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp similarity index 100% rename from CommandLineInterface.cpp rename to solc/CommandLineInterface.cpp diff --git a/CommandLineInterface.h b/solc/CommandLineInterface.h similarity index 100% rename from CommandLineInterface.h rename to solc/CommandLineInterface.h diff --git a/docker_emscripten/Dockerfile b/solc/docker_emscripten/Dockerfile similarity index 100% rename from docker_emscripten/Dockerfile rename to solc/docker_emscripten/Dockerfile diff --git a/jsonCompiler.cpp b/solc/jsonCompiler.cpp similarity index 100% rename from jsonCompiler.cpp rename to solc/jsonCompiler.cpp diff --git a/main.cpp b/solc/main.cpp similarity index 100% rename from main.cpp rename to solc/main.cpp From 895a0a819f89cc1b9a7d2e738ff0cff32380f101 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 19 Aug 2015 13:12:08 +0200 Subject: [PATCH 13/13] Moved solc files. --- CMakeLists.txt => solc/CMakeLists.txt | 0 CommandLineInterface.cpp => solc/CommandLineInterface.cpp | 0 CommandLineInterface.h => solc/CommandLineInterface.h | 0 {docker_emscripten => solc/docker_emscripten}/Dockerfile | 0 jsonCompiler.cpp => solc/jsonCompiler.cpp | 0 main.cpp => solc/main.cpp | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename CMakeLists.txt => solc/CMakeLists.txt (100%) rename CommandLineInterface.cpp => solc/CommandLineInterface.cpp (100%) rename CommandLineInterface.h => solc/CommandLineInterface.h (100%) rename {docker_emscripten => solc/docker_emscripten}/Dockerfile (100%) rename jsonCompiler.cpp => solc/jsonCompiler.cpp (100%) rename main.cpp => solc/main.cpp (100%) diff --git a/CMakeLists.txt b/solc/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to solc/CMakeLists.txt diff --git a/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp similarity index 100% rename from CommandLineInterface.cpp rename to solc/CommandLineInterface.cpp diff --git a/CommandLineInterface.h b/solc/CommandLineInterface.h similarity index 100% rename from CommandLineInterface.h rename to solc/CommandLineInterface.h diff --git a/docker_emscripten/Dockerfile b/solc/docker_emscripten/Dockerfile similarity index 100% rename from docker_emscripten/Dockerfile rename to solc/docker_emscripten/Dockerfile diff --git a/jsonCompiler.cpp b/solc/jsonCompiler.cpp similarity index 100% rename from jsonCompiler.cpp rename to solc/jsonCompiler.cpp diff --git a/main.cpp b/solc/main.cpp similarity index 100% rename from main.cpp rename to solc/main.cpp