2016-02-22 01:13:41 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2016-02-22 01:13:41 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2016-02-22 01:13:41 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2016-02-22 01:13:41 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-22 01:13:41 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2016
|
|
|
|
* Parsed inline assembly to be used by the AST
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-06-01 13:41:51 +00:00
|
|
|
#include <libsolidity/inlineasm/AsmDataForward.h>
|
|
|
|
|
2016-04-01 20:11:01 +00:00
|
|
|
#include <libevmasm/Instruction.h>
|
2016-04-18 11:47:40 +00:00
|
|
|
#include <libevmasm/SourceLocation.h>
|
2016-02-22 01:13:41 +00:00
|
|
|
|
2017-06-01 13:41:51 +00:00
|
|
|
#include <boost/variant.hpp>
|
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
2016-03-01 21:56:39 +00:00
|
|
|
namespace assembly
|
2016-02-22 01:13:41 +00:00
|
|
|
{
|
|
|
|
|
2017-04-26 22:58:34 +00:00
|
|
|
using Type = std::string;
|
|
|
|
|
|
|
|
struct TypedName { SourceLocation location; std::string name; Type type; };
|
|
|
|
using TypedNameList = std::vector<TypedName>;
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
/// Direct EVM instruction (except PUSHi and JUMPDEST)
|
2016-04-18 11:47:40 +00:00
|
|
|
struct Instruction { SourceLocation location; solidity::Instruction instruction; };
|
2016-03-01 21:56:39 +00:00
|
|
|
/// Literal number or string (up to 32 bytes)
|
2017-05-02 17:26:33 +00:00
|
|
|
enum class LiteralKind { Number, Boolean, String };
|
|
|
|
struct Literal { SourceLocation location; LiteralKind kind; std::string value; Type type; };
|
2016-03-01 21:56:39 +00:00
|
|
|
/// External / internal identifier or label reference
|
2016-04-18 11:47:40 +00:00
|
|
|
struct Identifier { SourceLocation location; std::string name; };
|
2016-03-01 21:56:39 +00:00
|
|
|
/// Jump label ("name:")
|
2016-04-18 11:47:40 +00:00
|
|
|
struct Label { SourceLocation location; std::string name; };
|
2017-05-24 00:02:11 +00:00
|
|
|
/// Assignment from stack (":= x", moves stack top into x, potentially multiple slots)
|
|
|
|
struct StackAssignment { SourceLocation location; Identifier variableName; };
|
2017-05-24 00:07:00 +00:00
|
|
|
/// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand
|
2016-03-01 21:56:39 +00:00
|
|
|
/// side and requires x to occupy exactly one stack slot.
|
2017-05-19 16:06:26 +00:00
|
|
|
///
|
|
|
|
/// Multiple assignment ("x, y := f()"), where the left hand side variables each occupy
|
|
|
|
/// a single stack slot and expects a single expression on the right hand returning
|
|
|
|
/// the same amount of items as the number of variables.
|
|
|
|
struct Assignment { SourceLocation location; std::vector<Identifier> variableNames; std::shared_ptr<Statement> value; };
|
2017-04-26 22:58:34 +00:00
|
|
|
/// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))"
|
2017-12-05 13:44:20 +00:00
|
|
|
struct FunctionalInstruction { SourceLocation location; solidity::Instruction instruction; std::vector<Statement> arguments; };
|
2017-02-01 20:20:21 +00:00
|
|
|
struct FunctionCall { SourceLocation location; Identifier functionName; std::vector<Statement> arguments; };
|
2017-04-26 22:58:34 +00:00
|
|
|
/// Block-scope variable declaration ("let x:u256 := mload(20:u256)"), non-hoisted
|
2017-05-05 17:56:29 +00:00
|
|
|
struct VariableDeclaration { SourceLocation location; TypedNameList variables; std::shared_ptr<Statement> value; };
|
2016-03-01 21:56:39 +00:00
|
|
|
/// Block that creates a scope (frees declared stack variables)
|
2016-04-18 11:47:40 +00:00
|
|
|
struct Block { SourceLocation location; std::vector<Statement> statements; };
|
2017-01-31 22:59:41 +00:00
|
|
|
/// Function definition ("function f(a, b) -> (d, e) { ... }")
|
2017-12-01 13:10:49 +00:00
|
|
|
struct FunctionDefinition { SourceLocation location; std::string name; TypedNameList parameters; TypedNameList returnVariables; Block body; };
|
2017-11-21 12:36:41 +00:00
|
|
|
/// Conditional execution without "else" part.
|
|
|
|
struct If { SourceLocation location; std::shared_ptr<Statement> condition; Block body; };
|
2017-04-28 13:27:56 +00:00
|
|
|
/// Switch case or default case
|
2017-05-17 10:21:37 +00:00
|
|
|
struct Case { SourceLocation location; std::shared_ptr<Literal> value; Block body; };
|
2017-04-28 13:27:56 +00:00
|
|
|
/// Switch statement
|
|
|
|
struct Switch { SourceLocation location; std::shared_ptr<Statement> expression; std::vector<Case> cases; };
|
2017-04-28 13:33:52 +00:00
|
|
|
struct ForLoop { SourceLocation location; Block pre; std::shared_ptr<Statement> condition; Block post; Block body; };
|
2016-04-18 11:47:40 +00:00
|
|
|
|
|
|
|
struct LocationExtractor: boost::static_visitor<SourceLocation>
|
|
|
|
{
|
|
|
|
template <class T> SourceLocation operator()(T const& _node) const
|
|
|
|
{
|
|
|
|
return _node.location;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Extracts the source location from an inline assembly node.
|
|
|
|
template <class T> inline SourceLocation locationOf(T const& _node)
|
|
|
|
{
|
|
|
|
return boost::apply_visitor(LocationExtractor(), _node);
|
|
|
|
}
|
2016-02-22 01:13:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 21:56:39 +00:00
|
|
|
}
|