mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Parse default dialect and omit when printing.
This commit is contained in:
parent
90c98a3289
commit
fbe5bb0cce
@ -387,7 +387,7 @@ void CompilerContext::appendInlineAssembly(
|
|||||||
yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion);
|
yul::EVMDialect const& dialect = yul::EVMDialect::strictAssemblyForEVM(m_evmVersion);
|
||||||
auto parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false);
|
auto parserResult = yul::Parser(errorReporter, dialect).parse(scanner, false);
|
||||||
#ifdef SOL_OUTPUT_ASM
|
#ifdef SOL_OUTPUT_ASM
|
||||||
cout << yul::AsmPrinter()(*parserResult) << endl;
|
cout << yul::AsmPrinter(&dialect)(*parserResult) << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto reportError = [&](string const& _context)
|
auto reportError = [&](string const& _context)
|
||||||
@ -438,7 +438,7 @@ void CompilerContext::appendInlineAssembly(
|
|||||||
|
|
||||||
#ifdef SOL_OUTPUT_ASM
|
#ifdef SOL_OUTPUT_ASM
|
||||||
cout << "After optimizer:" << endl;
|
cout << "After optimizer:" << endl;
|
||||||
cout << yul::AsmPrinter()(*parserResult) << endl;
|
cout << yul::AsmPrinter(&dialect)(*parserResult) << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -892,6 +892,7 @@ bool IRGeneratorForStatements::visit(InlineAssembly const& _inlineAsm)
|
|||||||
|
|
||||||
solAssert(holds_alternative<yul::Block>(modified), "");
|
solAssert(holds_alternative<yul::Block>(modified), "");
|
||||||
|
|
||||||
|
// Do not provide dialect so that we get the full type information.
|
||||||
m_code << yul::AsmPrinter()(std::get<yul::Block>(std::move(modified))) << "\n";
|
m_code << yul::AsmPrinter()(std::get<yul::Block>(std::move(modified))) << "\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -608,7 +608,7 @@ Scope& AsmAnalyzer::scope(Block const* _block)
|
|||||||
}
|
}
|
||||||
void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location)
|
void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location)
|
||||||
{
|
{
|
||||||
if (!_type.empty() && !contains(m_dialect.types, _type))
|
if (!_type.empty() && !m_dialect.types.count(_type))
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
_location,
|
_location,
|
||||||
"\"" + _type.str() + "\" is not a valid type (user defined types are not yet supported)."
|
"\"" + _type.str() + "\" is not a valid type (user defined types are not yet supported)."
|
||||||
|
@ -366,7 +366,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
|
|||||||
location(),
|
location(),
|
||||||
kind,
|
kind,
|
||||||
YulString{currentLiteral()},
|
YulString{currentLiteral()},
|
||||||
{}
|
kind == LiteralKind::Boolean ? m_dialect.boolType : m_dialect.defaultType
|
||||||
};
|
};
|
||||||
advance();
|
advance();
|
||||||
if (currentToken() == Token::Colon)
|
if (currentToken() == Token::Colon)
|
||||||
@ -497,6 +497,9 @@ TypedName Parser::parseTypedName()
|
|||||||
typedName.location.end = endPosition();
|
typedName.location.end = endPosition();
|
||||||
typedName.type = expectAsmIdentifier();
|
typedName.type = expectAsmIdentifier();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
typedName.type = m_dialect.defaultType;
|
||||||
|
|
||||||
return typedName;
|
return typedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <libyul/AsmPrinter.h>
|
#include <libyul/AsmPrinter.h>
|
||||||
#include <libyul/AsmData.h>
|
#include <libyul/AsmData.h>
|
||||||
#include <libyul/Exceptions.h>
|
#include <libyul/Exceptions.h>
|
||||||
|
#include <libyul/Dialect.h>
|
||||||
|
|
||||||
#include <libsolutil/CommonData.h>
|
#include <libsolutil/CommonData.h>
|
||||||
|
|
||||||
@ -238,7 +239,8 @@ string AsmPrinter::formatTypedName(TypedName _variable) const
|
|||||||
|
|
||||||
string AsmPrinter::appendTypeName(YulString _type) const
|
string AsmPrinter::appendTypeName(YulString _type) const
|
||||||
{
|
{
|
||||||
if (!_type.empty())
|
if (_type.empty() || (m_dialect && _type == m_dialect->defaultType))
|
||||||
|
return {};
|
||||||
|
else
|
||||||
return ":" + _type.str();
|
return ":" + _type.str();
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,16 @@ namespace solidity::yul
|
|||||||
{
|
{
|
||||||
struct Dialect;
|
struct Dialect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a parsed Yul AST into readable string representation.
|
||||||
|
* Ignores source locations.
|
||||||
|
* If a dialect is provided, the dialect's default type is omitted.
|
||||||
|
*/
|
||||||
class AsmPrinter
|
class AsmPrinter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AsmPrinter() {}
|
AsmPrinter() {}
|
||||||
|
explicit AsmPrinter(Dialect const& _dialect): m_dialect(&_dialect) {}
|
||||||
|
|
||||||
std::string operator()(Literal const& _literal) const;
|
std::string operator()(Literal const& _literal) const;
|
||||||
std::string operator()(Identifier const& _identifier) const;
|
std::string operator()(Identifier const& _identifier) const;
|
||||||
@ -53,6 +59,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string formatTypedName(TypedName _variable) const;
|
std::string formatTypedName(TypedName _variable) const;
|
||||||
std::string appendTypeName(YulString _type) const;
|
std::string appendTypeName(YulString _type) const;
|
||||||
|
|
||||||
|
Dialect const* m_dialect = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ struct Dialect: boost::noncopyable
|
|||||||
YulString defaultType;
|
YulString defaultType;
|
||||||
/// Type used for the literals "true" and "false".
|
/// Type used for the literals "true" and "false".
|
||||||
YulString boolType;
|
YulString boolType;
|
||||||
std::vector<YulString> types;
|
std::set<YulString> types;
|
||||||
|
|
||||||
/// @returns the builtin function of the given name or a nullptr if it is not a builtin function.
|
/// @returns the builtin function of the given name or a nullptr if it is not a builtin function.
|
||||||
virtual BuiltinFunction const* builtin(YulString /*_name*/) const { return nullptr; }
|
virtual BuiltinFunction const* builtin(YulString /*_name*/) const { return nullptr; }
|
||||||
|
@ -218,6 +218,9 @@ EVMDialectTyped::EVMDialectTyped(langutil::EVMVersion _evmVersion, bool _objectA
|
|||||||
EVMDialect(_evmVersion, _objectAccess)
|
EVMDialect(_evmVersion, _objectAccess)
|
||||||
{
|
{
|
||||||
defaultType = "u256"_yulstring;
|
defaultType = "u256"_yulstring;
|
||||||
|
boolType = "bool"_yulstring;
|
||||||
|
types = {defaultType, boolType};
|
||||||
|
|
||||||
m_functions["lt"_yulstring].returns = {"bool"_yulstring};
|
m_functions["lt"_yulstring].returns = {"bool"_yulstring};
|
||||||
m_functions["gt"_yulstring].returns = {"bool"_yulstring};
|
m_functions["gt"_yulstring].returns = {"bool"_yulstring};
|
||||||
m_functions["slt"_yulstring].returns = {"bool"_yulstring};
|
m_functions["slt"_yulstring].returns = {"bool"_yulstring};
|
||||||
|
@ -365,7 +365,7 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line
|
|||||||
return TestResult::FatalError;
|
return TestResult::FatalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_obtainedResult = AsmPrinter{}(*m_ast) + "\n";
|
m_obtainedResult = AsmPrinter{*m_dialect}(*m_ast) + "\n";
|
||||||
|
|
||||||
if (m_optimizerStep != m_validatedSettings["step"])
|
if (m_optimizerStep != m_validatedSettings["step"])
|
||||||
{
|
{
|
||||||
|
@ -248,7 +248,7 @@ public:
|
|||||||
default:
|
default:
|
||||||
cout << "Unknown option." << endl;
|
cout << "Unknown option." << endl;
|
||||||
}
|
}
|
||||||
source = AsmPrinter{}(*m_ast);
|
source = AsmPrinter{m_dialect}(*m_ast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user