mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6490 from g-r-a-n-t/pass-large-strings-by-value
Pass large strings by value
This commit is contained in:
commit
dd15c24320
@ -256,7 +256,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
|
|||||||
string contents = m_readFile(fileName);
|
string contents = m_readFile(fileName);
|
||||||
if (contents.empty())
|
if (contents.empty())
|
||||||
error<InvalidName>(std::string("File not found (or empty): ") + fileName);
|
error<InvalidName>(std::string("File not found (or empty): ") + fileName);
|
||||||
m_asm.append(CodeFragment::compile(contents, _s, m_readFile).m_asm);
|
m_asm.append(CodeFragment::compile(std::move(contents), _s, m_readFile).m_asm);
|
||||||
}
|
}
|
||||||
else if (us == "SET")
|
else if (us == "SET")
|
||||||
{
|
{
|
||||||
@ -745,11 +745,11 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeFragment CodeFragment::compile(string const& _src, CompilerState& _s, ReadCallback const& _readFile)
|
CodeFragment CodeFragment::compile(string _src, CompilerState& _s, ReadCallback const& _readFile)
|
||||||
{
|
{
|
||||||
CodeFragment ret;
|
CodeFragment ret;
|
||||||
sp::utree o;
|
sp::utree o;
|
||||||
parseTreeLLL(_src, o);
|
parseTreeLLL(std::move(_src), o);
|
||||||
if (!o.empty())
|
if (!o.empty())
|
||||||
ret = CodeFragment(o, _s, _readFile);
|
ret = CodeFragment(o, _s, _readFile);
|
||||||
_s.treesToKill.push_back(o);
|
_s.treesToKill.push_back(o);
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
CodeFragment() = default;
|
CodeFragment() = default;
|
||||||
CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback const& _readFile, bool _allowASM = false);
|
CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback const& _readFile, bool _allowASM = false);
|
||||||
|
|
||||||
static CodeFragment compile(std::string const& _src, CompilerState& _s, ReadCallback const& _readFile);
|
static CodeFragment compile(std::string _src, CompilerState& _s, ReadCallback const& _readFile);
|
||||||
|
|
||||||
/// Consolidates data and compiles code.
|
/// Consolidates data and compiles code.
|
||||||
eth::Assembly& assembly(CompilerState const& _cs) { finalise(_cs); return m_asm; }
|
eth::Assembly& assembly(CompilerState const& _cs) { finalise(_cs); return m_asm; }
|
||||||
@ -69,4 +69,3 @@ static CodeFragment const NullCodeFragment;
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,13 +28,13 @@ using namespace std;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::lll;
|
using namespace dev::lll;
|
||||||
|
|
||||||
bytes dev::lll::compileLLL(string const& _src, langutil::EVMVersion _evmVersion, bool _opt, std::vector<std::string>* _errors, ReadCallback const& _readFile)
|
bytes dev::lll::compileLLL(string _src, langutil::EVMVersion _evmVersion, bool _opt, std::vector<std::string>* _errors, ReadCallback const& _readFile)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CompilerState cs;
|
CompilerState cs;
|
||||||
cs.populateStandard();
|
cs.populateStandard();
|
||||||
auto assembly = CodeFragment::compile(_src, cs, _readFile).assembly(cs);
|
auto assembly = CodeFragment::compile(std::move(_src), cs, _readFile).assembly(cs);
|
||||||
if (_opt)
|
if (_opt)
|
||||||
assembly = assembly.optimise(true, _evmVersion, true, 200);
|
assembly = assembly.optimise(true, _evmVersion, true, 200);
|
||||||
bytes ret = assembly.assemble().bytecode;
|
bytes ret = assembly.assemble().bytecode;
|
||||||
@ -66,13 +66,13 @@ bytes dev::lll::compileLLL(string const& _src, langutil::EVMVersion _evmVersion,
|
|||||||
return bytes();
|
return bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dev::lll::compileLLLToAsm(std::string const& _src, langutil::EVMVersion _evmVersion, bool _opt, std::vector<std::string>* _errors, ReadCallback const& _readFile)
|
std::string dev::lll::compileLLLToAsm(std::string _src, langutil::EVMVersion _evmVersion, bool _opt, std::vector<std::string>* _errors, ReadCallback const& _readFile)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CompilerState cs;
|
CompilerState cs;
|
||||||
cs.populateStandard();
|
cs.populateStandard();
|
||||||
auto assembly = CodeFragment::compile(_src, cs, _readFile).assembly(cs);
|
auto assembly = CodeFragment::compile(std::move(_src), cs, _readFile).assembly(cs);
|
||||||
if (_opt)
|
if (_opt)
|
||||||
assembly = assembly.optimise(true, _evmVersion, true, 200);
|
assembly = assembly.optimise(true, _evmVersion, true, 200);
|
||||||
string ret = assembly.assemblyString();
|
string ret = assembly.assemblyString();
|
||||||
@ -104,13 +104,13 @@ std::string dev::lll::compileLLLToAsm(std::string const& _src, langutil::EVMVers
|
|||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
string dev::lll::parseLLL(string const& _src)
|
string dev::lll::parseLLL(string _src)
|
||||||
{
|
{
|
||||||
sp::utree o;
|
sp::utree o;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parseTreeLLL(_src, o);
|
parseTreeLLL(std::move(_src), o);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
@ -35,9 +35,9 @@ namespace lll
|
|||||||
|
|
||||||
using ReadCallback = std::function<std::string(std::string const&)>;
|
using ReadCallback = std::function<std::string(std::string const&)>;
|
||||||
|
|
||||||
std::string parseLLL(std::string const& _src);
|
std::string parseLLL(std::string _src);
|
||||||
std::string compileLLLToAsm(std::string const& _src, langutil::EVMVersion _evmVersion, bool _opt = true, std::vector<std::string>* _errors = nullptr, ReadCallback const& _readFile = ReadCallback());
|
std::string compileLLLToAsm(std::string _src, langutil::EVMVersion _evmVersion, bool _opt = true, std::vector<std::string>* _errors = nullptr, ReadCallback const& _readFile = ReadCallback());
|
||||||
bytes compileLLL(std::string const& _src, langutil::EVMVersion _evmVersion, bool _opt = true, std::vector<std::string>* _errors = nullptr, ReadCallback const& _readFile = ReadCallback());
|
bytes compileLLL(std::string _src, langutil::EVMVersion _evmVersion, bool _opt = true, std::vector<std::string>* _errors = nullptr, ReadCallback const& _readFile = ReadCallback());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,10 +72,10 @@ ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback = n
|
|||||||
return readCallback;
|
return readCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
string compile(string const& _input, CStyleReadFileCallback _readCallback = nullptr)
|
string compile(string _input, CStyleReadFileCallback _readCallback = nullptr)
|
||||||
{
|
{
|
||||||
StandardCompiler compiler(wrapReadCallback(_readCallback));
|
StandardCompiler compiler(wrapReadCallback(_readCallback));
|
||||||
return compiler.compile(_input);
|
return compiler.compile(std::move(_input));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -181,14 +181,14 @@ void CompilerStack::reset(bool _keepSettings)
|
|||||||
TypeProvider::reset();
|
TypeProvider::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerStack::setSources(StringMap const& _sources)
|
void CompilerStack::setSources(StringMap _sources)
|
||||||
{
|
{
|
||||||
if (m_stackState == SourcesSet)
|
if (m_stackState == SourcesSet)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Cannot change sources once set."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Cannot change sources once set."));
|
||||||
if (m_stackState != Empty)
|
if (m_stackState != Empty)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Must set sources before parsing."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Must set sources before parsing."));
|
||||||
for (auto const& source: _sources)
|
for (auto source: _sources)
|
||||||
m_sources[source.first].scanner = make_shared<Scanner>(CharStream(/*content*/source.second, /*name*/source.first));
|
m_sources[source.first].scanner = make_shared<Scanner>(CharStream(/*content*/std::move(source.second), /*name*/source.first));
|
||||||
m_stackState = SourcesSet;
|
m_stackState = SourcesSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,7 +571,7 @@ string CompilerStack::assemblyString(string const& _contractName, StringMap _sou
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: cache the JSON
|
/// TODO: cache the JSON
|
||||||
Json::Value CompilerStack::assemblyJSON(string const& _contractName, StringMap _sourceCodes) const
|
Json::Value CompilerStack::assemblyJSON(string const& _contractName, StringMap const& _sourceCodes) const
|
||||||
{
|
{
|
||||||
if (m_stackState != CompilationSuccessful)
|
if (m_stackState != CompilationSuccessful)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Compilation was not successful."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Compilation was not successful."));
|
||||||
|
@ -150,7 +150,7 @@ public:
|
|||||||
void useMetadataLiteralSources(bool _metadataLiteralSources);
|
void useMetadataLiteralSources(bool _metadataLiteralSources);
|
||||||
|
|
||||||
/// Sets the sources. Must be set before parsing.
|
/// Sets the sources. Must be set before parsing.
|
||||||
void setSources(StringMap const& _sources);
|
void setSources(StringMap _sources);
|
||||||
|
|
||||||
/// Adds a response to an SMTLib2 query (identified by the hash of the query input).
|
/// Adds a response to an SMTLib2 query (identified by the hash of the query input).
|
||||||
/// Must be set before parsing.
|
/// Must be set before parsing.
|
||||||
@ -238,7 +238,7 @@ public:
|
|||||||
/// @returns a JSON representation of the assembly.
|
/// @returns a JSON representation of the assembly.
|
||||||
/// @arg _sourceCodes is the map of input files to source code strings
|
/// @arg _sourceCodes is the map of input files to source code strings
|
||||||
/// Prerequisite: Successful compilation.
|
/// Prerequisite: Successful compilation.
|
||||||
Json::Value assemblyJSON(std::string const& _contractName, StringMap _sourceCodes = StringMap()) const;
|
Json::Value assemblyJSON(std::string const& _contractName, StringMap const& _sourceCodes = StringMap()) const;
|
||||||
|
|
||||||
/// @returns a JSON representing the contract ABI.
|
/// @returns a JSON representing the contract ABI.
|
||||||
/// Prerequisite: Successful call to parse or compile.
|
/// Prerequisite: Successful call to parse or compile.
|
||||||
|
@ -133,7 +133,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else if (mode == Binary || mode == Hex)
|
else if (mode == Binary || mode == Hex)
|
||||||
{
|
{
|
||||||
auto bs = compileLLL(src, langutil::EVMVersion{}, optimise ? true : false, &errors, readFileAsString);
|
auto bs = compileLLL(std::move(src), langutil::EVMVersion{}, optimise ? true : false, &errors, readFileAsString);
|
||||||
if (mode == Hex)
|
if (mode == Hex)
|
||||||
cout << toHex(bs) << endl;
|
cout << toHex(bs) << endl;
|
||||||
else if (mode == Binary)
|
else if (mode == Binary)
|
||||||
@ -141,11 +141,11 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else if (mode == ParseTree)
|
else if (mode == ParseTree)
|
||||||
{
|
{
|
||||||
cout << parseLLL(src) << endl;
|
cout << parseLLL(std::move(src)) << endl;
|
||||||
}
|
}
|
||||||
else if (mode == Assembly)
|
else if (mode == Assembly)
|
||||||
{
|
{
|
||||||
cout << compileLLLToAsm(src, langutil::EVMVersion{}, optimise ? true : false, &errors, readFileAsString) << endl;
|
cout << compileLLLToAsm(std::move(src), langutil::EVMVersion{}, optimise ? true : false, &errors, readFileAsString) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const& i: errors)
|
for (auto const& i: errors)
|
||||||
|
@ -834,7 +834,7 @@ bool CommandLineInterface::processInput()
|
|||||||
{
|
{
|
||||||
string input = dev::readStandardInput();
|
string input = dev::readStandardInput();
|
||||||
StandardCompiler compiler(fileReader);
|
StandardCompiler compiler(fileReader);
|
||||||
sout() << compiler.compile(input) << endl;
|
sout() << compiler.compile(std::move(input)) << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +83,10 @@ Json::Value getContractResult(Json::Value const& _compilerResult, string const&
|
|||||||
return _compilerResult["contracts"][_file][_name];
|
return _compilerResult["contracts"][_file][_name];
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value compile(string const& _input)
|
Json::Value compile(string _input)
|
||||||
{
|
{
|
||||||
StandardCompiler compiler;
|
StandardCompiler compiler;
|
||||||
string output = compiler.compile(_input);
|
string output = compiler.compile(std::move(_input));
|
||||||
Json::Value ret;
|
Json::Value ret;
|
||||||
BOOST_REQUIRE(jsonParseStrict(output, ret));
|
BOOST_REQUIRE(jsonParseStrict(output, ret));
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user