aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-30 09:17:15 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-09-11 22:53:20 +0800
commitbbfb16cf5ce903150bc3a141ac50553d8bf6d346 (patch)
treea79144b2c970f097f3bd1c8a6b3cdc27d0670ce8
parent50570c6c794eee01af64751c884fb6cb68f8dffc (diff)
downloaddexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.tar
dexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.tar.gz
dexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.tar.bz2
dexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.tar.lz
dexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.tar.xz
dexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.tar.zst
dexon-solidity-bbfb16cf5ce903150bc3a141ac50553d8bf6d346.zip
Introduce assemblyString
-rw-r--r--libevmasm/Assembly.cpp7
-rw-r--r--libevmasm/Assembly.h3
-rw-r--r--liblll/Compiler.cpp5
-rw-r--r--libsolidity/codegen/Compiler.h4
-rw-r--r--libsolidity/codegen/CompilerContext.h4
-rw-r--r--libsolidity/interface/AssemblyStack.cpp4
-rw-r--r--libsolidity/interface/CompilerStack.cpp9
-rw-r--r--libsolidity/interface/CompilerStack.h4
-rw-r--r--libsolidity/interface/StandardCompiler.cpp4
-rw-r--r--solc/CommandLineInterface.cpp7
10 files changed, 27 insertions, 24 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index 2203cadf..6b4bb52b 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -208,6 +208,13 @@ void Assembly::assemblyStream(ostream& _out, string const& _prefix, StringMap co
_out << endl << _prefix << "auxdata: 0x" << toHex(m_auxiliaryData) << endl;
}
+string Assembly::assemblyString(StringMap const& _sourceCodes) const
+{
+ ostringstream tmp;
+ assemblyStream(tmp, "", _sourceCodes);
+ return tmp.str();
+}
+
Json::Value Assembly::createJsonValue(string _name, int _begin, int _end, string _value, string _jumpType)
{
Json::Value value;
diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h
index b7e9b354..cbdd71bc 100644
--- a/libevmasm/Assembly.h
+++ b/libevmasm/Assembly.h
@@ -121,6 +121,9 @@ public:
Assembly& optimise(bool _enable, bool _isCreation = true, size_t _runs = 200);
/// Create a text representation of the assembly.
+ std::string assemblyString(
+ StringMap const& _sourceCodes = StringMap()
+ ) const;
void assemblyStream(
std::ostream& _out,
std::string const& _prefix = "",
diff --git a/liblll/Compiler.cpp b/liblll/Compiler.cpp
index f9bd3ab9..b69675aa 100644
--- a/liblll/Compiler.cpp
+++ b/liblll/Compiler.cpp
@@ -72,14 +72,13 @@ std::string dev::eth::compileLLLToAsm(std::string const& _src, bool _opt, std::v
{
CompilerState cs;
cs.populateStandard();
- stringstream ret;
auto assembly = CodeFragment::compile(_src, cs).assembly(cs);
if (_opt)
assembly = assembly.optimise(true);
- assembly.assemblyStream(ret);
+ string ret = assembly.assemblyString();
for (auto i: cs.treesToKill)
killBigints(i);
- return ret.str();
+ return ret;
}
catch (Exception const& _e)
{
diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h
index 5233cc91..06654486 100644
--- a/libsolidity/codegen/Compiler.h
+++ b/libsolidity/codegen/Compiler.h
@@ -60,9 +60,9 @@ public:
/// @returns Only the runtime object (without constructor).
eth::LinkerObject runtimeObject() const { return m_context.assembledRuntimeObject(m_runtimeSub); }
/// @arg _sourceCodes is the map of input files to source code strings
- void assemblyStream(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const
+ std::string assemblyString(StringMap const& _sourceCodes = StringMap()) const
{
- m_context.assemblyStream(_stream, _sourceCodes);
+ return m_context.assemblyString(_sourceCodes);
}
/// @arg _sourceCodes is the map of input files to source code strings
Json::Value assemblyJSON(StringMap const& _sourceCodes = StringMap()) const
diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h
index 47d4edde..5116585e 100644
--- a/libsolidity/codegen/CompilerContext.h
+++ b/libsolidity/codegen/CompilerContext.h
@@ -209,9 +209,9 @@ public:
eth::Assembly& nonConstAssembly() { return *m_asm; }
/// @arg _sourceCodes is the map of input files to source code strings
- void assemblyStream(std::ostream& _stream, StringMap const& _sourceCodes = StringMap()) const
+ std::string assemblyString(StringMap const& _sourceCodes = StringMap()) const
{
- m_asm->assemblyStream(_stream, "", _sourceCodes);
+ return m_asm->assemblyString(_sourceCodes);
}
/// @arg _sourceCodes is the map of input files to source code strings
diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp
index 025a01ac..504ad92c 100644
--- a/libsolidity/interface/AssemblyStack.cpp
+++ b/libsolidity/interface/AssemblyStack.cpp
@@ -91,9 +91,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
eth::Assembly assembly;
assembly::CodeGenerator::assemble(*m_parserResult, *m_analysisInfo, assembly);
object.bytecode = make_shared<eth::LinkerObject>(assembly.assemble());
- ostringstream tmp;
- assembly.assemblyStream(tmp);
- object.assembly = tmp.str();
+ object.assembly = assembly.assemblyString();
return object;
}
case Machine::EVM15:
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 5f62bb03..41bbf687 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -347,15 +347,14 @@ eth::LinkerObject const& CompilerStack::cloneObject(string const& _contractName)
return contract(_contractName).cloneObject;
}
-void CompilerStack::assemblyStream(ostream& _outStream, string const& _contractName, StringMap _sourceCodes) const
+/// FIXME: cache this string
+string CompilerStack::assemblyString(string const& _contractName, StringMap _sourceCodes) const
{
Contract const& currentContract = contract(_contractName);
if (currentContract.compiler)
- currentContract.compiler->assemblyStream(_outStream, _sourceCodes);
+ return currentContract.compiler->assemblyString(_sourceCodes);
else
- {
- _outStream << "Contract not fully implemented" << endl;
- }
+ return string();
}
/// FIXME: cache the JSON
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index 2f1b9bb3..f1bbae47 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -190,10 +190,10 @@ public:
/// if the contract does not (yet) have bytecode.
std::string const* runtimeSourceMapping(std::string const& _contractName = "") const;
- /// Streams a verbose version of the assembly to @a _outStream.
+ /// @return a verbose text representation of the assembly.
/// @arg _sourceCodes is the map of input files to source code strings
/// Prerequisite: Successful compilation.
- void assemblyStream(std::ostream& _outStream, std::string const& _contractName = "", StringMap _sourceCodes = StringMap()) const;
+ std::string assemblyString(std::string const& _contractName = "", StringMap _sourceCodes = StringMap()) const;
/// @returns a JSON representation of the assembly.
/// @arg _sourceCodes is the map of input files to source code strings
diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp
index c821a341..b4fbbef9 100644
--- a/libsolidity/interface/StandardCompiler.cpp
+++ b/libsolidity/interface/StandardCompiler.cpp
@@ -400,9 +400,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
// EVM
Json::Value evmData(Json::objectValue);
// @TODO: add ir
- ostringstream tmp;
- m_compilerStack.assemblyStream(tmp, contractName, createSourceList(_input));
- evmData["assembly"] = tmp.str();
+ evmData["assembly"] = m_compilerStack.assemblyString(contractName, createSourceList(_input));
evmData["legacyAssembly"] = m_compilerStack.assemblyJSON(contractName, createSourceList(_input));
evmData["methodIdentifiers"] = m_compilerStack.methodIdentifiers(contractName);
evmData["gasEstimates"] = m_compilerStack.gasEstimates(contractName);
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index 560dc98b..32c61585 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -1156,9 +1156,8 @@ void CommandLineInterface::outputCompilationResults()
}
else
{
- stringstream data;
- m_compiler->assemblyStream(data, contract, m_sourceCodes);
- createFile(m_compiler->filesystemFriendlyName(contract) + ".evm", data.str());
+ string ret = m_compiler->assemblyString(contract, m_sourceCodes);
+ createFile(m_compiler->filesystemFriendlyName(contract) + ".evm", ret));
}
}
else
@@ -1167,7 +1166,7 @@ void CommandLineInterface::outputCompilationResults()
if (m_args.count(g_argAsmJson)
cout << m_compiler->assemblyJSON(contract, m_sourceCodes);
else
- m_compiler->assemblyStream(cout, contract, m_sourceCodes);
+ cout << m_compiler->assemblyString(contract, m_sourceCodes);
}
}