Merge remote-tracking branch 'origin/develop' into breaking

This commit is contained in:
chriseth
2020-11-23 19:28:08 +01:00
511 changed files with 1263 additions and 372 deletions
+3 -2
View File
@@ -345,8 +345,9 @@ bytes BinaryTransform::operator()(Literal const& _literal)
bytes BinaryTransform::operator()(StringLiteral const&)
{
// TODO is this used?
yulAssert(false, "String literals not yet implemented");
// StringLiteral is a special AST element used for certain builtins.
// It is not mapped to actual WebAssembly, and should be processed in visit(BuiltinCall).
yulAssert(false, "");
}
bytes BinaryTransform::operator()(LocalVariable const& _variable)
+2
View File
@@ -101,6 +101,8 @@ string TextTransform::operator()(wasm::Literal const& _literal)
string TextTransform::operator()(wasm::StringLiteral const& _literal)
{
// StringLiteral is a special AST element used for certain builtins.
// The output of this will not be valid WebAssembly.
string quoted = boost::replace_all_copy(_literal.value, "\\", "\\\\");
boost::replace_all(quoted, "\"", "\\\"");
return "\"" + quoted + "\"";
+1
View File
@@ -63,6 +63,7 @@ using Expression = std::variant<
>;
struct Literal { std::variant<uint32_t, uint64_t> value; };
// This is a special AST element used for certain builtins. It is not mapped to actual WebAssembly.
struct StringLiteral { std::string value; };
struct LocalVariable { std::string name; };
struct GlobalVariable { std::string name; };
+26 -6
View File
@@ -55,7 +55,7 @@ function callvalue() -> z1, z2, z3, z4 {
}
function calldataload(x1, x2, x3, x4) -> z1, z2, z3, z4 {
eth.callDataCopy(0:i32, u256_to_i32(x1, x2, x3, x4), 32:i32)
calldatacopy(0, 0, 0, 0, x1, x2, x3, x4, 0, 0, 0, 32)
z1, z2, z3, z4 := mload_internal(0:i32)
}
@@ -64,11 +64,31 @@ function calldatasize() -> z1, z2, z3, z4 {
}
function calldatacopy(x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4) {
eth.callDataCopy(
to_internal_i32ptr(x1, x2, x3, x4),
u256_to_i32(y1, y2, y3, y4),
u256_to_i32(z1, z2, z3, z4)
)
let cds:i32 := eth.getCallDataSize()
let destination:i32 := u256_to_i32(x1, x2, x3, x4)
let offset:i32 := u256_to_i32(y1, y2, y3, y4)
let requested_size:i32 := u256_to_i32(z1, z2, z3, z4)
// overflow?
if i32.gt_u(offset, i32.sub(0xffffffff:i32, requested_size)) {
eth.revert(0:i32, 0:i32)
}
let available_size:i32 := i32.sub(cds, offset)
if i32.gt_u(offset, cds) {
available_size := 0:i32
}
if i32.gt_u(available_size, 0:i32) {
eth.callDataCopy(
destination,
offset,
available_size
)
}
if i32.gt_u(requested_size, available_size) {
memset(i32.add(destination, available_size), 0:i32, i32.sub(requested_size, available_size))
}
}
// Needed?
+7
View File
@@ -60,3 +60,10 @@ function pop(x1, x2, x3, x4) {
function memoryguard(x:i64) -> y1, y2, y3, y4 {
y4 := x
}
function memset(ptr:i32, value:i32, length:i32) {
for { let i:i32 := 0:i32 } i32.lt_u(i, length) { i := i32.add(i, 1:i32) }
{
i32.store8(i32.add(ptr, i), value)
}
}