Adding test for multi return values including bool in evmTyped dialect. Calling zeroLiteralForType from inliner

This commit is contained in:
Djordje Mijovic 2020-02-19 15:36:05 +01:00 committed by chriseth
parent bddbcbe6a4
commit 2efda4129b
3 changed files with 35 additions and 9 deletions

View File

@ -29,6 +29,7 @@
#include <libyul/optimiser/Semantics.h>
#include <libyul/Exceptions.h>
#include <libyul/AsmData.h>
#include <libyul/Dialect.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/Visitor.h>
@ -41,11 +42,11 @@ using namespace solidity::yul;
void FullInliner::run(OptimiserStepContext& _context, Block& _ast)
{
FullInliner{_ast, _context.dispenser}.run();
FullInliner{_ast, _context.dispenser, _context.dialect}.run();
}
FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser):
m_ast(_ast), m_nameDispenser(_dispenser)
FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const& _dialect):
m_ast(_ast), m_nameDispenser(_dispenser), m_dialect(_dialect)
{
// Determine constants
SSAValueTracker tracker;
@ -139,7 +140,7 @@ void FullInliner::updateCodeSize(FunctionDefinition const& _fun)
void FullInliner::handleBlock(YulString _currentFunctionName, Block& _block)
{
InlineModifier{*this, m_nameDispenser, _currentFunctionName}(_block);
InlineModifier{*this, m_nameDispenser, _currentFunctionName, m_dialect}(_block);
}
bool FullInliner::recursive(FunctionDefinition const& _fun) const
@ -198,7 +199,7 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
if (_value)
varDecl.value = make_unique<Expression>(std::move(*_value));
else
varDecl.value = make_unique<Expression>(Literal{{}, LiteralKind::Number, YulString{"0"}, {}});
varDecl.value = make_unique<Expression>(m_dialect.zeroLiteralForType(varDecl.variables.front().type));
newStatements.emplace_back(std::move(varDecl));
};

View File

@ -69,7 +69,7 @@ class FullInliner: public ASTModifier
{
public:
static constexpr char const* name{"FullInliner"};
static void run(OptimiserStepContext&, Block& _ast);
static void run(OptimiserStepContext& _context, Block& _ast);
/// Inlining heuristic.
/// @param _callSite the name of the function in which the function call is located.
@ -89,7 +89,7 @@ public:
void tentativelyUpdateCodeSize(YulString _function, YulString _callSite);
private:
FullInliner(Block& _ast, NameDispenser& _dispenser);
FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const& _dialect);
void run();
void updateCodeSize(FunctionDefinition const& _fun);
@ -108,6 +108,7 @@ private:
std::set<YulString> m_constants;
std::map<YulString, size_t> m_functionSizes;
NameDispenser& m_nameDispenser;
Dialect const& m_dialect;
};
/**
@ -117,10 +118,11 @@ private:
class InlineModifier: public ASTModifier
{
public:
InlineModifier(FullInliner& _driver, NameDispenser& _nameDispenser, YulString _functionName):
InlineModifier(FullInliner& _driver, NameDispenser& _nameDispenser, YulString _functionName, Dialect const& _dialect):
m_currentFunction(std::move(_functionName)),
m_driver(_driver),
m_nameDispenser(_nameDispenser)
m_nameDispenser(_nameDispenser),
m_dialect(_dialect)
{ }
void operator()(Block& _block) override;
@ -132,6 +134,7 @@ private:
YulString m_currentFunction;
FullInliner& m_driver;
NameDispenser& m_nameDispenser;
Dialect const& m_dialect;
};
/**

View File

@ -0,0 +1,22 @@
{
function f(a: u256) -> x: bool, y:u256 {
y := mul(a, a)
}
let r: bool, s: u256 := f(mload(3))
}
// ====
// dialect: evmTyped
// step: fullInliner
// ----
// {
// {
// let a_3 := mload(3)
// let x_4:bool := false
// let y_5 := 0
// y_5 := mul(a_3, a_3)
// let r:bool := x_4
// let s := y_5
// }
// function f(a) -> x:bool, y
// { y := mul(a, a) }
// }