mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
ir/Common: Add YulArity struct
This commit is contained in:
parent
22d5caa979
commit
16e58449ab
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libsolidity/codegen/ir/Common.h>
|
#include <libsolidity/codegen/ir/Common.h>
|
||||||
|
#include <libsolidity/ast/TypeProvider.h>
|
||||||
|
|
||||||
#include <libsolutil/CommonIO.h>
|
#include <libsolutil/CommonIO.h>
|
||||||
|
|
||||||
@ -23,6 +24,13 @@ using namespace std;
|
|||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
|
|
||||||
|
YulArity YulArity::fromType(FunctionType const& _functionType)
|
||||||
|
{
|
||||||
|
return YulArity{
|
||||||
|
TupleType(_functionType.parameterTypes()).sizeOnStack(),
|
||||||
|
TupleType(_functionType.returnParameterTypes()).sizeOnStack()
|
||||||
|
};
|
||||||
|
}
|
||||||
string IRNames::function(FunctionDefinition const& _function)
|
string IRNames::function(FunctionDefinition const& _function)
|
||||||
{
|
{
|
||||||
// @TODO previously, we had to distinguish creation context and runtime context,
|
// @TODO previously, we had to distinguish creation context and runtime context,
|
||||||
|
@ -22,11 +22,28 @@
|
|||||||
|
|
||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace solidity::frontend
|
namespace solidity::frontend
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Structure that describes arity and co-arity of a Yul function, i.e. the number of its inputs and outputs.
|
||||||
|
*/
|
||||||
|
struct YulArity
|
||||||
|
{
|
||||||
|
explicit YulArity(size_t _in, size_t _out): in(_in), out(_out) {}
|
||||||
|
|
||||||
|
static YulArity fromType(FunctionType const& _functionType);
|
||||||
|
|
||||||
|
bool operator==(YulArity const& _other) const { return in == _other.in && out == _other.out; }
|
||||||
|
bool operator!=(YulArity const& _other) const { return !(*this == _other); }
|
||||||
|
|
||||||
|
size_t in; /// Number of input parameters
|
||||||
|
size_t out; /// Number of output parameters
|
||||||
|
};
|
||||||
|
|
||||||
struct IRNames
|
struct IRNames
|
||||||
{
|
{
|
||||||
static std::string function(FunctionDefinition const& _function);
|
static std::string function(FunctionDefinition const& _function);
|
||||||
@ -45,3 +62,15 @@ struct IRNames
|
|||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Overloading std::less() makes it possible to use YulArity as a map key. We could define operator<
|
||||||
|
// instead but such an operator would be a bit ambiguous (e.g. YulArity{2, 2} would be be greater than
|
||||||
|
// YulArity{1, 10} in lexicographical order but the latter has greater total number of inputs and outputs).
|
||||||
|
template<>
|
||||||
|
struct std::less<solidity::frontend::YulArity>
|
||||||
|
{
|
||||||
|
bool operator() (solidity::frontend::YulArity const& _lhs, solidity::frontend::YulArity const& _rhs) const
|
||||||
|
{
|
||||||
|
return _lhs.in < _rhs.in || (_lhs.in == _rhs.in && _lhs.out < _rhs.out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user