if input was code block, only print code

This commit is contained in:
Daniel Lupu 2022-04-30 18:14:56 +03:00 committed by r0qs
parent 153e32896b
commit da28f9f315
No known key found for this signature in database
GPG Key ID: 61503DBA6667276C

View File

@ -132,6 +132,11 @@ public:
ObjectParser parser(errorReporter, m_dialect); ObjectParser parser(errorReporter, m_dialect);
auto scanner = make_shared<Scanner>(_charStream); auto scanner = make_shared<Scanner>(_charStream);
if (!m_inputWasCodeBlock && scanner->currentToken() == Token::LBrace) {
m_inputWasCodeBlock = true;
}
auto content = parser.parse(scanner, false); auto content = parser.parse(scanner, false);
if (content != nullptr) if (content != nullptr)
@ -276,7 +281,15 @@ public:
void parseAndPrint(string _source, string _objectPath) void parseAndPrint(string _source, string _objectPath)
{ {
parse(_source, _objectPath); parse(_source, _objectPath);
printObject();
}
void printObject()
{
if (!m_inputWasCodeBlock)
cout << m_object->toString(&m_dialect) << endl; cout << m_object->toString(&m_dialect) << endl;
else
cout << AsmPrinter{m_dialect}(*m_object->code) << endl;
} }
void resetNameDispenser() void resetNameDispenser()
@ -358,12 +371,14 @@ public:
cerr << boost::current_exception_diagnostic_information() << endl; cerr << boost::current_exception_diagnostic_information() << endl;
} }
cout << "----------------------" << endl; cout << "----------------------" << endl;
cout << m_object->toString(&m_dialect) << endl; printObject();
} }
} }
private: private:
shared_ptr<yul::Object> m_object; shared_ptr<yul::Object> m_object;
bool m_inputWasCodeBlock;
Dialect const& m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})}; Dialect const& m_dialect{EVMDialect::strictAssemblyForEVMObjects(EVMVersion{})};
set<YulString> const m_reservedIdentifiers = {}; set<YulString> const m_reservedIdentifiers = {};
shared_ptr<NameDispenser> m_nameDispenser = make_shared<NameDispenser>( shared_ptr<NameDispenser> m_nameDispenser = make_shared<NameDispenser>(