mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8181 from ethereum/variablePartRefactor
[YulIR] Change expression parts to use strings instead of numbers.
This commit is contained in:
commit
1bdb409b3a
@ -108,12 +108,11 @@ string IRGenerationContext::variable(Expression const& _expression)
|
|||||||
return suffixedVariableNameList(move(var) + "_", 1, 1 + size);
|
return suffixedVariableNameList(move(var) + "_", 1, 1 + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerationContext::variablePart(Expression const& _expression, size_t _part)
|
string IRGenerationContext::variablePart(Expression const& _expression, string const& _part)
|
||||||
{
|
{
|
||||||
size_t numVars = _expression.annotation().type->sizeOnStack();
|
size_t numVars = _expression.annotation().type->sizeOnStack();
|
||||||
solAssert(numVars > 1, "");
|
solAssert(numVars > 1, "");
|
||||||
solAssert(1 <= _part && _part <= numVars, "");
|
return "expr_" + to_string(_expression.id()) + "_" + _part;
|
||||||
return "expr_" + to_string(_expression.id()) + "_" + to_string(_part);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
|
string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
|
||||||
|
@ -82,9 +82,8 @@ public:
|
|||||||
/// @returns the variable (or comma-separated list of variables) that contain
|
/// @returns the variable (or comma-separated list of variables) that contain
|
||||||
/// the value of the given expression.
|
/// the value of the given expression.
|
||||||
std::string variable(Expression const& _expression);
|
std::string variable(Expression const& _expression);
|
||||||
/// @returns the variable of a multi-variable expression. Variables are numbered
|
/// @returns the sub-variable of a multi-variable expression.
|
||||||
/// starting from 1.
|
std::string variablePart(Expression const& _expression, std::string const& _part);
|
||||||
std::string variablePart(Expression const& _expression, size_t _part);
|
|
||||||
|
|
||||||
std::string internalDispatch(size_t _in, size_t _out);
|
std::string internalDispatch(size_t _in, size_t _out);
|
||||||
|
|
||||||
|
@ -717,11 +717,11 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
|||||||
else
|
else
|
||||||
solAssert(false, "Contract member is neither variable nor function.");
|
solAssert(false, "Contract member is neither variable nor function.");
|
||||||
|
|
||||||
defineExpressionPart(_memberAccess, 1) << expressionAsType(
|
defineExpressionPart(_memberAccess, "address") << expressionAsType(
|
||||||
_memberAccess.expression(),
|
_memberAccess.expression(),
|
||||||
type.isPayable() ? *TypeProvider::payableAddress() : *TypeProvider::address()
|
type.isPayable() ? *TypeProvider::payableAddress() : *TypeProvider::address()
|
||||||
) << "\n";
|
) << "\n";
|
||||||
defineExpressionPart(_memberAccess, 2) << formatNumber(identifier) << "\n";
|
defineExpressionPart(_memberAccess, "functionIdentifier") << formatNumber(identifier) << "\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
solAssert(false, "Invalid member access in contract");
|
solAssert(false, "Invalid member access in contract");
|
||||||
@ -1177,7 +1177,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
|||||||
templ("result", m_context.newYulVariable());
|
templ("result", m_context.newYulVariable());
|
||||||
templ("freeMem", fetchFreeMem());
|
templ("freeMem", fetchFreeMem());
|
||||||
templ("shl28", m_utils.shiftLeftFunction(8 * (32 - 4)));
|
templ("shl28", m_utils.shiftLeftFunction(8 * (32 - 4)));
|
||||||
templ("funId", m_context.variablePart(_functionCall.expression(), 2));
|
templ("funId", m_context.variablePart(_functionCall.expression(), "functionIdentifier"));
|
||||||
|
|
||||||
// If the function takes arbitrary parameters or is a bare call, copy dynamic length data in place.
|
// If the function takes arbitrary parameters or is a bare call, copy dynamic length data in place.
|
||||||
// Move arguments to memory, will not update the free memory pointer (but will update the memory
|
// Move arguments to memory, will not update the free memory pointer (but will update the memory
|
||||||
@ -1203,7 +1203,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
|||||||
else if (useStaticCall)
|
else if (useStaticCall)
|
||||||
solAssert(!funType.valueSet(), "Value set for staticcall");
|
solAssert(!funType.valueSet(), "Value set for staticcall");
|
||||||
else if (funType.valueSet())
|
else if (funType.valueSet())
|
||||||
templ("value", m_context.variablePart(_functionCall.expression(), 4));
|
templ("value", m_context.variablePart(_functionCall.expression(), "value"));
|
||||||
else
|
else
|
||||||
templ("value", "0");
|
templ("value", "0");
|
||||||
|
|
||||||
@ -1212,7 +1212,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
|||||||
templ("checkExistence", checkExistence);
|
templ("checkExistence", checkExistence);
|
||||||
|
|
||||||
if (funType.gasSet())
|
if (funType.gasSet())
|
||||||
templ("gas", m_context.variablePart(_functionCall.expression(), 3));
|
templ("gas", m_context.variablePart(_functionCall.expression(), "gas"));
|
||||||
else if (m_context.evmVersion().canOverchargeGasForCall())
|
else if (m_context.evmVersion().canOverchargeGasForCall())
|
||||||
// Send all gas (requires tangerine whistle EVM)
|
// Send all gas (requires tangerine whistle EVM)
|
||||||
templ("gas", "gas()");
|
templ("gas", "gas()");
|
||||||
@ -1285,7 +1285,7 @@ ostream& IRGeneratorForStatements::defineExpression(Expression const& _expressio
|
|||||||
return m_code;
|
return m_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream& IRGeneratorForStatements::defineExpressionPart(Expression const& _expression, size_t _part)
|
ostream& IRGeneratorForStatements::defineExpressionPart(Expression const& _expression, string const& _part)
|
||||||
{
|
{
|
||||||
return m_code << "let " << m_context.variablePart(_expression, _part) << " := ";
|
return m_code << "let " << m_context.variablePart(_expression, _part) << " := ";
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,7 @@ private:
|
|||||||
std::string expressionAsType(Expression const& _expression, Type const& _to);
|
std::string expressionAsType(Expression const& _expression, Type const& _to);
|
||||||
std::ostream& defineExpression(Expression const& _expression);
|
std::ostream& defineExpression(Expression const& _expression);
|
||||||
/// Defines only one of many variables corresponding to an expression.
|
/// Defines only one of many variables corresponding to an expression.
|
||||||
/// We start counting at 1 instead of 0.
|
std::ostream& defineExpressionPart(Expression const& _expression, std::string const& _part);
|
||||||
std::ostream& defineExpressionPart(Expression const& _expression, size_t _part);
|
|
||||||
|
|
||||||
void appendAndOrOperatorCode(BinaryOperation const& _binOp);
|
void appendAndOrOperatorCode(BinaryOperation const& _binOp);
|
||||||
void appendSimpleUnaryOperation(UnaryOperation const& _operation, Expression const& _expr);
|
void appendSimpleUnaryOperation(UnaryOperation const& _operation, Expression const& _expr);
|
||||||
|
Loading…
Reference in New Issue
Block a user