mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Support "datasize" and "dataoffset" with literals in eWasm.
This commit is contained in:
parent
edf62e4d2b
commit
8cd197e572
@ -30,6 +30,7 @@ namespace wasm
|
|||||||
{
|
{
|
||||||
|
|
||||||
struct Literal;
|
struct Literal;
|
||||||
|
struct StringLiteral;
|
||||||
struct LocalVariable;
|
struct LocalVariable;
|
||||||
struct GlobalVariable;
|
struct GlobalVariable;
|
||||||
struct Label;
|
struct Label;
|
||||||
@ -43,12 +44,13 @@ struct Loop;
|
|||||||
struct Break;
|
struct Break;
|
||||||
struct Continue;
|
struct Continue;
|
||||||
using Expression = boost::variant<
|
using Expression = boost::variant<
|
||||||
Literal, LocalVariable, GlobalVariable, Label,
|
Literal, StringLiteral, LocalVariable, GlobalVariable, Label,
|
||||||
FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment,
|
FunctionCall, BuiltinCall, LocalAssignment, GlobalAssignment,
|
||||||
Block, If, Loop, Break, Continue
|
Block, If, Loop, Break, Continue
|
||||||
>;
|
>;
|
||||||
|
|
||||||
struct Literal { uint64_t value; };
|
struct Literal { uint64_t value; };
|
||||||
|
struct StringLiteral { std::string value; };
|
||||||
struct LocalVariable { std::string name; };
|
struct LocalVariable { std::string name; };
|
||||||
struct GlobalVariable { std::string name; };
|
struct GlobalVariable { std::string name; };
|
||||||
struct Label { std::string name; };
|
struct Label { std::string name; };
|
||||||
|
@ -126,8 +126,18 @@ wasm::Expression EWasmCodeTransform::operator()(FunctionalInstruction const& _f)
|
|||||||
|
|
||||||
wasm::Expression EWasmCodeTransform::operator()(FunctionCall const& _call)
|
wasm::Expression EWasmCodeTransform::operator()(FunctionCall const& _call)
|
||||||
{
|
{
|
||||||
if (m_dialect.builtin(_call.functionName.name))
|
if (BuiltinFunction const* builtin = m_dialect.builtin(_call.functionName.name))
|
||||||
return wasm::BuiltinCall{_call.functionName.name.str(), visit(_call.arguments)};
|
{
|
||||||
|
if (builtin->literalArguments)
|
||||||
|
{
|
||||||
|
vector<wasm::Expression> literals;
|
||||||
|
for (auto const& arg: _call.arguments)
|
||||||
|
literals.emplace_back(wasm::StringLiteral{boost::get<Literal>(arg).value.str()});
|
||||||
|
return wasm::BuiltinCall{_call.functionName.name.str(), std::move(literals)};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return wasm::BuiltinCall{_call.functionName.name.str(), visit(_call.arguments)};
|
||||||
|
}
|
||||||
else
|
else
|
||||||
// If this function returns multiple values, then the first one will
|
// If this function returns multiple values, then the first one will
|
||||||
// be returned in the expression itself and the others in global variables.
|
// be returned in the expression itself and the others in global variables.
|
||||||
|
@ -56,6 +56,13 @@ string EWasmToText::operator()(wasm::Literal const& _literal)
|
|||||||
return "(i64.const " + to_string(_literal.value) + ")";
|
return "(i64.const " + to_string(_literal.value) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string EWasmToText::operator()(wasm::StringLiteral const& _literal)
|
||||||
|
{
|
||||||
|
string quoted = boost::replace_all_copy(_literal.value, "\\", "\\\\");
|
||||||
|
boost::replace_all(quoted, "\"", "\\\"");
|
||||||
|
return "\"" + quoted + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
string EWasmToText::operator()(wasm::LocalVariable const& _identifier)
|
string EWasmToText::operator()(wasm::LocalVariable const& _identifier)
|
||||||
{
|
{
|
||||||
return "(get_local $" + _identifier.name + ")";
|
return "(get_local $" + _identifier.name + ")";
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
std::string operator()(wasm::Literal const& _literal);
|
std::string operator()(wasm::Literal const& _literal);
|
||||||
|
std::string operator()(wasm::StringLiteral const& _literal);
|
||||||
std::string operator()(wasm::LocalVariable const& _identifier);
|
std::string operator()(wasm::LocalVariable const& _identifier);
|
||||||
std::string operator()(wasm::GlobalVariable const& _identifier);
|
std::string operator()(wasm::GlobalVariable const& _identifier);
|
||||||
std::string operator()(wasm::Label const& _label);
|
std::string operator()(wasm::Label const& _label);
|
||||||
|
Loading…
Reference in New Issue
Block a user