2019-04-18 12:39:48 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
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,
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Simplified in-memory representation of a Wasm AST.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <boost/variant.hpp>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace yul
|
|
|
|
{
|
|
|
|
namespace wasm
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Literal;
|
2019-04-23 08:45:16 +00:00
|
|
|
struct LocalVariable;
|
|
|
|
struct GlobalVariable;
|
2019-04-18 12:39:48 +00:00
|
|
|
struct Label;
|
|
|
|
struct FunctionCall;
|
|
|
|
struct BuiltinCall;
|
|
|
|
struct LocalAssignment;
|
2019-04-23 08:45:16 +00:00
|
|
|
struct GlobalAssignment;
|
2019-04-18 12:39:48 +00:00
|
|
|
struct Block;
|
|
|
|
struct If;
|
|
|
|
struct Loop;
|
|
|
|
struct Break;
|
|
|
|
struct Continue;
|
2019-04-23 08:45:16 +00:00
|
|
|
using Expression = boost::variant<
|
|
|
|
Literal, LocalVariable, GlobalVariable, Label,
|
|
|
|
FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment,
|
|
|
|
Block, If, Loop, Break, Continue
|
|
|
|
>;
|
2019-04-18 12:39:48 +00:00
|
|
|
|
|
|
|
struct Literal { uint64_t value; };
|
2019-04-23 08:45:16 +00:00
|
|
|
struct LocalVariable { std::string name; };
|
|
|
|
struct GlobalVariable { std::string name; };
|
2019-04-18 12:39:48 +00:00
|
|
|
struct Label { std::string name; };
|
|
|
|
struct FunctionCall { std::string functionName; std::vector<Expression> arguments; };
|
|
|
|
struct BuiltinCall { std::string functionName; std::vector<Expression> arguments; };
|
|
|
|
struct LocalAssignment { std::string variableName; std::unique_ptr<Expression> value; };
|
2019-04-23 08:45:16 +00:00
|
|
|
struct GlobalAssignment { std::string variableName; std::unique_ptr<Expression> value; };
|
2019-04-18 12:39:48 +00:00
|
|
|
struct Block { std::string labelName; std::vector<Expression> statements; };
|
2019-04-23 19:32:58 +00:00
|
|
|
struct If {
|
|
|
|
std::unique_ptr<Expression> condition;
|
|
|
|
std::vector<Expression> statements;
|
|
|
|
std::unique_ptr<std::vector<Expression>> elseStatements;
|
|
|
|
};
|
2019-04-18 12:39:48 +00:00
|
|
|
struct Loop { std::string labelName; std::vector<Expression> statements; };
|
|
|
|
struct Break { Label label; };
|
|
|
|
struct Continue { Label label; };
|
|
|
|
|
|
|
|
struct VariableDeclaration { std::string variableName; };
|
2019-04-23 08:45:16 +00:00
|
|
|
struct GlobalVariableDeclaration { std::string variableName; };
|
|
|
|
|
2019-04-18 12:39:48 +00:00
|
|
|
struct FunctionDefinition
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::string> parameterNames;
|
|
|
|
bool returns;
|
|
|
|
std::vector<VariableDeclaration> locals;
|
|
|
|
std::vector<Expression> body;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|