Browse Source

added asm-json flag to cl compiler

Conflicts:
	libsolidity/CompilerStack.cpp
cl-refactor
Liana Husikyan 10 years ago
parent
commit
2a5a5a99f9
  1. 3
      libevmcore/Assembly.cpp
  2. 2
      libevmcore/Assembly.h
  3. 5
      libsolidity/Compiler.h
  4. 3
      libsolidity/CompilerContext.h
  5. 4
      libsolidity/CompilerStack.cpp
  6. 3
      libsolidity/CompilerStack.h
  7. 20
      solc/CommandLineInterface.cpp

3
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)
{

2
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;

5
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(); }

3
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(); }

4
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;
}

3
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.

20
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)
@ -220,6 +226,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
"Request to output the AST of the contract in JSON format.")
(g_argAsmStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the EVM assembly of the contract.")
(g_argAsmJsonStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the EVM assembly of the contract in JSON format.")
(g_argOpcodesStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the Opcodes of the contract.")
(g_argBinaryStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
@ -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();
}
}

Loading…
Cancel
Save