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

Commit c71beff

Browse files
authored
Merge pull request #312 from ewasm/cleanup
Add stack cleanup helper for 160-bit
2 parents 97b8d00 + 39fc25e commit c71beff

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

wasm/generateInterface.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ function checkOverflowStackItem256 (spOffset) {
222222
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3}))))`
223223
}
224224

225+
// assumes the stack contains 160 bits of value and clears the rest
226+
function cleanupStackItem160 (spOffset) {
227+
return `
228+
;; zero out mem
229+
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})) (i64.const 0))
230+
(i32.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2 + 4})) (i32.const 0))`
231+
}
232+
225233
// assumes the stack contains 128 bits of value and clears the rest
226234
function cleanupStackItem128 (spOffset) {
227235
return `
@@ -383,11 +391,8 @@ function generateManifest (interfaceManifest, opts) {
383391
call += '(get_local $callback)'
384392
}
385393

386-
// FIXME: implement support in cleanupStackItem160
387-
call += `)
388-
;; zero out mem
389-
(i64.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})) (i64.const 0))
390-
(i32.store (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2 + 4})) (i32.const 0))`
394+
call += ')'
395+
call += cleanupStackItem160(spOffset)
391396
} else if (output === 'i256') {
392397
call = `${call}
393398
(i32.add (get_global $sp)

0 commit comments

Comments
 (0)