aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-05-24 18:55:43 +0800
committerGitHub <noreply@github.com>2017-05-24 18:55:43 +0800
commitcf639f48f2e7be43ac47fda6d7dec765ed0893e4 (patch)
tree47fdccd7ebbc822b43dd99f0cf0a621f228de4e1
parente9b106cd0e9a3ca792d8335b5c2f0fa03cf4eebc (diff)
parentb77b11781d174712bd141d0fd82e823cd2727aec (diff)
downloaddexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.tar
dexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.tar.gz
dexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.tar.bz2
dexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.tar.lz
dexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.tar.xz
dexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.tar.zst
dexon-solidity-cf639f48f2e7be43ac47fda6d7dec765ed0893e4.zip
Merge pull request #2295 from ethereum/asm-cleanup
Cleanup the assembly AST
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.cpp4
-rw-r--r--libsolidity/inlineasm/AsmAnalysis.h8
-rw-r--r--libsolidity/inlineasm/AsmAnalysisInfo.h6
-rw-r--r--libsolidity/inlineasm/AsmCodeGen.cpp4
-rw-r--r--libsolidity/inlineasm/AsmData.h29
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp19
-rw-r--r--libsolidity/inlineasm/AsmParser.h2
-rw-r--r--libsolidity/inlineasm/AsmPrinter.cpp6
-rw-r--r--libsolidity/inlineasm/AsmPrinter.h4
-rw-r--r--libsolidity/inlineasm/AsmScopeFiller.h6
10 files changed, 47 insertions, 41 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp
index 9e0ade2a..babb93b4 100644
--- a/libsolidity/inlineasm/AsmAnalysis.cpp
+++ b/libsolidity/inlineasm/AsmAnalysis.cpp
@@ -160,7 +160,7 @@ bool AsmAnalyzer::operator()(FunctionalInstruction const& _instr)
return success;
}
-bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
+bool AsmAnalyzer::operator()(assembly::StackAssignment const& _assignment)
{
bool success = checkAssignment(_assignment.variableName, size_t(-1));
m_info.stackHeightInfo[&_assignment] = m_stackHeight;
@@ -168,7 +168,7 @@ bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
}
-bool AsmAnalyzer::operator()(FunctionalAssignment const& _assignment)
+bool AsmAnalyzer::operator()(assembly::Assignment const& _assignment)
{
int const stackHeight = m_stackHeight;
bool success = boost::apply_visitor(*this, *_assignment.value);
diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h
index 426ee0d2..f09e4b59 100644
--- a/libsolidity/inlineasm/AsmAnalysis.h
+++ b/libsolidity/inlineasm/AsmAnalysis.h
@@ -40,11 +40,11 @@ struct Literal;
struct Block;
struct Label;
struct FunctionalInstruction;
-struct FunctionalAssignment;
+struct Assignment;
struct VariableDeclaration;
struct Instruction;
struct Identifier;
-struct Assignment;
+struct StackAssignment;
struct FunctionDefinition;
struct FunctionCall;
@@ -73,8 +73,8 @@ public:
bool operator()(assembly::Identifier const&);
bool operator()(assembly::FunctionalInstruction const& _functionalInstruction);
bool operator()(assembly::Label const& _label);
- bool operator()(assembly::Assignment const&);
- bool operator()(assembly::FunctionalAssignment const& _functionalAssignment);
+ bool operator()(assembly::StackAssignment const&);
+ bool operator()(assembly::Assignment const& _assignment);
bool operator()(assembly::VariableDeclaration const& _variableDeclaration);
bool operator()(assembly::FunctionDefinition const& _functionDefinition);
bool operator()(assembly::FunctionCall const& _functionCall);
diff --git a/libsolidity/inlineasm/AsmAnalysisInfo.h b/libsolidity/inlineasm/AsmAnalysisInfo.h
index e21eb2c5..d2253c78 100644
--- a/libsolidity/inlineasm/AsmAnalysisInfo.h
+++ b/libsolidity/inlineasm/AsmAnalysisInfo.h
@@ -36,17 +36,17 @@ struct Literal;
struct Block;
struct Label;
struct FunctionalInstruction;
-struct FunctionalAssignment;
+struct Assignment;
struct VariableDeclaration;
struct Instruction;
struct Identifier;
-struct Assignment;
+struct StackAssignment;
struct FunctionDefinition;
struct FunctionCall;
struct Scope;
-using Statement = boost::variant<Instruction, Literal, Label, Assignment, Identifier, FunctionalAssignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Block>;
+using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Block>;
struct AsmAnalysisInfo
{
diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp
index 02d5ced0..53eafc96 100644
--- a/libsolidity/inlineasm/AsmCodeGen.cpp
+++ b/libsolidity/inlineasm/AsmCodeGen.cpp
@@ -233,13 +233,13 @@ public:
m_assembly.appendLabel(*label.id);
checkStackHeight(&_label);
}
- void operator()(assembly::Assignment const& _assignment)
+ void operator()(assembly::StackAssignment const& _assignment)
{
m_assembly.setSourceLocation(_assignment.location);
generateAssignment(_assignment.variableName, _assignment.location);
checkStackHeight(&_assignment);
}
- void operator()(FunctionalAssignment const& _assignment)
+ void operator()(assembly::Assignment const& _assignment)
{
int height = m_assembly.stackHeight();
boost::apply_visitor(*this, *_assignment.value);
diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h
index 65dfbadf..3b4048c3 100644
--- a/libsolidity/inlineasm/AsmData.h
+++ b/libsolidity/inlineasm/AsmData.h
@@ -40,6 +40,20 @@ using TypedNameList = std::vector<TypedName>;
/// What follows are the AST nodes for assembly.
+struct Instruction;
+struct Literal;
+struct Label;
+struct StackAssignment;
+struct Identifier;
+struct Assignment;
+struct VariableDeclaration;
+struct FunctionalInstruction;
+struct FunctionDefinition;
+struct FunctionCall;
+struct Block;
+
+using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Block>;
+
/// Direct EVM instruction (except PUSHi and JUMPDEST)
struct Instruction { SourceLocation location; solidity::Instruction instruction; };
/// Literal number or string (up to 32 bytes)
@@ -47,20 +61,13 @@ enum class LiteralKind { Number, Boolean, String };
struct Literal { SourceLocation location; LiteralKind kind; std::string value; Type type; };
/// External / internal identifier or label reference
struct Identifier { SourceLocation location; std::string name; };
-struct FunctionalInstruction;
/// Jump label ("name:")
struct Label { SourceLocation location; std::string name; };
-/// Assignemnt (":= x", moves stack top into x, potentially multiple slots)
-struct Assignment { SourceLocation location; Identifier variableName; };
-struct FunctionalAssignment;
-struct VariableDeclaration;
-struct FunctionDefinition;
-struct FunctionCall;
-struct Block;
-using Statement = boost::variant<Instruction, Literal, Label, Assignment, Identifier, FunctionalAssignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Block>;
-/// Functional assignment ("x := mload(20:u256)", expects push-1-expression on the right hand
+/// Assignment from stack (":= x", moves stack top into x, potentially multiple slots)
+struct StackAssignment { 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.
-struct FunctionalAssignment { SourceLocation location; Identifier variableName; std::shared_ptr<Statement> value; };
+struct Assignment { SourceLocation location; Identifier variableName; std::shared_ptr<Statement> value; };
/// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))"
struct FunctionalInstruction { SourceLocation location; Instruction instruction; std::vector<Statement> arguments; };
struct FunctionCall { SourceLocation location; Identifier functionName; std::vector<Statement> arguments; };
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 73f70e3f..85ae9424 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -71,7 +71,7 @@ assembly::Statement Parser::parseStatement()
{
if (m_julia)
break;
- assembly::Assignment assignment = createWithLocation<assembly::Assignment>();
+ assembly::StackAssignment assignment = createWithLocation<assembly::StackAssignment>();
m_scanner->next();
expectToken(Token::Colon);
assignment.variableName.location = location();
@@ -96,7 +96,7 @@ assembly::Statement Parser::parseStatement()
switch (m_scanner->currentToken())
{
case Token::LParen:
- return parseFunctionalInstruction(std::move(statement));
+ return parseCall(std::move(statement));
case Token::Colon:
{
if (statement.type() != typeid(assembly::Identifier))
@@ -107,15 +107,14 @@ assembly::Statement Parser::parseStatement()
// while identifier:= (being followed by a non-colon) as identifier := (assignment).
if (m_scanner->currentToken() == Token::Assign && m_scanner->peekNextToken() != Token::Colon)
{
- // functional assignment
- FunctionalAssignment funAss = createWithLocation<FunctionalAssignment>(identifier.location);
+ assembly::Assignment assignment = createWithLocation<assembly::Assignment>(identifier.location);
if (!m_julia && instructions().count(identifier.name))
fatalParserError("Cannot use instruction names for identifier names.");
m_scanner->next();
- funAss.variableName = identifier;
- funAss.value.reset(new Statement(parseExpression()));
- funAss.location.end = locationOf(*funAss.value).end;
- return funAss;
+ assignment.variableName = identifier;
+ assignment.value.reset(new Statement(parseExpression()));
+ assignment.location.end = locationOf(*assignment.value).end;
+ return assignment;
}
else
{
@@ -139,7 +138,7 @@ assembly::Statement Parser::parseExpression()
{
Statement operation = parseElementaryOperation(true);
if (m_scanner->currentToken() == Token::LParen)
- return parseFunctionalInstruction(std::move(operation));
+ return parseCall(std::move(operation));
else
return operation;
}
@@ -304,7 +303,7 @@ assembly::FunctionDefinition Parser::parseFunctionDefinition()
return funDef;
}
-assembly::Statement Parser::parseFunctionalInstruction(assembly::Statement&& _instruction)
+assembly::Statement Parser::parseCall(assembly::Statement&& _instruction)
{
if (_instruction.type() == typeid(Instruction))
{
diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h
index addc1725..812762a6 100644
--- a/libsolidity/inlineasm/AsmParser.h
+++ b/libsolidity/inlineasm/AsmParser.h
@@ -68,7 +68,7 @@ protected:
Statement parseElementaryOperation(bool _onlySinglePusher = false);
VariableDeclaration parseVariableDeclaration();
FunctionDefinition parseFunctionDefinition();
- Statement parseFunctionalInstruction(Statement&& _instruction);
+ Statement parseCall(Statement&& _instruction);
TypedName parseTypedName();
std::string expectAsmIdentifier();
diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp
index 219a57ad..92b12423 100644
--- a/libsolidity/inlineasm/AsmPrinter.cpp
+++ b/libsolidity/inlineasm/AsmPrinter.cpp
@@ -108,15 +108,15 @@ string AsmPrinter::operator()(assembly::Label const& _label)
return _label.name + ":";
}
-string AsmPrinter::operator()(assembly::Assignment const& _assignment)
+string AsmPrinter::operator()(assembly::StackAssignment const& _assignment)
{
solAssert(!m_julia, "");
return "=: " + (*this)(_assignment.variableName);
}
-string AsmPrinter::operator()(assembly::FunctionalAssignment const& _functionalAssignment)
+string AsmPrinter::operator()(assembly::Assignment const& _assignment)
{
- return (*this)(_functionalAssignment.variableName) + " := " + boost::apply_visitor(*this, *_functionalAssignment.value);
+ return (*this)(_assignment.variableName) + " := " + boost::apply_visitor(*this, *_assignment.value);
}
string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDeclaration)
diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h
index 282fd7e3..423eeefa 100644
--- a/libsolidity/inlineasm/AsmPrinter.h
+++ b/libsolidity/inlineasm/AsmPrinter.h
@@ -35,8 +35,8 @@ struct Literal;
struct Identifier;
struct FunctionalInstruction;
struct Label;
+struct StackAssignment;
struct Assignment;
-struct FunctionalAssignment;
struct VariableDeclaration;
struct FunctionDefinition;
struct FunctionCall;
@@ -52,8 +52,8 @@ public:
std::string operator()(assembly::Identifier const& _identifier);
std::string operator()(assembly::FunctionalInstruction const& _functionalInstruction);
std::string operator()(assembly::Label const& _label);
+ std::string operator()(assembly::StackAssignment const& _assignment);
std::string operator()(assembly::Assignment const& _assignment);
- std::string operator()(assembly::FunctionalAssignment const& _functionalAssignment);
std::string operator()(assembly::VariableDeclaration const& _variableDeclaration);
std::string operator()(assembly::FunctionDefinition const& _functionDefinition);
std::string operator()(assembly::FunctionCall const& _functionCall);
diff --git a/libsolidity/inlineasm/AsmScopeFiller.h b/libsolidity/inlineasm/AsmScopeFiller.h
index 61428eea..b1b0833b 100644
--- a/libsolidity/inlineasm/AsmScopeFiller.h
+++ b/libsolidity/inlineasm/AsmScopeFiller.h
@@ -39,11 +39,11 @@ struct Literal;
struct Block;
struct Label;
struct FunctionalInstruction;
-struct FunctionalAssignment;
+struct Assignment;
struct VariableDeclaration;
struct Instruction;
struct Identifier;
-struct Assignment;
+struct StackAssignment;
struct FunctionDefinition;
struct FunctionCall;
@@ -64,8 +64,8 @@ public:
bool operator()(assembly::Identifier const&) { return true; }
bool operator()(assembly::FunctionalInstruction const&) { return true; }
bool operator()(assembly::Label const& _label);
+ bool operator()(assembly::StackAssignment const&) { return true; }
bool operator()(assembly::Assignment const&) { return true; }
- bool operator()(assembly::FunctionalAssignment const&) { return true; }
bool operator()(assembly::VariableDeclaration const& _variableDeclaration);
bool operator()(assembly::FunctionDefinition const& _functionDefinition);
bool operator()(assembly::FunctionCall const&) { return true; }