mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Assembly: Remove Label instruction.
This commit is contained in:
parent
5e8d348f66
commit
e23998fc6e
@ -763,7 +763,6 @@ Grammar::
|
|||||||
AssemblyExpression |
|
AssemblyExpression |
|
||||||
AssemblyLocalDefinition |
|
AssemblyLocalDefinition |
|
||||||
AssemblyAssignment |
|
AssemblyAssignment |
|
||||||
LabelDefinition |
|
|
||||||
AssemblyIf |
|
AssemblyIf |
|
||||||
AssemblySwitch |
|
AssemblySwitch |
|
||||||
AssemblyFunctionDefinition |
|
AssemblyFunctionDefinition |
|
||||||
@ -779,7 +778,6 @@ Grammar::
|
|||||||
AssemblyAssignment = IdentifierOrList ':=' AssemblyExpression
|
AssemblyAssignment = IdentifierOrList ':=' AssemblyExpression
|
||||||
IdentifierOrList = Identifier | '(' IdentifierList ')'
|
IdentifierOrList = Identifier | '(' IdentifierList ')'
|
||||||
IdentifierList = Identifier ( ',' Identifier)*
|
IdentifierList = Identifier ( ',' Identifier)*
|
||||||
LabelDefinition = Identifier ':'
|
|
||||||
AssemblyIf = 'if' AssemblyExpression AssemblyBlock
|
AssemblyIf = 'if' AssemblyExpression AssemblyBlock
|
||||||
AssemblySwitch = 'switch' AssemblyExpression AssemblyCase*
|
AssemblySwitch = 'switch' AssemblyExpression AssemblyCase*
|
||||||
( 'default' AssemblyBlock )?
|
( 'default' AssemblyBlock )?
|
||||||
|
@ -41,7 +41,6 @@ public:
|
|||||||
m_dialect(_dialect),
|
m_dialect(_dialect),
|
||||||
m_reportMutability(_reportMutability) {}
|
m_reportMutability(_reportMutability) {}
|
||||||
|
|
||||||
void operator()(yul::Label const&) { }
|
|
||||||
void operator()(yul::Instruction const& _instruction)
|
void operator()(yul::Instruction const& _instruction)
|
||||||
{
|
{
|
||||||
checkInstruction(_instruction.location, _instruction.instruction);
|
checkInstruction(_instruction.location, _instruction.instruction);
|
||||||
|
@ -87,18 +87,6 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
|
|||||||
return analysisInfo;
|
return analysisInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AsmAnalyzer::operator()(Label const& _label)
|
|
||||||
{
|
|
||||||
solAssert(!_label.name.empty(), "");
|
|
||||||
checkLooseFeature(
|
|
||||||
_label.location,
|
|
||||||
"The use of labels is disallowed. Please use \"if\", \"switch\", \"for\" or function calls instead."
|
|
||||||
);
|
|
||||||
m_info.stackHeightInfo[&_label] = m_stackHeight;
|
|
||||||
warnOnInstructions(dev::eth::Instruction::JUMPDEST, _label.location);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AsmAnalyzer::operator()(yul::Instruction const& _instruction)
|
bool AsmAnalyzer::operator()(yul::Instruction const& _instruction)
|
||||||
{
|
{
|
||||||
checkLooseFeature(
|
checkLooseFeature(
|
||||||
|
@ -85,7 +85,6 @@ public:
|
|||||||
bool operator()(Literal const& _literal);
|
bool operator()(Literal const& _literal);
|
||||||
bool operator()(Identifier const&);
|
bool operator()(Identifier const&);
|
||||||
bool operator()(FunctionalInstruction const& _functionalInstruction);
|
bool operator()(FunctionalInstruction const& _functionalInstruction);
|
||||||
bool operator()(Label const& _label);
|
|
||||||
bool operator()(ExpressionStatement const&);
|
bool operator()(ExpressionStatement const&);
|
||||||
bool operator()(Assignment const& _assignment);
|
bool operator()(Assignment const& _assignment);
|
||||||
bool operator()(VariableDeclaration const& _variableDeclaration);
|
bool operator()(VariableDeclaration const& _variableDeclaration);
|
||||||
|
@ -49,8 +49,6 @@ enum class LiteralKind { Number, Boolean, String };
|
|||||||
struct Literal { langutil::SourceLocation location; LiteralKind kind; YulString value; Type type; };
|
struct Literal { langutil::SourceLocation location; LiteralKind kind; YulString value; Type type; };
|
||||||
/// External / internal identifier or label reference
|
/// External / internal identifier or label reference
|
||||||
struct Identifier { langutil::SourceLocation location; YulString name; };
|
struct Identifier { langutil::SourceLocation location; YulString name; };
|
||||||
/// Jump label ("name:")
|
|
||||||
struct Label { langutil::SourceLocation location; YulString name; };
|
|
||||||
/// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand
|
/// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand
|
||||||
/// side and requires x to occupy exactly one stack slot.
|
/// side and requires x to occupy exactly one stack slot.
|
||||||
///
|
///
|
||||||
|
@ -48,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, Label, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Break, Continue, Block>;
|
using Statement = boost::variant<ExpressionStatement, Instruction, Assignment, VariableDeclaration, FunctionDefinition, If, Switch, ForLoop, Break, Continue, Block>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -205,23 +205,6 @@ Statement Parser::parseStatement()
|
|||||||
|
|
||||||
return Statement{std::move(assignment)};
|
return Statement{std::move(assignment)};
|
||||||
}
|
}
|
||||||
case Token::Colon:
|
|
||||||
{
|
|
||||||
if (elementary.type() != typeid(Identifier))
|
|
||||||
fatalParserError("Label name must precede \":\".");
|
|
||||||
|
|
||||||
Identifier const& identifier = boost::get<Identifier>(elementary);
|
|
||||||
|
|
||||||
advance();
|
|
||||||
|
|
||||||
// label
|
|
||||||
if (m_dialect.flavour != AsmFlavour::Loose)
|
|
||||||
fatalParserError("Labels are not supported.");
|
|
||||||
|
|
||||||
Label label = createWithLocation<Label>(identifier.location);
|
|
||||||
label.name = identifier.name;
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if (m_dialect.flavour != AsmFlavour::Loose)
|
if (m_dialect.flavour != AsmFlavour::Loose)
|
||||||
fatalParserError("Call or assignment expected.");
|
fatalParserError("Call or assignment expected.");
|
||||||
|
@ -113,13 +113,6 @@ string AsmPrinter::operator()(ExpressionStatement const& _statement) const
|
|||||||
return boost::apply_visitor(*this, _statement.expression);
|
return boost::apply_visitor(*this, _statement.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
string AsmPrinter::operator()(Label const& _label) const
|
|
||||||
{
|
|
||||||
solAssert(!m_yul, "");
|
|
||||||
solAssert(!_label.name.empty(), "Invalid label.");
|
|
||||||
return _label.name.str() + ":";
|
|
||||||
}
|
|
||||||
|
|
||||||
string AsmPrinter::operator()(Assignment const& _assignment) const
|
string AsmPrinter::operator()(Assignment const& _assignment) const
|
||||||
{
|
{
|
||||||
solAssert(_assignment.variableNames.size() >= 1, "");
|
solAssert(_assignment.variableNames.size() >= 1, "");
|
||||||
|
@ -41,7 +41,6 @@ public:
|
|||||||
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;
|
||||||
std::string operator()(ExpressionStatement const& _expr) const;
|
std::string operator()(ExpressionStatement const& _expr) const;
|
||||||
std::string operator()(Label const& _label) const;
|
|
||||||
std::string operator()(Assignment const& _assignment) const;
|
std::string operator()(Assignment const& _assignment) const;
|
||||||
std::string operator()(VariableDeclaration const& _variableDeclaration) const;
|
std::string operator()(VariableDeclaration const& _variableDeclaration) const;
|
||||||
std::string operator()(FunctionDefinition const& _functionDefinition) const;
|
std::string operator()(FunctionDefinition const& _functionDefinition) const;
|
||||||
|
@ -50,20 +50,6 @@ bool ScopeFiller::operator()(ExpressionStatement const& _expr)
|
|||||||
return boost::apply_visitor(*this, _expr.expression);
|
return boost::apply_visitor(*this, _expr.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScopeFiller::operator()(Label const& _item)
|
|
||||||
{
|
|
||||||
if (!m_currentScope->registerLabel(_item.name))
|
|
||||||
{
|
|
||||||
//@TODO secondary location
|
|
||||||
m_errorReporter.declarationError(
|
|
||||||
_item.location,
|
|
||||||
"Label name " + _item.name.str() + " already taken in this scope."
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScopeFiller::operator()(VariableDeclaration const& _varDecl)
|
bool ScopeFiller::operator()(VariableDeclaration const& _varDecl)
|
||||||
{
|
{
|
||||||
for (auto const& variable: _varDecl.variables)
|
for (auto const& variable: _varDecl.variables)
|
||||||
|
@ -54,7 +54,6 @@ public:
|
|||||||
bool operator()(Identifier const&) { return true; }
|
bool operator()(Identifier const&) { return true; }
|
||||||
bool operator()(FunctionalInstruction const&) { return true; }
|
bool operator()(FunctionalInstruction const&) { return true; }
|
||||||
bool operator()(ExpressionStatement const& _expr);
|
bool operator()(ExpressionStatement const& _expr);
|
||||||
bool operator()(Label const& _label);
|
|
||||||
bool operator()(Assignment const&) { return true; }
|
bool operator()(Assignment const&) { return true; }
|
||||||
bool operator()(VariableDeclaration const& _variableDeclaration);
|
bool operator()(VariableDeclaration const& _variableDeclaration);
|
||||||
bool operator()(FunctionDefinition const& _functionDefinition);
|
bool operator()(FunctionDefinition const& _functionDefinition);
|
||||||
|
@ -257,17 +257,6 @@ void CodeTransform::operator()(ExpressionStatement const& _statement)
|
|||||||
checkStackHeight(&_statement);
|
checkStackHeight(&_statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeTransform::operator()(Label const& _label)
|
|
||||||
{
|
|
||||||
solAssert(!m_allowStackOpt, "");
|
|
||||||
m_assembly.setSourceLocation(_label.location);
|
|
||||||
solAssert(m_scope, "");
|
|
||||||
solAssert(m_scope->identifiers.count(_label.name), "");
|
|
||||||
Scope::Label& label = boost::get<Scope::Label>(m_scope->identifiers.at(_label.name));
|
|
||||||
m_assembly.appendLabel(labelID(label));
|
|
||||||
checkStackHeight(&_label);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CodeTransform::operator()(FunctionCall const& _call)
|
void CodeTransform::operator()(FunctionCall const& _call)
|
||||||
{
|
{
|
||||||
solAssert(m_scope, "");
|
solAssert(m_scope, "");
|
||||||
|
@ -177,7 +177,6 @@ public:
|
|||||||
void operator()(FunctionalInstruction const& _instr);
|
void operator()(FunctionalInstruction const& _instr);
|
||||||
void operator()(FunctionCall const&);
|
void operator()(FunctionCall const&);
|
||||||
void operator()(ExpressionStatement const& _statement);
|
void operator()(ExpressionStatement const& _statement);
|
||||||
void operator()(Label const& _label);
|
|
||||||
void operator()(Assignment const& _assignment);
|
void operator()(Assignment const& _assignment);
|
||||||
void operator()(VariableDeclaration const& _varDecl);
|
void operator()(VariableDeclaration const& _varDecl);
|
||||||
void operator()(If const& _if);
|
void operator()(If const& _if);
|
||||||
|
@ -113,12 +113,6 @@ wasm::Expression EWasmCodeTransform::operator()(ExpressionStatement const& _stat
|
|||||||
return visitReturnByValue(_statement.expression);
|
return visitReturnByValue(_statement.expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm::Expression EWasmCodeTransform::operator()(Label const&)
|
|
||||||
{
|
|
||||||
yulAssert(false, "");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
wasm::Expression EWasmCodeTransform::operator()(FunctionalInstruction const& _f)
|
wasm::Expression EWasmCodeTransform::operator()(FunctionalInstruction const& _f)
|
||||||
{
|
{
|
||||||
yulAssert(false, "EVM instruction in ewasm code: " + eth::instructionInfo(_f.instruction).name);
|
yulAssert(false, "EVM instruction in ewasm code: " + eth::instructionInfo(_f.instruction).name);
|
||||||
|
@ -44,7 +44,6 @@ public:
|
|||||||
wasm::Expression operator()(yul::FunctionalInstruction const& _instr);
|
wasm::Expression operator()(yul::FunctionalInstruction const& _instr);
|
||||||
wasm::Expression operator()(yul::FunctionCall const&);
|
wasm::Expression operator()(yul::FunctionCall const&);
|
||||||
wasm::Expression operator()(yul::ExpressionStatement const& _statement);
|
wasm::Expression operator()(yul::ExpressionStatement const& _statement);
|
||||||
wasm::Expression operator()(yul::Label const& _label);
|
|
||||||
wasm::Expression operator()(yul::Assignment const& _assignment);
|
wasm::Expression operator()(yul::Assignment const& _assignment);
|
||||||
wasm::Expression operator()(yul::VariableDeclaration const& _varDecl);
|
wasm::Expression operator()(yul::VariableDeclaration const& _varDecl);
|
||||||
wasm::Expression operator()(yul::If const& _if);
|
wasm::Expression operator()(yul::If const& _if);
|
||||||
|
@ -59,12 +59,6 @@ Statement ASTCopier::operator()(Assignment const& _assignment)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Statement ASTCopier::operator()(Label const&)
|
|
||||||
{
|
|
||||||
assertThrow(false, OptimizerException, "Invalid operation.");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Expression ASTCopier::operator()(FunctionCall const& _call)
|
Expression ASTCopier::operator()(FunctionCall const& _call)
|
||||||
{
|
{
|
||||||
return FunctionCall{
|
return FunctionCall{
|
||||||
|
@ -50,7 +50,6 @@ 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()(Instruction const& _instruction) = 0;
|
||||||
virtual Statement operator()(Label const& _label) = 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;
|
||||||
@ -76,7 +75,6 @@ public:
|
|||||||
Expression operator()(FunctionalInstruction const& _instr) override;
|
Expression operator()(FunctionalInstruction const& _instr) override;
|
||||||
Expression operator()(FunctionCall const&) override;
|
Expression operator()(FunctionCall const&) override;
|
||||||
Statement operator()(ExpressionStatement const& _statement) override;
|
Statement operator()(ExpressionStatement const& _statement) override;
|
||||||
Statement operator()(Label const& _label) override;
|
|
||||||
Statement operator()(Assignment const& _assignment) override;
|
Statement operator()(Assignment const& _assignment) override;
|
||||||
Statement operator()(VariableDeclaration const& _varDecl) override;
|
Statement operator()(VariableDeclaration const& _varDecl) override;
|
||||||
Statement operator()(If const& _if) override;
|
Statement operator()(If const& _if) override;
|
||||||
|
@ -48,7 +48,6 @@ public:
|
|||||||
virtual void operator()(FunctionalInstruction const& _instr);
|
virtual void operator()(FunctionalInstruction const& _instr);
|
||||||
virtual void operator()(FunctionCall const& _funCall);
|
virtual void operator()(FunctionCall const& _funCall);
|
||||||
virtual void operator()(ExpressionStatement const& _statement);
|
virtual void operator()(ExpressionStatement const& _statement);
|
||||||
virtual void operator()(Label const&) { assertThrow(false, OptimizerException, ""); }
|
|
||||||
virtual void operator()(Assignment const& _assignment);
|
virtual void operator()(Assignment const& _assignment);
|
||||||
virtual void operator()(VariableDeclaration const& _varDecl);
|
virtual void operator()(VariableDeclaration const& _varDecl);
|
||||||
virtual void operator()(If const& _if);
|
virtual void operator()(If const& _if);
|
||||||
@ -84,7 +83,6 @@ public:
|
|||||||
virtual void operator()(FunctionalInstruction& _instr);
|
virtual void operator()(FunctionalInstruction& _instr);
|
||||||
virtual void operator()(FunctionCall& _funCall);
|
virtual void operator()(FunctionCall& _funCall);
|
||||||
virtual void operator()(ExpressionStatement& _statement);
|
virtual void operator()(ExpressionStatement& _statement);
|
||||||
virtual void operator()(Label&) { assertThrow(false, OptimizerException, ""); }
|
|
||||||
virtual void operator()(Assignment& _assignment);
|
virtual void operator()(Assignment& _assignment);
|
||||||
virtual void operator()(VariableDeclaration& _varDecl);
|
virtual void operator()(VariableDeclaration& _varDecl);
|
||||||
virtual void operator()(If& _if);
|
virtual void operator()(If& _if);
|
||||||
|
@ -164,11 +164,6 @@ bool SyntacticallyEqual::statementEqual(Instruction const&, Instruction const&)
|
|||||||
assertThrow(false, OptimizerException, "");
|
assertThrow(false, OptimizerException, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntacticallyEqual::statementEqual(Label const&, Label 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,7 +60,6 @@ public:
|
|||||||
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 statementEqual(Instruction const& _lhs, Instruction const& _rhs);
|
||||||
bool statementEqual(Label const& _lhs, Label const& _rhs);
|
|
||||||
|
|
||||||
bool visitDeclaration(TypedName const& _lhs, TypedName const& _rhs);
|
bool visitDeclaration(TypedName const& _lhs, TypedName const& _rhs);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user