mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Assembly: Remove StackAssignment instruction.
This commit is contained in:
parent
5a52fa547e
commit
5e8d348f66
@ -763,7 +763,6 @@ Grammar::
|
||||
AssemblyExpression |
|
||||
AssemblyLocalDefinition |
|
||||
AssemblyAssignment |
|
||||
AssemblyStackAssignment |
|
||||
LabelDefinition |
|
||||
AssemblyIf |
|
||||
AssemblySwitch |
|
||||
@ -780,7 +779,6 @@ Grammar::
|
||||
AssemblyAssignment = IdentifierOrList ':=' AssemblyExpression
|
||||
IdentifierOrList = Identifier | '(' IdentifierList ')'
|
||||
IdentifierList = Identifier ( ',' Identifier)*
|
||||
AssemblyStackAssignment = '=:' Identifier
|
||||
LabelDefinition = Identifier ':'
|
||||
AssemblyIf = 'if' AssemblyExpression AssemblyBlock
|
||||
AssemblySwitch = 'switch' AssemblyExpression AssemblyCase*
|
||||
|
@ -58,7 +58,6 @@ public:
|
||||
{
|
||||
boost::apply_visitor(*this, _expr.expression);
|
||||
}
|
||||
void operator()(yul::StackAssignment const&) {}
|
||||
void operator()(yul::Assignment const& _assignment)
|
||||
{
|
||||
boost::apply_visitor(*this, *_assignment.value);
|
||||
|
@ -232,17 +232,6 @@ bool AsmAnalyzer::operator()(ExpressionStatement const& _statement)
|
||||
return success;
|
||||
}
|
||||
|
||||
bool AsmAnalyzer::operator()(StackAssignment const& _assignment)
|
||||
{
|
||||
checkLooseFeature(
|
||||
_assignment.location,
|
||||
"The use of stack assignment is disallowed. Please use assignment in functional notation instead."
|
||||
);
|
||||
bool success = checkAssignment(_assignment.variableName, size_t(-1));
|
||||
m_info.stackHeightInfo[&_assignment] = m_stackHeight;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool AsmAnalyzer::operator()(Assignment const& _assignment)
|
||||
{
|
||||
solAssert(_assignment.value, "");
|
||||
|
@ -87,7 +87,6 @@ public:
|
||||
bool operator()(FunctionalInstruction const& _functionalInstruction);
|
||||
bool operator()(Label const& _label);
|
||||
bool operator()(ExpressionStatement const&);
|
||||
bool operator()(StackAssignment const&);
|
||||
bool operator()(Assignment const& _assignment);
|
||||
bool operator()(VariableDeclaration const& _variableDeclaration);
|
||||
bool operator()(FunctionDefinition const& _functionDefinition);
|
||||
|
@ -51,8 +51,6 @@ struct Literal { langutil::SourceLocation location; LiteralKind kind; YulString
|
||||
struct Identifier { langutil::SourceLocation location; YulString name; };
|
||||
/// Jump label ("name:")
|
||||
struct Label { langutil::SourceLocation location; YulString name; };
|
||||
/// Assignment from stack (":= x", moves stack top into x, potentially multiple slots)
|
||||
struct StackAssignment { langutil::SourceLocation location; Identifier variableName; };
|
||||
/// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand
|
||||
/// side and requires x to occupy exactly one stack slot.
|
||||
///
|
||||
|
@ -30,7 +30,6 @@ namespace yul
|
||||
struct Instruction;
|
||||
struct Literal;
|
||||
struct Label;
|
||||
struct StackAssignment;
|
||||
struct Identifier;
|
||||
struct Assignment;
|
||||
struct VariableDeclaration;
|
||||
@ -49,6 +48,6 @@ struct Block;
|
||||
struct TypedName;
|
||||
|
||||
using Expression = boost::variant<FunctionalInstruction, FunctionCall, Identifier, Literal>;
|
||||
using Statement = boost::variant<ExpressionStatement, Instruction, Label, StackAssignment, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Break, Continue, Block>;
|
||||
using Statement = boost::variant<ExpressionStatement, Instruction, Label, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Break, Continue, Block>;
|
||||
|
||||
}
|
||||
|
@ -144,23 +144,6 @@ Statement Parser::parseStatement()
|
||||
m_scanner->next();
|
||||
return stmt;
|
||||
}
|
||||
case Token::Assign:
|
||||
{
|
||||
if (m_dialect.flavour != AsmFlavour::Loose)
|
||||
break;
|
||||
StackAssignment assignment = createWithLocation<StackAssignment>();
|
||||
advance();
|
||||
expectToken(Token::Colon);
|
||||
assignment.variableName.location = location();
|
||||
assignment.variableName.name = YulString(currentLiteral());
|
||||
if (m_dialect.builtin(assignment.variableName.name))
|
||||
fatalParserError("Identifier expected, got builtin symbol.");
|
||||
else if (instructions().count(assignment.variableName.name.str()))
|
||||
fatalParserError("Identifier expected, got instruction name.");
|
||||
assignment.location.end = endPosition();
|
||||
expectToken(Token::Identifier);
|
||||
return Statement{move(assignment)};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -120,13 +120,6 @@ string AsmPrinter::operator()(Label const& _label) const
|
||||
return _label.name.str() + ":";
|
||||
}
|
||||
|
||||
string AsmPrinter::operator()(StackAssignment const& _assignment) const
|
||||
{
|
||||
solAssert(!m_yul, "");
|
||||
solAssert(!_assignment.variableName.name.empty(), "Invalid variable name.");
|
||||
return "=: " + (*this)(_assignment.variableName);
|
||||
}
|
||||
|
||||
string AsmPrinter::operator()(Assignment const& _assignment) const
|
||||
{
|
||||
solAssert(_assignment.variableNames.size() >= 1, "");
|
||||
|
@ -42,7 +42,6 @@ public:
|
||||
std::string operator()(FunctionalInstruction const& _functionalInstruction) const;
|
||||
std::string operator()(ExpressionStatement const& _expr) const;
|
||||
std::string operator()(Label const& _label) const;
|
||||
std::string operator()(StackAssignment const& _assignment) const;
|
||||
std::string operator()(Assignment const& _assignment) const;
|
||||
std::string operator()(VariableDeclaration const& _variableDeclaration) const;
|
||||
std::string operator()(FunctionDefinition const& _functionDefinition) const;
|
||||
|
@ -55,7 +55,6 @@ public:
|
||||
bool operator()(FunctionalInstruction const&) { return true; }
|
||||
bool operator()(ExpressionStatement const& _expr);
|
||||
bool operator()(Label const& _label);
|
||||
bool operator()(StackAssignment const&) { return true; }
|
||||
bool operator()(Assignment const&) { return true; }
|
||||
bool operator()(VariableDeclaration const& _variableDeclaration);
|
||||
bool operator()(FunctionDefinition const& _functionDefinition);
|
||||
|
@ -250,14 +250,6 @@ void CodeTransform::operator()(Assignment const& _assignment)
|
||||
checkStackHeight(&_assignment);
|
||||
}
|
||||
|
||||
void CodeTransform::operator()(StackAssignment const& _assignment)
|
||||
{
|
||||
solAssert(!m_allowStackOpt, "");
|
||||
m_assembly.setSourceLocation(_assignment.location);
|
||||
generateAssignment(_assignment.variableName);
|
||||
checkStackHeight(&_assignment);
|
||||
}
|
||||
|
||||
void CodeTransform::operator()(ExpressionStatement const& _statement)
|
||||
{
|
||||
m_assembly.setSourceLocation(_statement.location);
|
||||
|
@ -178,7 +178,6 @@ public:
|
||||
void operator()(FunctionCall const&);
|
||||
void operator()(ExpressionStatement const& _statement);
|
||||
void operator()(Label const& _label);
|
||||
void operator()(StackAssignment const& _assignment);
|
||||
void operator()(Assignment const& _assignment);
|
||||
void operator()(VariableDeclaration const& _varDecl);
|
||||
void operator()(If const& _if);
|
||||
|
@ -108,12 +108,6 @@ wasm::Expression EWasmCodeTransform::operator()(Assignment const& _assignment)
|
||||
return generateMultiAssignment(move(variableNames), visit(*_assignment.value));
|
||||
}
|
||||
|
||||
wasm::Expression EWasmCodeTransform::operator()(StackAssignment const&)
|
||||
{
|
||||
yulAssert(false, "");
|
||||
return {};
|
||||
}
|
||||
|
||||
wasm::Expression EWasmCodeTransform::operator()(ExpressionStatement const& _statement)
|
||||
{
|
||||
return visitReturnByValue(_statement.expression);
|
||||
|
@ -45,7 +45,6 @@ public:
|
||||
wasm::Expression operator()(yul::FunctionCall const&);
|
||||
wasm::Expression operator()(yul::ExpressionStatement const& _statement);
|
||||
wasm::Expression operator()(yul::Label const& _label);
|
||||
wasm::Expression operator()(yul::StackAssignment const& _assignment);
|
||||
wasm::Expression operator()(yul::Assignment const& _assignment);
|
||||
wasm::Expression operator()(yul::VariableDeclaration const& _varDecl);
|
||||
wasm::Expression operator()(yul::If const& _if);
|
||||
|
@ -59,12 +59,6 @@ Statement ASTCopier::operator()(Assignment const& _assignment)
|
||||
};
|
||||
}
|
||||
|
||||
Statement ASTCopier::operator()(StackAssignment const&)
|
||||
{
|
||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
||||
return {};
|
||||
}
|
||||
|
||||
Statement ASTCopier::operator()(Label const&)
|
||||
{
|
||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
||||
|
@ -51,7 +51,6 @@ public:
|
||||
virtual Statement operator()(ExpressionStatement const& _statement) = 0;
|
||||
virtual Statement operator()(Instruction const& _instruction) = 0;
|
||||
virtual Statement operator()(Label const& _label) = 0;
|
||||
virtual Statement operator()(StackAssignment const& _assignment) = 0;
|
||||
virtual Statement operator()(Assignment const& _assignment) = 0;
|
||||
virtual Statement operator()(VariableDeclaration const& _varDecl) = 0;
|
||||
virtual Statement operator()(If const& _if) = 0;
|
||||
@ -78,7 +77,6 @@ public:
|
||||
Expression operator()(FunctionCall const&) override;
|
||||
Statement operator()(ExpressionStatement const& _statement) override;
|
||||
Statement operator()(Label const& _label) override;
|
||||
Statement operator()(StackAssignment const& _assignment) override;
|
||||
Statement operator()(Assignment const& _assignment) override;
|
||||
Statement operator()(VariableDeclaration const& _varDecl) override;
|
||||
Statement operator()(If const& _if) override;
|
||||
|
@ -49,7 +49,6 @@ public:
|
||||
virtual void operator()(FunctionCall const& _funCall);
|
||||
virtual void operator()(ExpressionStatement const& _statement);
|
||||
virtual void operator()(Label const&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(StackAssignment const&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(Assignment const& _assignment);
|
||||
virtual void operator()(VariableDeclaration const& _varDecl);
|
||||
virtual void operator()(If const& _if);
|
||||
@ -86,7 +85,6 @@ public:
|
||||
virtual void operator()(FunctionCall& _funCall);
|
||||
virtual void operator()(ExpressionStatement& _statement);
|
||||
virtual void operator()(Label&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(StackAssignment&) { assertThrow(false, OptimizerException, ""); }
|
||||
virtual void operator()(Assignment& _assignment);
|
||||
virtual void operator()(VariableDeclaration& _varDecl);
|
||||
virtual void operator()(If& _if);
|
||||
|
@ -169,11 +169,6 @@ bool SyntacticallyEqual::statementEqual(Label const&, Label const&)
|
||||
assertThrow(false, OptimizerException, "");
|
||||
}
|
||||
|
||||
bool SyntacticallyEqual::statementEqual(StackAssignment const&, StackAssignment const&)
|
||||
{
|
||||
assertThrow(false, OptimizerException, "");
|
||||
}
|
||||
|
||||
bool SyntacticallyEqual::statementEqual(Block const& _lhs, Block const& _rhs)
|
||||
{
|
||||
return containerEqual(_lhs.statements, _rhs.statements, [this](Statement const& _lhsStmt, Statement const& _rhsStmt) -> bool {
|
||||
|
@ -61,7 +61,6 @@ public:
|
||||
private:
|
||||
bool statementEqual(Instruction const& _lhs, Instruction const& _rhs);
|
||||
bool statementEqual(Label const& _lhs, Label const& _rhs);
|
||||
bool statementEqual(StackAssignment const& _lhs, StackAssignment const& _rhs);
|
||||
|
||||
bool visitDeclaration(TypedName const& _lhs, TypedName const& _rhs);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user