mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
tmp
This commit is contained in:
parent
597426bd1c
commit
731a61b9fc
@ -71,6 +71,8 @@ add_library(yul
|
|||||||
backends/evm/EVMObjectCompiler.h
|
backends/evm/EVMObjectCompiler.h
|
||||||
backends/evm/EVMMetrics.cpp
|
backends/evm/EVMMetrics.cpp
|
||||||
backends/evm/EVMMetrics.h
|
backends/evm/EVMMetrics.h
|
||||||
|
backends/evm/DirectStackLayoutGenerator.cpp
|
||||||
|
backends/evm/DirectStackLayoutGenerator.h
|
||||||
backends/evm/NoOutputAssembly.h
|
backends/evm/NoOutputAssembly.h
|
||||||
backends/evm/NoOutputAssembly.cpp
|
backends/evm/NoOutputAssembly.cpp
|
||||||
backends/evm/OptimizedEVMCodeTransform.cpp
|
backends/evm/OptimizedEVMCodeTransform.cpp
|
||||||
|
84
libyul/backends/evm/DirectStackLayoutGenerator.cpp
Normal file
84
libyul/backends/evm/DirectStackLayoutGenerator.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
/**
|
||||||
|
* Stack layout generator for Yul to EVM code generation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libyul/backends/evm/DirectStackLayoutGenerator.h>
|
||||||
|
|
||||||
|
#include <libyul/AST.h>
|
||||||
|
|
||||||
|
#include <range/v3/view/drop_exactly.hpp>
|
||||||
|
#include <range/v3/view/reverse.hpp>
|
||||||
|
|
||||||
|
using namespace solidity;
|
||||||
|
using namespace solidity::yul;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::run(Block const& _block)
|
||||||
|
{
|
||||||
|
yulAssert(_block.statements.size() > 0, "");
|
||||||
|
yulAssert(holds_alternative<Block>(_block.statements.front()), "");
|
||||||
|
|
||||||
|
{
|
||||||
|
DirectStackLayoutGenerator generator;
|
||||||
|
generator(get<Block>(_block.statements.front()));
|
||||||
|
}
|
||||||
|
for (Statement const& statement: _block.statements | ranges::views::drop_exactly(1))
|
||||||
|
{
|
||||||
|
FunctionDefinition const* functionDefinition = get_if<FunctionDefinition>(&statement);
|
||||||
|
yulAssert(functionDefinition, "");
|
||||||
|
DirectStackLayoutGenerator generator;
|
||||||
|
generator(*functionDefinition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::operator()(Block const& _block)
|
||||||
|
{
|
||||||
|
for (Statement const& statement: _block.statements | ranges::views::reverse)
|
||||||
|
visit(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::operator()(VariableDeclaration const& _variableDeclaration)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::operator()(Assignment const& _assignment)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::operator()(ExpressionStatement const& _expressionStatement)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::operator()(If const& _if)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void DirectStackLayoutGenerator::operator()(Switch const& _switch)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void DirectStackLayoutGenerator::operator()(ForLoop const& _forLoop)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectStackLayoutGenerator::operator()(FunctionDefinition const& _functionDefinition)
|
||||||
|
{
|
||||||
|
}
|
67
libyul/backends/evm/DirectStackLayoutGenerator.h
Normal file
67
libyul/backends/evm/DirectStackLayoutGenerator.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
/**
|
||||||
|
* Stack layout generator for Yul to EVM code generation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <libyul/backends/evm/ControlFlowGraph.h>
|
||||||
|
|
||||||
|
#include <libyul/optimiser/ASTWalker.h>
|
||||||
|
|
||||||
|
namespace solidity::yul
|
||||||
|
{
|
||||||
|
|
||||||
|
struct StackLayout
|
||||||
|
{
|
||||||
|
struct StackInfo
|
||||||
|
{
|
||||||
|
Stack entry;
|
||||||
|
Stack exit;
|
||||||
|
};
|
||||||
|
std::map<Block const*, StackInfo> blockInfos;
|
||||||
|
std::map<Statement const*, StackInfo> statementInfos;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DirectStackLayoutGenerator: public ASTWalker
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void run(Block const& _ast);
|
||||||
|
|
||||||
|
virtual void operator()(Literal const&) {}
|
||||||
|
virtual void operator()(Identifier const&) {}
|
||||||
|
virtual void operator()(FunctionCall const& _funCall);
|
||||||
|
virtual void operator()(ExpressionStatement const& _statement);
|
||||||
|
virtual void operator()(Assignment const& _assignment);
|
||||||
|
virtual void operator()(VariableDeclaration const& _varDecl);
|
||||||
|
virtual void operator()(If const& _if);
|
||||||
|
virtual void operator()(Switch const& _switch);
|
||||||
|
virtual void operator()(ForLoop const&);
|
||||||
|
virtual void operator()(FunctionDefinition const&);
|
||||||
|
virtual void operator()(Break const&);
|
||||||
|
virtual void operator()(Continue const&);
|
||||||
|
virtual void operator()(Leave const&);
|
||||||
|
virtual void operator()(Block const& _block);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DirectStackLayoutGenerator() {}
|
||||||
|
Stack m_stack;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
2361
test/libyul/evmCodeTransform/test.yul
Normal file
2361
test/libyul/evmCodeTransform/test.yul
Normal file
File diff suppressed because it is too large
Load Diff
2359
test/libyul/yulStackLayout/test.yul
Normal file
2359
test/libyul/yulStackLayout/test.yul
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user