mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8183 from ethereum/functionOptionsYulIR
[YulIR] Function call options for Yul IR
This commit is contained in:
commit
bdd8045db5
@ -2954,7 +2954,7 @@ vector<tuple<string, TypePointer>> FunctionType::makeStackItems() const
|
|||||||
if (m_valueSet)
|
if (m_valueSet)
|
||||||
slots.emplace_back("value", TypeProvider::uint256());
|
slots.emplace_back("value", TypeProvider::uint256());
|
||||||
if (m_saltSet)
|
if (m_saltSet)
|
||||||
slots.emplace_back("salt", TypeProvider::uint256());
|
slots.emplace_back("salt", TypeProvider::fixedBytes(32));
|
||||||
if (bound())
|
if (bound())
|
||||||
for (auto const& [boundName, boundType]: m_parameterTypes.front()->stackItems())
|
for (auto const& [boundName, boundType]: m_parameterTypes.front()->stackItems())
|
||||||
slots.emplace_back("self_" + boundName, boundType);
|
slots.emplace_back("self_" + boundName, boundType);
|
||||||
|
@ -739,6 +739,25 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRGeneratorForStatements::endVisit(FunctionCallOptions const& _options)
|
||||||
|
{
|
||||||
|
FunctionType const& previousType = dynamic_cast<FunctionType const&>(*_options.expression().annotation().type);
|
||||||
|
|
||||||
|
solUnimplementedAssert(!previousType.bound(), "");
|
||||||
|
|
||||||
|
// Copy over existing values.
|
||||||
|
for (auto const& item: previousType.stackItems())
|
||||||
|
define(IRVariable(_options).part(get<0>(item)), IRVariable(_options.expression()).part(get<0>(item)));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < _options.names().size(); ++i)
|
||||||
|
{
|
||||||
|
string const& name = *_options.names()[i];
|
||||||
|
solAssert(name == "salt" || name == "gas" || name == "value", "");
|
||||||
|
|
||||||
|
define(IRVariable(_options).part(name), *_options.options()[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
||||||
{
|
{
|
||||||
ASTString const& member = _memberAccess.memberName();
|
ASTString const& member = _memberAccess.memberName();
|
||||||
|
@ -60,6 +60,7 @@ public:
|
|||||||
void endVisit(UnaryOperation const& _unaryOperation) override;
|
void endVisit(UnaryOperation const& _unaryOperation) override;
|
||||||
bool visit(BinaryOperation const& _binOp) override;
|
bool visit(BinaryOperation const& _binOp) override;
|
||||||
void endVisit(FunctionCall const& _funCall) override;
|
void endVisit(FunctionCall const& _funCall) override;
|
||||||
|
void endVisit(FunctionCallOptions const& _funCallOptions) override;
|
||||||
void endVisit(MemberAccess const& _memberAccess) override;
|
void endVisit(MemberAccess const& _memberAccess) override;
|
||||||
bool visit(InlineAssembly const& _inlineAsm) override;
|
bool visit(InlineAssembly const& _inlineAsm) override;
|
||||||
void endVisit(IndexAccess const& _indexAccess) override;
|
void endVisit(IndexAccess const& _indexAccess) override;
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
pragma solidity >= 0.6.0;
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function g(uint n) external payable returns (uint, uint) {
|
||||||
|
return (msg.value * 1000, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
function f(uint n) public payable returns (uint, uint) {
|
||||||
|
return this.g{value: 10}(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// g(uint256), 1 ether: 4 -> 1000000000000000000000, 4
|
||||||
|
// f(uint256), 11 ether: 2 -> 10000, 2
|
Loading…
Reference in New Issue
Block a user