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

Commit b82ba4d

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

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: {
@@ -289,6 +291,12 @@ function generateManifest (interfaceManifest, opts) {
289291
locals += `(local $offset${numOfLocals} i32)`
290292
body += `(set_local $offset${numOfLocals} ${checkOverflowStackItem256(spOffset)})`
291293
call += `(get_local $offset${numOfLocals})`
294+
} else if (input === 'callReturnMemoryOffset' || input === 'callReturnMemorySize') {
295+
// FIXME: this should actually insert a wrapper for invoking returndatacopy
296+
// with these arguments in the postprocessing step
297+
298+
// Remove (ignore) this stack item here
299+
spOffset--
292300
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE')) {
293301
// CALLs in EVM have 7 arguments
294302
// but in ewasm CALLs only have 5 arguments
@@ -303,12 +311,6 @@ function generateManifest (interfaceManifest, opts) {
303311

304312
call += `(get_local $length${numOfLocals})`
305313
numOfLocals++
306-
307-
// delete 6th stack element
308-
spOffset--
309-
310-
// delete 7th stack element
311-
spOffset--
312314
} else if (input === 'length' && (opcode !== 'CALL' && opcode !== 'CALLCODE')) {
313315
locals += `(local $length${numOfLocals} i32)`
314316
body += `(set_local $length${numOfLocals} ${checkOverflowStackItem256(spOffset)})`
@@ -376,6 +378,8 @@ function generateManifest (interfaceManifest, opts) {
376378
(i32.eqz ${call}) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
377379
)))`
378380

381+
// FIXME: add callReturnMemory* handling here
382+
379383
} else {
380384
call =
381385
`(i64.store

0 commit comments

Comments
 (0)