solidity/libsolidity/inlineasm/AsmData.h

80 lines
2.9 KiB
C
Raw Normal View History

2016-02-22 01:13:41 +00:00
/*
This file is part of solidity.
2016-02-22 01:13:41 +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.
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
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
#include <boost/variant.hpp>
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
namespace dev
{
namespace solidity
{
namespace assembly
2016-02-22 01:13:41 +00:00
{
/// What follows are the AST nodes for assembly.
2016-02-22 01:13:41 +00:00
/// Direct EVM instruction (except PUSHi and JUMPDEST)
2016-04-18 11:47:40 +00:00
struct Instruction { SourceLocation location; solidity::Instruction instruction; };
/// Literal number or string (up to 32 bytes)
2016-04-18 11:47:40 +00:00
struct Literal { SourceLocation location; bool isNumber; std::string value; };
/// External / internal identifier or label reference
2016-04-18 11:47:40 +00:00
struct Identifier { SourceLocation location; std::string name; };
struct FunctionalInstruction;
/// Jump label ("name:")
2016-04-18 11:47:40 +00:00
struct Label { SourceLocation location; std::string name; };
/// Assignemnt (":= x", moves stack top into x, potentially multiple slots)
2016-04-18 11:47:40 +00:00
struct Assignment { SourceLocation location; Identifier variableName; };
struct FunctionalAssignment;
struct VariableDeclaration;
struct Block;
using Statement = boost::variant<Instruction, Literal, Label, Assignment, Identifier, FunctionalAssignment, FunctionalInstruction, VariableDeclaration, Block>;
/// Functional assignment ("x := mload(20)", expects push-1-expression on the right hand
/// side and requires x to occupy exactly one stack slot.
2016-04-18 11:47:40 +00:00
struct FunctionalAssignment { SourceLocation location; Identifier variableName; std::shared_ptr<Statement> value; };
/// Functional instruction, e.g. "mul(mload(20), add(2, x))"
2016-04-18 11:47:40 +00:00
struct FunctionalInstruction { SourceLocation location; Instruction instruction; std::vector<Statement> arguments; };
/// Block-scope variable declaration ("let x := mload(20)"), non-hoisted
2016-04-18 11:47:40 +00:00
struct VariableDeclaration { SourceLocation location; std::string name; std::shared_ptr<Statement> value; };
/// 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; };
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
}
}
}