Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit c5c9b2e

Browse files
committed
Clean up logic to make code more readable
1 parent 164cb91 commit c5c9b2e

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

wasm/generateInterface.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function generateManifest (interfaceManifest, opts) {
248248
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8})))
249249
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
250250
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3}))))`
251-
} else if (input === 'i64' && opcode !== 'CALL') {
251+
} else if (input === 'i64') {
252252
call += `(call $check_overflow_i64
253253
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32})))
254254
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8})))
@@ -263,11 +263,7 @@ function generateManifest (interfaceManifest, opts) {
263263
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
264264
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})))))`
265265
call += `(get_local $offset${numOfLocals})`
266-
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE')) {
267-
// CALLs in EVM have 7 arguments
268-
// but in ewasm CALLs only have 5 arguments
269-
// so delete the bottom two stack elements, after processing the 5th argument
270-
266+
} else if (input === 'length') {
271267
locals += `(local $length${numOfLocals} i32)`
272268
body += `(set_local $length${numOfLocals}
273269
(call $check_overflow
@@ -282,25 +278,13 @@ function generateManifest (interfaceManifest, opts) {
282278
call += `(get_local $length${numOfLocals})`
283279
numOfLocals++
284280

285-
// delete 6th stack element
286-
spOffset--
287-
288-
// delete 7th stack element
289-
spOffset--
290-
} else if (input === 'length' && (opcode !== 'CALL' && opcode !== 'CALLCODE')) {
291-
locals += `(local $length${numOfLocals} i32)`
292-
body += `(set_local $length${numOfLocals}
293-
(call $check_overflow
294-
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32})))
295-
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8})))
296-
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
297-
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})))))
298-
299-
(call $memusegas (get_local $offset${numOfLocals}) (get_local $length${numOfLocals}))
300-
(set_local $offset${numOfLocals} (i32.add (get_global $memstart) (get_local $offset${numOfLocals})))`
301-
302-
call += `(get_local $length${numOfLocals})`
303-
numOfLocals++
281+
// CALLs in EVM have 7 arguments
282+
// but in ewasm CALLs only have 5 arguments
283+
// so delete the bottom two stack elements, after processing the 5th argument
284+
if (opcode === 'CALL' || opcode === 'CALLCODE') {
285+
spOffset--
286+
spOffset--
287+
}
304288
}
305289
spOffset--
306290
})

0 commit comments

Comments
 (0)