@@ -13,6 +13,8 @@ const wasmTypes = {
13
13
ipointer : 'i32' ,
14
14
opointer : 'i32' ,
15
15
gasLimit : 'i64' ,
16
+ callReturnMemoryOffset : 'i32' ,
17
+ callReturnMemorySize : 'i32' ,
16
18
// FIXME: these are handled wrongly currently
17
19
address : 'i32' ,
18
20
i128 : 'i32' ,
@@ -140,19 +142,19 @@ const interfaceManifest = {
140
142
CALL : {
141
143
name : 'call' ,
142
144
async : true ,
143
- input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' ] ,
145
+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
144
146
output : [ 'i32' ]
145
147
} ,
146
148
CALLCODE : {
147
149
name : 'callCode' ,
148
150
async : true ,
149
- input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' ] ,
151
+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
150
152
output : [ 'i32' ]
151
153
} ,
152
154
DELEGATECALL : {
153
155
name : 'callDelegate' ,
154
156
async : true ,
155
- input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'writeOffset' , 'length' ] ,
157
+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'writeOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
156
158
output : [ 'i32' ]
157
159
} ,
158
160
SSTORE : {
@@ -207,7 +209,8 @@ function generateManifest (interfaceManifest, opts) {
207
209
for ( let opcode in interfaceManifest ) {
208
210
const op = interfaceManifest [ opcode ]
209
211
// Translate input types to native wasm types
210
- let inputs = op . input . map ( type => toWasmType ( type ) )
212
+ // callReturnMemoryOffset and callReturnMemorySize are actually output and must be ignored here
213
+ let inputs = op . input . filter ( type => type !== 'callReturnMemoryOffset' && type !== 'callReturnMemorySize' ) . map ( type => toWasmType ( type ) )
211
214
// Also add output types which are non-basic because they need to be passed as inputs
212
215
inputs = inputs . concat ( op . output . filter ( type => type !== 'i32' && type !== 'i64' ) . map ( type => toWasmType ( type ) ) )
213
216
let params = ''
@@ -289,6 +292,12 @@ function generateManifest (interfaceManifest, opts) {
289
292
locals += `(local $offset${ numOfLocals } i32)`
290
293
body += `(set_local $offset${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
291
294
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 --
292
301
} else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' ) ) {
293
302
// CALLs in EVM have 7 arguments
294
303
// but in ewasm CALLs only have 5 arguments
@@ -303,12 +312,6 @@ function generateManifest (interfaceManifest, opts) {
303
312
304
313
call += `(get_local $length${ numOfLocals } )`
305
314
numOfLocals ++
306
-
307
- // delete 6th stack element
308
- spOffset --
309
-
310
- // delete 7th stack element
311
- spOffset --
312
315
} else if ( input === 'length' && ( opcode !== 'CALL' && opcode !== 'CALLCODE' ) ) {
313
316
locals += `(local $length${ numOfLocals } i32)`
314
317
body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
@@ -376,6 +379,8 @@ function generateManifest (interfaceManifest, opts) {
376
379
(i32.eqz ${ call } ) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
377
380
)))`
378
381
382
+ // FIXME: add callReturnMemory* handling here
383
+
379
384
} else {
380
385
call =
381
386
`(i64.store
0 commit comments