From 2a5a5a99f91ff69abd4b510450c04806cca0bab2 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 17 Apr 2015 17:41:41 +0200 Subject: [PATCH] added asm-json flag to cl compiler Conflicts: libsolidity/CompilerStack.cpp --- libevmcore/Assembly.cpp | 3 ++- libevmcore/Assembly.h | 2 +- libsolidity/Compiler.h | 5 +++-- libsolidity/CompilerContext.h | 3 ++- libsolidity/CompilerStack.cpp | 4 ++-- libsolidity/CompilerStack.h | 3 ++- solc/CommandLineInterface.cpp | 38 +++++++++++++++++++++-------------- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/libevmcore/Assembly.cpp b/libevmcore/Assembly.cpp index bf4ea2145..589912857 100644 --- a/libevmcore/Assembly.cpp +++ b/libevmcore/Assembly.cpp @@ -101,8 +101,9 @@ string Assembly::getLocationFromSources(StringMap const& _sourceCodes, SourceLoc return move(cut); } -ostream& Assembly::stream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes) const +ostream& Assembly::stream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes, bool _inJsonFormat) const { + (void)_inJsonFormat; _out << _prefix << ".code:" << endl; for (AssemblyItem const& i: m_items) { diff --git a/libevmcore/Assembly.h b/libevmcore/Assembly.h index 2744af900..06cac8801 100644 --- a/libevmcore/Assembly.h +++ b/libevmcore/Assembly.h @@ -86,7 +86,7 @@ public: bytes assemble() const; Assembly& optimise(bool _enable); - std::ostream& stream(std::ostream& _out, std::string const& _prefix = "", const StringMap &_sourceCodes = StringMap()) const; + std::ostream& stream(std::ostream& _out, std::string const& _prefix = "", const StringMap &_sourceCodes = StringMap(), bool _inJsonFormat = false) const; protected: std::string getLocationFromSources(StringMap const& _sourceCodes, SourceLocation const& _location) const; diff --git a/libsolidity/Compiler.h b/libsolidity/Compiler.h index 4b1e1b4d6..260aebd33 100644 --- a/libsolidity/Compiler.h +++ b/libsolidity/Compiler.h @@ -42,9 +42,10 @@ public: bytes getAssembledBytecode() { return m_context.getAssembledBytecode(m_optimize); } bytes getRuntimeBytecode() { return m_runtimeContext.getAssembledBytecode(m_optimize);} /// @arg _sourceCodes is the map of input files to source code strings - void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const + /// @arg _inJsonFromat shows weather the out should be in Json format + void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap(), bool _inJsonFormat = false) const { - m_context.streamAssembly(_stream, _sourceCodes); + m_context.streamAssembly(_stream, _sourceCodes, _inJsonFormat); } /// @returns Assembly items of the normal compiler context eth::AssemblyItems const& getAssemblyItems() const { return m_context.getAssembly().getItems(); } diff --git a/libsolidity/CompilerContext.h b/libsolidity/CompilerContext.h index e752d59b8..3fcf0706d 100644 --- a/libsolidity/CompilerContext.h +++ b/libsolidity/CompilerContext.h @@ -122,7 +122,8 @@ public: eth::Assembly const& getAssembly() const { return m_asm; } /// @arg _sourceCodes is the map of input files to source code strings - void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const { m_asm.stream(_stream, "", _sourceCodes); } + /// @arg _inJsonFromat shows weather the out should be in Json format + void streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap(), bool _inJsonFormat = false) const { m_asm.stream(_stream, "", _sourceCodes, _inJsonFormat); } bytes getAssembledBytecode(bool _optimize = false) { return m_asm.optimise(_optimize).assemble(); } diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index c35d9324c..592f61276 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -184,11 +184,11 @@ dev::h256 CompilerStack::getContractCodeHash(string const& _contractName) const return dev::sha3(getRuntimeBytecode(_contractName)); } -void CompilerStack::streamAssembly(ostream& _outStream, string const& _contractName, StringMap _sourceCodes) const +void CompilerStack::streamAssembly(ostream& _outStream, string const& _contractName, StringMap _sourceCodes, bool _inJsonFormat) const { Contract const& contract = getContract(_contractName); if (contract.compiler) - getContract(_contractName).compiler->streamAssembly(_outStream, _sourceCodes); + contract(_contractName).compiler->streamAssembly(_outStream, _sourceCodes, _inJsonFormat); else _outStream << "Contract not fully implemented" << endl; } diff --git a/libsolidity/CompilerStack.h b/libsolidity/CompilerStack.h index 19c1ba4e1..ef3d09663 100644 --- a/libsolidity/CompilerStack.h +++ b/libsolidity/CompilerStack.h @@ -102,8 +102,9 @@ public: /// Streams a verbose version of the assembly to @a _outStream. /// @arg _sourceCodes is the map of input files to source code strings + /// @arg _inJsonFromat shows weather the out should be in Json format /// Prerequisite: Successful compilation. - void streamAssembly(std::ostream& _outStream, std::string const& _contractName = "", StringMap _sourceCodes = StringMap()) const; + void streamAssembly(std::ostream& _outStream, std::string const& _contractName = "", StringMap _sourceCodes = StringMap(), bool _inJsonFormat = false) const; /// Returns a string representing the contract interface in JSON. /// Prerequisite: Successful call to parse or compile. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 6ed90cdea..d21839f14 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -55,6 +55,7 @@ namespace solidity static string const g_argAbiStr = "json-abi"; static string const g_argSolAbiStr = "sol-abi"; 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"; @@ -80,10 +81,15 @@ static bool needStdout(po::variables_map const& _args) { return - argToStdout(_args, g_argAbiStr) || argToStdout(_args, g_argSolAbiStr) || - argToStdout(_args, g_argNatspecUserStr) || argToStdout(_args, g_argAstJson) || - argToStdout(_args, g_argNatspecDevStr) || argToStdout(_args, g_argAsmStr) || - argToStdout(_args, g_argOpcodesStr) || argToStdout(_args, g_argBinaryStr); + argToStdout(_args, g_argAbiStr) || + argToStdout(_args, g_argSolAbiStr) || + argToStdout(_args, g_argNatspecUserStr) || + argToStdout(_args, g_argAstJson) || + argToStdout(_args, g_argNatspecDevStr) || + argToStdout(_args, g_argAsmStr) || + argToStdout(_args, g_argAsmJsonStr) || + argToStdout(_args, g_argOpcodesStr) || + argToStdout(_args, g_argBinaryStr); } static inline bool outputToFile(OutputType type) @@ -215,23 +221,25 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) ("add-std", po::value()->default_value(false), "Add standard contracts") ("input-file", po::value>(), "input file") (g_argAstStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the AST of the contract.") + "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.") + "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.") + "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.") + "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).") + "Request to output the contract in binary (hexadecimal).") (g_argAbiStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's JSON ABI interface.") + "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.") + "Request to output the contract's Solidity ABI interface.") (g_argNatspecUserStr.c_str(), po::value()->value_name("stdout|file|both"), - "Request to output the contract's Natspec user documentation.") + "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."); + "Request to output the contract's Natspec developer documentation."); // All positional options should be interpreted as input files po::positional_options_description p; @@ -417,13 +425,13 @@ void CommandLineInterface::actOnInput() if (outputToStdout(choice)) { cout << "EVM assembly:" << endl; - m_compiler->streamAssembly(cout, contract, m_sourceCodes); + m_compiler->streamAssembly(cout, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); } if (outputToFile(choice)) { ofstream outFile(contract + ".evm"); - m_compiler->streamAssembly(outFile, contract, m_sourceCodes); + m_compiler->streamAssembly(outFile, contract, m_sourceCodes, m_args.count(g_argAsmJsonStr)); outFile.close(); } }