2019-01-17 10:19:54 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
2019-03-20 15:21:38 +00:00
|
|
|
#include <ostream>
|
|
|
|
#include <sstream>
|
2019-03-20 15:21:38 +00:00
|
|
|
#include <stack>
|
2019-04-17 09:41:28 +00:00
|
|
|
#include <set>
|
2019-01-17 10:19:54 +00:00
|
|
|
|
|
|
|
#include <test/tools/ossfuzz/yulProto.pb.h>
|
2019-04-17 09:41:28 +00:00
|
|
|
#include <libdevcore/Common.h>
|
|
|
|
#include <libdevcore/FixedHash.h>
|
2019-01-17 10:19:54 +00:00
|
|
|
|
|
|
|
namespace yul
|
|
|
|
{
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
namespace yul_fuzzer
|
|
|
|
{
|
2019-03-20 15:21:38 +00:00
|
|
|
class ProtoConverter
|
|
|
|
{
|
|
|
|
public:
|
2019-03-20 15:21:38 +00:00
|
|
|
ProtoConverter()
|
|
|
|
{
|
|
|
|
// The hard-coded function template foo has 10 parameters that are already "live"
|
|
|
|
m_numLiveVars = 10;
|
|
|
|
m_numVarsPerScope.push(m_numLiveVars);
|
|
|
|
m_numNestedForLoops = 0;
|
2019-03-26 09:52:30 +00:00
|
|
|
m_inForScope.push(false);
|
2019-03-20 15:21:38 +00:00
|
|
|
}
|
|
|
|
ProtoConverter(ProtoConverter const&) = delete;
|
|
|
|
ProtoConverter(ProtoConverter&&) = delete;
|
2019-03-20 15:21:38 +00:00
|
|
|
std::string functionToString(Function const& _input);
|
|
|
|
std::string protoToYul(uint8_t const* _data, size_t _size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void visit(BinaryOp const&);
|
|
|
|
void visit(Block const&);
|
|
|
|
void visit(Literal const&);
|
|
|
|
void visit(VarRef const&);
|
|
|
|
void visit(Expression const&);
|
|
|
|
void visit(VarDecl const&);
|
|
|
|
void visit(TypedVarDecl const&);
|
|
|
|
void visit(UnaryOp const&);
|
|
|
|
void visit(AssignmentStatement const&);
|
|
|
|
void visit(IfStmt const&);
|
|
|
|
void visit(StoreFunc const&);
|
|
|
|
void visit(Statement const&);
|
|
|
|
void visit(Function const&);
|
|
|
|
void visit(ForStmt const&);
|
|
|
|
void visit(CaseStmt const&);
|
|
|
|
void visit(SwitchStmt const&);
|
2019-03-26 09:52:30 +00:00
|
|
|
void visit(TernaryOp const&);
|
2019-03-26 09:52:30 +00:00
|
|
|
void visit(NullaryOp const&);
|
|
|
|
void visit(LogFunc const&);
|
2019-03-26 09:52:30 +00:00
|
|
|
void visit(CopyFunc const&);
|
|
|
|
void visit(ExtCodeCopy const&);
|
2019-03-26 09:52:30 +00:00
|
|
|
void visit(StopInvalidStmt const&);
|
|
|
|
void visit(RetRevStmt const&);
|
|
|
|
void visit(SelfDestructStmt const&);
|
|
|
|
void visit(TerminatingStmt const&);
|
2019-03-20 15:21:38 +00:00
|
|
|
template <class T>
|
|
|
|
void visit(google::protobuf::RepeatedPtrField<T> const& _repeated_field);
|
|
|
|
|
|
|
|
std::string createHex(std::string const& _hexBytes) const;
|
|
|
|
std::string createAlphaNum(std::string const& _strBytes) const;
|
2019-04-17 09:41:28 +00:00
|
|
|
bool isCaseLiteralUnique(Literal const&);
|
2019-03-20 15:21:38 +00:00
|
|
|
|
|
|
|
std::ostringstream m_output;
|
2019-03-20 15:21:38 +00:00
|
|
|
std::stack<uint8_t> m_numVarsPerScope;
|
|
|
|
int32_t m_numLiveVars;
|
|
|
|
int32_t m_numNestedForLoops;
|
2019-03-26 09:52:30 +00:00
|
|
|
std::stack<bool> m_inForScope;
|
2019-04-17 09:41:28 +00:00
|
|
|
std::stack<std::set<dev::u256>> m_switchLiteralSetPerScope;
|
2019-03-20 15:21:38 +00:00
|
|
|
};
|
2019-01-17 10:19:54 +00:00
|
|
|
}
|
2019-03-14 14:40:54 +00:00
|
|
|
}
|
2019-03-20 15:21:38 +00:00
|
|
|
}
|