mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7611 from ethereum/yul-ast-cleanup-1
Yul AST cleanup (part 1)
This commit is contained in:
commit
b70af98c55
@ -27,7 +27,6 @@
|
|||||||
namespace yul
|
namespace yul
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Instruction;
|
|
||||||
struct Literal;
|
struct Literal;
|
||||||
struct Label;
|
struct Label;
|
||||||
struct Identifier;
|
struct Identifier;
|
||||||
@ -49,6 +48,6 @@ struct Block;
|
|||||||
struct TypedName;
|
struct TypedName;
|
||||||
|
|
||||||
using Expression = boost::variant<FunctionalInstruction, FunctionCall, Identifier, Literal>;
|
using Expression = boost::variant<FunctionalInstruction, FunctionCall, Identifier, Literal>;
|
||||||
using Statement = boost::variant<ExpressionStatement, Instruction, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Break, Continue, Leave, Block>;
|
using Statement = boost::variant<ExpressionStatement, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Break, Continue, Leave, Block>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -232,8 +232,8 @@ Statement Parser::parseStatement()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
solAssert(elementary.type() == typeid(Instruction), "Invalid elementary operation.");
|
solAssert(false, "Invalid elementary operation.");
|
||||||
return boost::get<Instruction>(elementary);
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,13 +39,6 @@ using namespace yul;
|
|||||||
|
|
||||||
//@TODO source locations
|
//@TODO source locations
|
||||||
|
|
||||||
string AsmPrinter::operator()(yul::Instruction const& _instruction) const
|
|
||||||
{
|
|
||||||
solAssert(!m_yul, "");
|
|
||||||
solAssert(isValidInstruction(_instruction.instruction), "Invalid instruction");
|
|
||||||
return boost::to_lower_copy(instructionInfo(_instruction.instruction).name);
|
|
||||||
}
|
|
||||||
|
|
||||||
string AsmPrinter::operator()(Literal const& _literal) const
|
string AsmPrinter::operator()(Literal const& _literal) const
|
||||||
{
|
{
|
||||||
switch (_literal.kind)
|
switch (_literal.kind)
|
||||||
|
@ -36,7 +36,6 @@ class AsmPrinter: public boost::static_visitor<std::string>
|
|||||||
public:
|
public:
|
||||||
explicit AsmPrinter(bool _yul = false): m_yul(_yul) {}
|
explicit AsmPrinter(bool _yul = false): m_yul(_yul) {}
|
||||||
|
|
||||||
std::string operator()(Instruction const& _instruction) const;
|
|
||||||
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;
|
||||||
std::string operator()(FunctionalInstruction const& _functionalInstruction) const;
|
std::string operator()(FunctionalInstruction const& _functionalInstruction) const;
|
||||||
|
@ -49,7 +49,6 @@ class ScopeFiller: public boost::static_visitor<bool>
|
|||||||
public:
|
public:
|
||||||
ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter);
|
ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter);
|
||||||
|
|
||||||
bool operator()(Instruction const&) { return true; }
|
|
||||||
bool operator()(Literal const&) { return true; }
|
bool operator()(Literal const&) { return true; }
|
||||||
bool operator()(Identifier const&) { return true; }
|
bool operator()(Identifier const&) { return true; }
|
||||||
bool operator()(FunctionalInstruction const&) { return true; }
|
bool operator()(FunctionalInstruction const&) { return true; }
|
||||||
|
@ -171,12 +171,6 @@ wasm::Expression EWasmCodeTransform::operator()(Literal const& _literal)
|
|||||||
return wasm::Literal{uint64_t(value)};
|
return wasm::Literal{uint64_t(value)};
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm::Expression EWasmCodeTransform::operator()(yul::Instruction const&)
|
|
||||||
{
|
|
||||||
yulAssert(false, "EVM instruction used for Wasm code generation.");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
wasm::Expression EWasmCodeTransform::operator()(If const& _if)
|
wasm::Expression EWasmCodeTransform::operator()(If const& _if)
|
||||||
{
|
{
|
||||||
return wasm::If{visit(*_if.condition), visit(_if.body.statements), {}};
|
return wasm::If{visit(*_if.condition), visit(_if.body.statements), {}};
|
||||||
|
@ -38,7 +38,6 @@ public:
|
|||||||
static std::string run(Dialect const& _dialect, yul::Block const& _ast);
|
static std::string run(Dialect const& _dialect, yul::Block const& _ast);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wasm::Expression operator()(yul::Instruction const& _instruction);
|
|
||||||
wasm::Expression operator()(yul::Literal const& _literal);
|
wasm::Expression operator()(yul::Literal const& _literal);
|
||||||
wasm::Expression operator()(yul::Identifier const& _identifier);
|
wasm::Expression operator()(yul::Identifier const& _identifier);
|
||||||
wasm::Expression operator()(yul::FunctionalInstruction const& _instr);
|
wasm::Expression operator()(yul::FunctionalInstruction const& _instr);
|
||||||
|
@ -30,12 +30,6 @@ using namespace std;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace yul;
|
using namespace yul;
|
||||||
|
|
||||||
Statement ASTCopier::operator()(Instruction const&)
|
|
||||||
{
|
|
||||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Statement ASTCopier::operator()(ExpressionStatement const& _statement)
|
Statement ASTCopier::operator()(ExpressionStatement const& _statement)
|
||||||
{
|
{
|
||||||
return ExpressionStatement{ _statement.location, translate(_statement.expression) };
|
return ExpressionStatement{ _statement.location, translate(_statement.expression) };
|
||||||
|
@ -49,7 +49,6 @@ class StatementCopier: public boost::static_visitor<Statement>
|
|||||||
public:
|
public:
|
||||||
virtual ~StatementCopier() = default;
|
virtual ~StatementCopier() = default;
|
||||||
virtual Statement operator()(ExpressionStatement const& _statement) = 0;
|
virtual Statement operator()(ExpressionStatement const& _statement) = 0;
|
||||||
virtual Statement operator()(Instruction const& _instruction) = 0;
|
|
||||||
virtual Statement operator()(Assignment const& _assignment) = 0;
|
virtual Statement operator()(Assignment const& _assignment) = 0;
|
||||||
virtual Statement operator()(VariableDeclaration const& _varDecl) = 0;
|
virtual Statement operator()(VariableDeclaration const& _varDecl) = 0;
|
||||||
virtual Statement operator()(If const& _if) = 0;
|
virtual Statement operator()(If const& _if) = 0;
|
||||||
@ -71,7 +70,6 @@ class ASTCopier: public ExpressionCopier, public StatementCopier
|
|||||||
public:
|
public:
|
||||||
virtual ~ASTCopier() = default;
|
virtual ~ASTCopier() = default;
|
||||||
Expression operator()(Literal const& _literal) override;
|
Expression operator()(Literal const& _literal) override;
|
||||||
Statement operator()(Instruction const& _instruction) override;
|
|
||||||
Expression operator()(Identifier const& _identifier) override;
|
Expression operator()(Identifier const& _identifier) override;
|
||||||
Expression operator()(FunctionalInstruction const& _instr) override;
|
Expression operator()(FunctionalInstruction const& _instr) override;
|
||||||
Expression operator()(FunctionCall const&) override;
|
Expression operator()(FunctionCall const&) override;
|
||||||
|
@ -43,7 +43,6 @@ class ASTWalker: public boost::static_visitor<>
|
|||||||
public:
|
public:
|
||||||
virtual ~ASTWalker() = default;
|
virtual ~ASTWalker() = default;
|
||||||
virtual void operator()(Literal const&) {}
|
virtual void operator()(Literal const&) {}
|
||||||
virtual void operator()(Instruction const&) { assertThrow(false, OptimizerException, ""); }
|
|
||||||
virtual void operator()(Identifier const&) {}
|
virtual void operator()(Identifier const&) {}
|
||||||
virtual void operator()(FunctionalInstruction const& _instr);
|
virtual void operator()(FunctionalInstruction const& _instr);
|
||||||
virtual void operator()(FunctionCall const& _funCall);
|
virtual void operator()(FunctionCall const& _funCall);
|
||||||
@ -79,7 +78,6 @@ class ASTModifier: public boost::static_visitor<>
|
|||||||
public:
|
public:
|
||||||
virtual ~ASTModifier() = default;
|
virtual ~ASTModifier() = default;
|
||||||
virtual void operator()(Literal&) {}
|
virtual void operator()(Literal&) {}
|
||||||
virtual void operator()(Instruction&) { assertThrow(false, OptimizerException, ""); }
|
|
||||||
virtual void operator()(Identifier&) {}
|
virtual void operator()(Identifier&) {}
|
||||||
virtual void operator()(FunctionalInstruction& _instr);
|
virtual void operator()(FunctionalInstruction& _instr);
|
||||||
virtual void operator()(FunctionCall& _funCall);
|
virtual void operator()(FunctionCall& _funCall);
|
||||||
|
@ -33,9 +33,10 @@ void ForLoopConditionIntoBody::operator()(ForLoop& _forLoop)
|
|||||||
{
|
{
|
||||||
if (m_dialect.booleanNegationFunction() && _forLoop.condition->type() != typeid(Literal))
|
if (m_dialect.booleanNegationFunction() && _forLoop.condition->type() != typeid(Literal))
|
||||||
{
|
{
|
||||||
langutil::SourceLocation loc = locationOf(*_forLoop.condition);
|
langutil::SourceLocation const loc = locationOf(*_forLoop.condition);
|
||||||
_forLoop.body.statements.insert(
|
|
||||||
_forLoop.body.statements.begin(),
|
_forLoop.body.statements.emplace(
|
||||||
|
begin(_forLoop.body.statements),
|
||||||
If {
|
If {
|
||||||
loc,
|
loc,
|
||||||
make_unique<Expression>(
|
make_unique<Expression>(
|
||||||
|
@ -159,11 +159,6 @@ bool SyntacticallyEqual::statementEqual(ForLoop const& _lhs, ForLoop const& _rhs
|
|||||||
statementEqual(_lhs.post, _rhs.post);
|
statementEqual(_lhs.post, _rhs.post);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntacticallyEqual::statementEqual(Instruction const&, Instruction const&)
|
|
||||||
{
|
|
||||||
assertThrow(false, OptimizerException, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SyntacticallyEqual::statementEqual(Block const& _lhs, Block const& _rhs)
|
bool SyntacticallyEqual::statementEqual(Block const& _lhs, Block const& _rhs)
|
||||||
{
|
{
|
||||||
return containerEqual(_lhs.statements, _rhs.statements, [this](Statement const& _lhsStmt, Statement const& _rhsStmt) -> bool {
|
return containerEqual(_lhs.statements, _rhs.statements, [this](Statement const& _lhsStmt, Statement const& _rhsStmt) -> bool {
|
||||||
|
@ -60,8 +60,6 @@ public:
|
|||||||
bool statementEqual(Leave const&, Leave const&) { return true; }
|
bool statementEqual(Leave const&, Leave const&) { return true; }
|
||||||
bool statementEqual(Block const& _lhs, Block const& _rhs);
|
bool statementEqual(Block const& _lhs, Block const& _rhs);
|
||||||
private:
|
private:
|
||||||
bool statementEqual(Instruction const& _lhs, Instruction const& _rhs);
|
|
||||||
|
|
||||||
bool visitDeclaration(TypedName const& _lhs, TypedName const& _rhs);
|
bool visitDeclaration(TypedName const& _lhs, TypedName const& _rhs);
|
||||||
|
|
||||||
template<typename U, typename V>
|
template<typename U, typename V>
|
||||||
|
Loading…
Reference in New Issue
Block a user