changed output method for all components

Conflicts:
	solc/CommandLineInterface.cpp
This commit is contained in:
Liana Husikyan 2015-08-10 12:44:59 +02:00
parent 1c7354ed0f
commit 6f97fb2576

View File

@ -118,13 +118,14 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args)
void CommandLineInterface::handleBinary(string const& _contract) void CommandLineInterface::handleBinary(string const& _contract)
{ {
<<<<<<< HEAD
if (m_args.count(g_argBinaryStr)) if (m_args.count(g_argBinaryStr))
{ {
if (m_args.count("output-dir")) if (m_args.count("output-dir"))
{ {
ofstream outFile(_contract + ".binary"); stringstream data;
outFile << toHex(m_compiler->getBytecode(_contract)); data << toHex(m_compiler->getBytecode(_contract));
outFile.close(); createFile(_contract + ".binary", data.str());
} }
else else
{ {
@ -137,16 +138,15 @@ void CommandLineInterface::handleBinary(string const& _contract)
{ {
if (outputToFile(m_args[g_argCloneBinaryStr].as<OutputType>())) if (outputToFile(m_args[g_argCloneBinaryStr].as<OutputType>()))
{ {
ofstream outFile(_contract + ".clone_binary"); stringstream data;
outFile << toHex(m_compiler->getCloneBytecode(_contract)); data << toHex(m_compiler->getCloneBytecode(_contract));
outFile.close(); createFile(_contract + ".clone_binary", data.str());
} }
else else
{ {
cout << "Clone Binary: " << endl; cout << "Clone Binary: " << endl;
cout << toHex(m_compiler->getCloneBytecode(_contract)) << endl; cout << toHex(m_compiler->getCloneBytecode(_contract)) << endl;
} }
} }
else else
{ {
@ -158,12 +158,11 @@ void CommandLineInterface::handleBinary(string const& _contract)
void CommandLineInterface::handleOpcode(string const& _contract) void CommandLineInterface::handleOpcode(string const& _contract)
{ {
//auto choice = m_args[g_argOpcodesStr].as<OutputType>();
if (m_args.count("output-dir")) if (m_args.count("output-dir"))
{ {
ofstream outFile(_contract + ".opcode"); stringstream data;
outFile << eth::disassemble(m_compiler->getBytecode(_contract)); data << eth::disassemble(m_compiler->getBytecode(_contract));
outFile.close(); createFile(_contract + ".opcode", data.str());
} }
else else
{ {
@ -191,12 +190,11 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
for (auto const& it: m_compiler->getContractDefinition(_contract).getInterfaceFunctions()) for (auto const& it: m_compiler->getContractDefinition(_contract).getInterfaceFunctions())
out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n"; out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n";
//auto choice = m_args[g_argSignatureHashes].as<OutputType>();
if (m_args.count("output-dir")) if (m_args.count("output-dir"))
{ {
ofstream outFile(_contract + ".signatures"); stringstream data;
outFile << out; data << out;
outFile.close(); createFile(_contract + ".signatures", data.str());
} }
else else
cout << "Function signatures: " << endl << out; cout << "Function signatures: " << endl << out;
@ -236,12 +234,11 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
if (m_args.count(argName)) if (m_args.count(argName))
{ {
//auto choice = m_args[argName].as<OutputType>();
if (m_args.count("output-dir")) if (m_args.count("output-dir"))
{ {
ofstream outFile(_contract + suffix); stringstream data;
outFile << m_compiler->getMetadata(_contract, _type); data << m_compiler->getMetadata(_contract, _type);
outFile.close(); createFile(_contract + suffix, data.str());
} }
else 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<string>());
fs::create_directories(p);
ofstream outFile(m_args["output-dir"].as<string>() + "/" + _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. // Declare the supported options.
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
@ -317,7 +328,7 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
po::value<string>()->value_name(boost::join(g_combinedJsonArgs, ",")), po::value<string>()->value_name(boost::join(g_combinedJsonArgs, ",")),
"Output a single json document containing the specified information, can be combined." "Output a single json document containing the specified information, can be combined."
) )
("o,output-dir", po::value<string>(), "Output directory path") ("output-dir,o", po::value<string>(), "Output directory path")
(g_argAstStr.c_str(), "Request to output the AST of the contract.") (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_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_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."); (g_argNatspecDevStr.c_str(), "Request to output the contract's Natspec developer documentation.");
// All positional options should be interpreted as input files // All positional options should be interpreted as input files
po::positional_options_description inputFileNamePosition; po::positional_options_description filesPositions;
inputFileNamePosition.add("input-file", -1); filesPositions.add("output-dir", 1);
filesPositions.add("input-file", -1);
// parse the compiler arguments // parse the compiler arguments
try 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) catch (po::error const& _exception)
{ {
@ -534,25 +547,22 @@ void CommandLineInterface::handleAst(string const& _argStr)
asts asts
); );
// auto choice = m_args[_argStr].as<OutputType>();
if (m_args.count("output-dir")) if (m_args.count("output-dir"))
{ {
for (auto const& sourceCode: m_sourceCodes) for (auto const& sourceCode: m_sourceCodes)
{ {
boost::filesystem::path p(sourceCode.first); stringstream data;
ofstream outFile(p.stem().string() + ".ast");
if (_argStr == g_argAstStr) if (_argStr == g_argAstStr)
{ {
ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second); ASTPrinter printer(m_compiler->getAST(sourceCode.first), sourceCode.second);
printer.print(outFile); printer.print(data);
} }
else else
{ {
ASTJsonConverter converter(m_compiler->getAST(sourceCode.first)); ASTJsonConverter converter(m_compiler->getAST(sourceCode.first));
converter.print(outFile); converter.print(data);
} }
outFile.close(); createFile(sourceCode.first + ".ast", data.str());
} }
} }
else else
@ -597,13 +607,11 @@ void CommandLineInterface::actOnInput()
// do we need EVM assembly? // do we need EVM assembly?
if (m_args.count(g_argAsmStr) || m_args.count(g_argAsmJsonStr)) if (m_args.count(g_argAsmStr) || m_args.count(g_argAsmJsonStr))
{ {
//auto choice = m_args.count(g_argAsmStr) ? m_args[g_argAsmStr].as<OutputType>() : m_args[g_argAsmJsonStr].as<OutputType>();
if (m_args.count("output-dir")) if (m_args.count("output-dir"))
{ {
ofstream outFile(contract + (m_args.count(g_argAsmJsonStr) ? "_evm.json" : ".evm")); stringstream data;
m_compiler->streamAssembly(outFile, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); m_compiler->streamAssembly(data, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr));
outFile.close(); createFile(contract + (m_args.count(g_argAsmJsonStr) ? "_evm.json" : ".evm"), data.str());
} }
else else
{ {