mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Split inline assembly into loose and strict flavours.
This commit is contained in:
committed by
Alex Beregszaszi
parent
2548228b36
commit
124190336b
@@ -103,14 +103,14 @@ assembly::Statement Parser::parseStatement()
|
||||
return parseForLoop();
|
||||
case Token::Assign:
|
||||
{
|
||||
if (m_julia)
|
||||
if (m_flavour != AsmFlavour::Loose)
|
||||
break;
|
||||
assembly::StackAssignment assignment = createWithLocation<assembly::StackAssignment>();
|
||||
advance();
|
||||
expectToken(Token::Colon);
|
||||
assignment.variableName.location = location();
|
||||
assignment.variableName.name = currentLiteral();
|
||||
if (!m_julia && instructions().count(assignment.variableName.name))
|
||||
if (instructions().count(assignment.variableName.name))
|
||||
fatalParserError("Identifier expected, got instruction name.");
|
||||
assignment.location.end = endPosition();
|
||||
expectToken(Token::Identifier);
|
||||
@@ -170,7 +170,7 @@ assembly::Statement Parser::parseStatement()
|
||||
if (currentToken() == Token::Assign && peekNextToken() != Token::Colon)
|
||||
{
|
||||
assembly::Assignment assignment = createWithLocation<assembly::Assignment>(identifier.location);
|
||||
if (!m_julia && instructions().count(identifier.name))
|
||||
if (m_flavour != AsmFlavour::IULIA && instructions().count(identifier.name))
|
||||
fatalParserError("Cannot use instruction names for identifier names.");
|
||||
advance();
|
||||
assignment.variableNames.emplace_back(identifier);
|
||||
@@ -181,7 +181,7 @@ assembly::Statement Parser::parseStatement()
|
||||
else
|
||||
{
|
||||
// label
|
||||
if (m_julia)
|
||||
if (m_flavour != AsmFlavour::Loose)
|
||||
fatalParserError("Labels are not supported.");
|
||||
Label label = createWithLocation<Label>(identifier.location);
|
||||
label.name = identifier.name;
|
||||
@@ -189,7 +189,7 @@ assembly::Statement Parser::parseStatement()
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (m_julia)
|
||||
if (m_flavour != AsmFlavour::Loose)
|
||||
fatalParserError("Call or assignment expected.");
|
||||
break;
|
||||
}
|
||||
@@ -247,13 +247,17 @@ assembly::ForLoop Parser::parseForLoop()
|
||||
assembly::Expression Parser::parseExpression()
|
||||
{
|
||||
RecursionGuard recursionGuard(*this);
|
||||
// In strict mode, this might parse a plain Instruction, but
|
||||
// it will be converted to a FunctionalInstruction inside
|
||||
// parseCall below.
|
||||
ElementaryOperation operation = parseElementaryOperation();
|
||||
if (operation.type() == typeid(Instruction))
|
||||
{
|
||||
Instruction const& instr = boost::get<Instruction>(operation);
|
||||
// Enforce functional notation for instructions requiring multiple arguments.
|
||||
int args = instructionInfo(instr.instruction).args;
|
||||
if (args > 0 && currentToken() != Token::LParen)
|
||||
bool requireFunctionalNotation = (args > 0 || m_flavour != AsmFlavour::Loose);
|
||||
if (requireFunctionalNotation && currentToken() != Token::LParen)
|
||||
fatalParserError(string(
|
||||
"Expected token \"(\" (\"" +
|
||||
instructionNames().at(instr.instruction) +
|
||||
@@ -278,6 +282,7 @@ assembly::Expression Parser::parseExpression()
|
||||
else if (operation.type() == typeid(Instruction))
|
||||
{
|
||||
// Instructions not taking arguments are allowed as expressions.
|
||||
solAssert(m_flavour == AsmFlavour::Loose, "");
|
||||
Instruction& instr = boost::get<Instruction>(operation);
|
||||
return FunctionalInstruction{std::move(instr.location), instr.instruction, {}};
|
||||
}
|
||||
@@ -351,7 +356,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
|
||||
else
|
||||
literal = currentLiteral();
|
||||
// first search the set of instructions.
|
||||
if (!m_julia && instructions().count(literal))
|
||||
if (m_flavour != AsmFlavour::IULIA && instructions().count(literal))
|
||||
{
|
||||
dev::solidity::Instruction const& instr = instructions().at(literal);
|
||||
ret = Instruction{location(), instr};
|
||||
@@ -392,7 +397,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
|
||||
""
|
||||
};
|
||||
advance();
|
||||
if (m_julia)
|
||||
if (m_flavour == AsmFlavour::IULIA)
|
||||
{
|
||||
expectToken(Token::Colon);
|
||||
literal.location.end = endPosition();
|
||||
@@ -405,7 +410,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
|
||||
}
|
||||
default:
|
||||
fatalParserError(
|
||||
m_julia ?
|
||||
m_flavour == AsmFlavour::IULIA ?
|
||||
"Literal or identifier expected." :
|
||||
"Literal, identifier or instruction expected."
|
||||
);
|
||||
@@ -475,7 +480,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
|
||||
RecursionGuard recursionGuard(*this);
|
||||
if (_initialOp.type() == typeid(Instruction))
|
||||
{
|
||||
solAssert(!m_julia, "Instructions are invalid in JULIA");
|
||||
solAssert(m_flavour != AsmFlavour::IULIA, "Instructions are invalid in JULIA");
|
||||
Instruction& instruction = boost::get<Instruction>(_initialOp);
|
||||
FunctionalInstruction ret;
|
||||
ret.instruction = instruction.instruction;
|
||||
@@ -546,7 +551,7 @@ assembly::Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
|
||||
}
|
||||
else
|
||||
fatalParserError(
|
||||
m_julia ?
|
||||
m_flavour == AsmFlavour::IULIA ?
|
||||
"Function name expected." :
|
||||
"Assembly instruction or function name required in front of \"(\")"
|
||||
);
|
||||
@@ -559,7 +564,7 @@ TypedName Parser::parseTypedName()
|
||||
RecursionGuard recursionGuard(*this);
|
||||
TypedName typedName = createWithLocation<TypedName>();
|
||||
typedName.name = expectAsmIdentifier();
|
||||
if (m_julia)
|
||||
if (m_flavour == AsmFlavour::IULIA)
|
||||
{
|
||||
expectToken(Token::Colon);
|
||||
typedName.location.end = endPosition();
|
||||
@@ -571,7 +576,7 @@ TypedName Parser::parseTypedName()
|
||||
string Parser::expectAsmIdentifier()
|
||||
{
|
||||
string name = currentLiteral();
|
||||
if (m_julia)
|
||||
if (m_flavour == AsmFlavour::IULIA)
|
||||
{
|
||||
switch (currentToken())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user