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

Commit 8866897

Browse files
committed
Add proper input field for callReturnMemory* instead of workarounds (it is not fully supported yet)
1 parent a2c5ad7 commit 8866897

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

wasm/generateInterface.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const wasmTypes = {
1313
ipointer: 'i32',
1414
opointer: 'i32',
1515
gasLimit: 'i64',
16+
callReturnMemoryOffset: 'i32',
17+
callReturnMemorySize: 'i32',
1618
// FIXME: these are handled wrongly currently
1719
address: 'i32',
1820
i128: 'i32',
@@ -140,19 +142,19 @@ const interfaceManifest = {
140142
CALL: {
141143
name: 'call',
142144
async: true,
143-
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length'],
145+
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'callReturnMemoryOffset', 'callReturnMemorySize'],
144146
output: ['i32']
145147
},
146148
CALLCODE: {
147149
name: 'callCode',
148150
async: true,
149-
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length'],
151+
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'callReturnMemoryOffset', 'callReturnMemorySize'],
150152
output: ['i32']
151153
},
152154
DELEGATECALL: {
153155
name: 'callDelegate',
154156
async: true,
155-
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length'],
157+
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length', 'callReturnMemoryOffset', 'callReturnMemorySize'],
156158
output: ['i32']
157159
},
158160
SSTORE: {
@@ -290,6 +292,12 @@ function generateManifest (interfaceManifest, opts) {
290292
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 2})))
291293
(i64.load (i32.add (get_global $sp) (i32.const ${spOffset * 32 + 8 * 3})))))`
292294
call += `(get_local $offset${numOfLocals})`
295+
} else if (input === 'callReturnMemoryOffset' || input === 'callReturnMemorySize') {
296+
// FIXME: this should actually insert a wrapper for invoking returndatacopy
297+
// with these arguments in the postprocessing step
298+
299+
// Remove (ignore) this stack item here
300+
spOffset--
293301
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE')) {
294302
// CALLs in EVM have 7 arguments
295303
// but in ewasm CALLs only have 5 arguments
@@ -308,12 +316,6 @@ function generateManifest (interfaceManifest, opts) {
308316

309317
call += `(get_local $length${numOfLocals})`
310318
numOfLocals++
311-
312-
// delete 6th stack element
313-
spOffset--
314-
315-
// delete 7th stack element
316-
spOffset--
317319
} else if (input === 'length' && (opcode !== 'CALL' && opcode !== 'CALLCODE')) {
318320
locals += `(local $length${numOfLocals} i32)`
319321
body += `(set_local $length${numOfLocals}
@@ -385,6 +387,8 @@ function generateManifest (interfaceManifest, opts) {
385387
(i32.eqz ${call}) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
386388
)))`
387389

390+
// FIXME: add callReturnMemory* handling here
391+
388392
} else {
389393
call =
390394
`(i64.store

0 commit comments

Comments
 (0)