mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6309 from ethereum/proto-add-str-hex-lit
yul proto: Add support for generating string and hex literals.
This commit is contained in:
commit
7d94d3af20
@ -19,10 +19,40 @@
|
|||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <boost/range/algorithm_ext/erase.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace yul::test::yul_fuzzer;
|
using namespace yul::test::yul_fuzzer;
|
||||||
|
|
||||||
|
std::string yul::test::yul_fuzzer::createHex(std::string const& _hexBytes)
|
||||||
|
{
|
||||||
|
std::string tmp{_hexBytes};
|
||||||
|
if (!tmp.empty())
|
||||||
|
{
|
||||||
|
boost::range::remove_erase_if(tmp, [=](char c) -> bool {
|
||||||
|
return !std::isxdigit(c);
|
||||||
|
});
|
||||||
|
tmp = tmp.substr(0, 64);
|
||||||
|
}
|
||||||
|
// We need this awkward if case hex literals cannot be empty.
|
||||||
|
if (tmp.empty())
|
||||||
|
tmp = "1";
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string yul::test::yul_fuzzer::createAlphaNum(std::string const& _strBytes)
|
||||||
|
{
|
||||||
|
std::string tmp{_strBytes};
|
||||||
|
if (!tmp.empty())
|
||||||
|
{
|
||||||
|
boost::range::remove_erase_if(tmp, [=](char c) -> bool {
|
||||||
|
return !(std::isalpha(c) || std::isdigit(c));
|
||||||
|
});
|
||||||
|
tmp = tmp.substr(0, 32);
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x)
|
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x)
|
||||||
{
|
{
|
||||||
switch (_x.literal_oneof_case())
|
switch (_x.literal_oneof_case())
|
||||||
@ -30,6 +60,12 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x)
|
|||||||
case Literal::kIntval:
|
case Literal::kIntval:
|
||||||
_os << _x.intval();
|
_os << _x.intval();
|
||||||
break;
|
break;
|
||||||
|
case Literal::kHexval:
|
||||||
|
_os << "0x" << createHex(_x.hexval());
|
||||||
|
break;
|
||||||
|
case Literal::kStrval:
|
||||||
|
_os << "\"" << createAlphaNum(_x.strval()) << "\"";
|
||||||
|
break;
|
||||||
case Literal::LITERAL_ONEOF_NOT_SET:
|
case Literal::LITERAL_ONEOF_NOT_SET:
|
||||||
_os << "1";
|
_os << "1";
|
||||||
break;
|
break;
|
||||||
@ -301,9 +337,7 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Block const& _x)
|
|||||||
_os << "}\n";
|
_os << "}\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_os << "{}\n";
|
_os << "{}\n";
|
||||||
}
|
|
||||||
return _os;
|
return _os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ class Function;
|
|||||||
|
|
||||||
std::string functionToString(Function const& input);
|
std::string functionToString(Function const& input);
|
||||||
std::string protoToYul(uint8_t const* data, size_t size);
|
std::string protoToYul(uint8_t const* data, size_t size);
|
||||||
|
std::string createHex(std::string const& _hexBytes);
|
||||||
|
std::string createAlphaNum(std::string const& _strBytes);
|
||||||
std::ostream& operator<<(std::ostream& _os, BinaryOp const& _x);
|
std::ostream& operator<<(std::ostream& _os, BinaryOp const& _x);
|
||||||
std::ostream& operator<<(std::ostream& _os, Block const& _x);
|
std::ostream& operator<<(std::ostream& _os, Block const& _x);
|
||||||
std::ostream& operator<<(std::ostream& _os, Literal const& _x);
|
std::ostream& operator<<(std::ostream& _os, Literal const& _x);
|
||||||
|
@ -48,6 +48,8 @@ message VarRef {
|
|||||||
message Literal {
|
message Literal {
|
||||||
oneof literal_oneof {
|
oneof literal_oneof {
|
||||||
uint64 intval = 1;
|
uint64 intval = 1;
|
||||||
|
string hexval = 2;
|
||||||
|
string strval = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user