set proper execution num for creation objects

This commit is contained in:
Daniel Lupu 2022-12-24 00:32:24 +02:00 committed by r0qs
parent feb4880b50
commit 83fec48f54
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

@ -87,7 +87,7 @@ public:
}.printErrorInformation(_errors); }.printErrorInformation(_errors);
} }
void parse(string const& _input, string const& _objectPath) void parse(string const& _input)
{ {
ErrorList errors; ErrorList errors;
ErrorReporter errorReporter(errors); ErrorReporter errorReporter(errors);
@ -100,27 +100,17 @@ public:
auto scanner = make_shared<Scanner>(charStream); auto scanner = make_shared<Scanner>(charStream);
if (!m_inputIsCodeBlock && scanner->currentToken() == Token::LBrace) if (!m_inputIsCodeBlock && scanner->currentToken() == Token::LBrace)
{
m_inputIsCodeBlock = true; m_inputIsCodeBlock = true;
if (!_objectPath.empty()) m_object = parser.parse(scanner, false);
solThrow(Exception, "Object path argument cannot be used. Input is a code block.");
}
shared_ptr<Object> object = parser.parse(scanner, false); if (!m_object || !errorReporter.errors().empty())
if (!object || !errorReporter.errors().empty())
{ {
cerr << "Error parsing source." << endl; cerr << "Error parsing source." << endl;
printErrors(charStream, errors); printErrors(charStream, errors);
solThrow(Exception, "Could not parse source."); solThrow(Exception, "Could not parse source.");
} }
m_object = Object::objectAt(object, _objectPath);
if (m_object == nullptr)
solThrow(Exception, "Assembly object not found.");
runCodeAnalyzer(errorReporter); runCodeAnalyzer(errorReporter);
} }
catch(...) catch(...)
@ -234,7 +224,11 @@ public:
{ {
applyFunctionToObjectAndSubobjects( applyFunctionToObjectAndSubobjects(
*m_object, *m_object,
[&](Object& _object) { OptimiserSuite{*m_context}.runSequence(_steps, *_object.code); } [&](Object& _object)
{
OptimiserStepContext context = createOptimiserStepContext(_object);
OptimiserSuite{context}.runSequence(_steps, *_object.code);
}
); );
} }
@ -242,7 +236,11 @@ public:
{ {
applyFunctionToObjectAndSubobjects( applyFunctionToObjectAndSubobjects(
*m_object, *m_object,
[&](Object& _object) { VarNameCleaner::run(*m_context, *_object.code); } [&](Object& _object)
{
OptimiserStepContext context = createOptimiserStepContext(_object);
VarNameCleaner::run(context, *_object.code);
}
); );
} }
@ -254,10 +252,17 @@ public:
); );
} }
void printObject() void printObject(string const& _objectPath)
{ {
if (!m_inputIsCodeBlock) if (!m_inputIsCodeBlock)
cout << m_object->toString(&m_dialect) << endl; {
shared_ptr<Object> subObject = Object::objectAt(m_object, _objectPath);
if (subObject == nullptr)
solThrow(Exception, "Assembly object not found.");
cout << subObject->toString(&m_dialect) << endl;
}
else else
{ {
yulAssert( yulAssert(
@ -265,6 +270,9 @@ public:
"Unexpected subObjects found." "Unexpected subObjects found."
); );
if (!_objectPath.empty())
solThrow(Exception, "Object path argument cannot be used. Input is a code block.");
cout << AsmPrinter{m_dialect}(*m_object->code) << endl; cout << AsmPrinter{m_dialect}(*m_object->code) << endl;
} }
} }
@ -275,22 +283,25 @@ public:
m_dialect, m_dialect,
m_reservedIdentifiers m_reservedIdentifiers
); );
}
m_context = make_shared<OptimiserStepContext>( void parseAndRunSteps(string const& _source, string const& _steps)
OptimiserStepContext{ {
parse(_source);
runCodeDisambiguator();
runSequence(_steps);
}
OptimiserStepContext createOptimiserStepContext(Object& _object)
{
bool isCreation = m_object.get() == &_object || !boost::ends_with(_object.name.str(), "_deployed");
return OptimiserStepContext{
m_dialect, m_dialect,
*m_nameDispenser, *m_nameDispenser,
m_reservedIdentifiers, m_reservedIdentifiers,
solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment isCreation ? nullopt : make_optional(OptimiserSettings::standard().expectedExecutionsPerDeployment)
} };
);
}
void parseAndRunSteps(string const& _source, string const& _objectPath, string const& _steps)
{
parse(_source, _objectPath);
runCodeDisambiguator();
runSequence(_steps);
} }
void runInteractive(string _source, string const& _objectPath, bool _disambiguated = false) void runInteractive(string _source, string const& _objectPath, bool _disambiguated = false)
@ -299,7 +310,7 @@ public:
ErrorReporter errorReporter(errors); ErrorReporter errorReporter(errors);
bool disambiguated = _disambiguated; bool disambiguated = _disambiguated;
parse(_source, _objectPath); parse(_source);
while (true) while (true)
{ {
@ -346,7 +357,7 @@ public:
cerr << boost::current_exception_diagnostic_information() << endl; cerr << boost::current_exception_diagnostic_information() << endl;
} }
cout << "----------------------" << endl; cout << "----------------------" << endl;
printObject(); printObject(_objectPath);
} }
} }
@ -360,14 +371,6 @@ private:
m_dialect, m_dialect,
m_reservedIdentifiers m_reservedIdentifiers
); );
shared_ptr<OptimiserStepContext> m_context = make_shared<OptimiserStepContext>(
OptimiserStepContext{
m_dialect,
*m_nameDispenser,
m_reservedIdentifiers,
solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment
}
);
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
@ -400,8 +403,9 @@ int main(int argc, char** argv)
( (
"object", "object",
po::value<string>()->value_name("path"), po::value<string>()->value_name("path"),
"Dotted path to a specific Yul object in the source. " "Dotted path to a specific Yul object in the source to print after running the steps. "
"If not specified, the top-level object is used. " "If not specified, the top-level object will be selected. "
"The object will be printed recursively. "
"Only valid if the source actually contains objects (rather than a block of Yul code)." "Only valid if the source actually contains objects (rather than a block of Yul code)."
) )
( (
@ -461,8 +465,8 @@ int main(int argc, char** argv)
if (!nonInteractive) if (!nonInteractive)
{ {
yulOpti.parse(input, objectPath); yulOpti.parse(input);
yulOpti.printObject(); yulOpti.printObject(objectPath);
} }
if (arguments.count("steps")) if (arguments.count("steps"))
@ -470,7 +474,7 @@ int main(int argc, char** argv)
string sequence = arguments["steps"].as<string>(); string sequence = arguments["steps"].as<string>();
if (!nonInteractive) if (!nonInteractive)
cout << "----------------------" << endl; cout << "----------------------" << endl;
yulOpti.parseAndRunSteps(input, objectPath, sequence); yulOpti.parseAndRunSteps(input, sequence);
disambiguated = true; disambiguated = true;
} }
if (!nonInteractive) if (!nonInteractive)