@@ -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,25 +142,25 @@ 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' ] ,
157
+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
156
158
output : [ 'i32' ]
157
159
} ,
158
160
STATICCALL : {
159
161
name : 'callStatic' ,
160
162
async : true ,
161
- input : [ 'gasLimit' , 'address' , 'readOffset' , 'length' ] ,
163
+ input : [ 'gasLimit' , 'address' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
162
164
output : [ 'i32' ]
163
165
} ,
164
166
RETURNDATACOPY : {
@@ -262,7 +264,8 @@ function generateManifest (interfaceManifest, opts) {
262
264
for ( let opcode in interfaceManifest ) {
263
265
const op = interfaceManifest [ opcode ]
264
266
// Translate input types to native wasm types
265
- let inputs = op . input . map ( type => toWasmType ( type ) )
267
+ // callReturnMemoryOffset and callReturnMemorySize are actually output and must be ignored here
268
+ let inputs = op . input . filter ( type => type !== 'callReturnMemoryOffset' && type !== 'callReturnMemorySize' ) . map ( type => toWasmType ( type ) )
266
269
// Also add output types which are non-basic because they need to be passed as inputs
267
270
inputs = inputs . concat ( op . output . filter ( type => type !== 'i32' && type !== 'i64' ) . map ( type => toWasmType ( type ) ) )
268
271
let params = ''
@@ -344,7 +347,13 @@ function generateManifest (interfaceManifest, opts) {
344
347
locals += `(local $offset${ numOfLocals } i32)`
345
348
body += `(set_local $offset${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
346
349
call += `(get_local $offset${ numOfLocals } )`
347
- } else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL' ) ) {
350
+ } else if ( input === 'callReturnMemoryOffset' || input === 'callReturnMemorySize' ) {
351
+ // FIXME: this should actually insert a wrapper for invoking returndatacopy
352
+ // with these arguments in the postprocessing step
353
+
354
+ // Remove (ignore) this stack item here
355
+ spOffset --
356
+ } else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' ) ) {
348
357
// CALLs in EVM have 7 arguments
349
358
// but in ewasm CALLs only have 5 arguments
350
359
// so delete the bottom two stack elements, after processing the 5th argument
@@ -358,12 +367,6 @@ function generateManifest (interfaceManifest, opts) {
358
367
359
368
call += `(get_local $length${ numOfLocals } )`
360
369
numOfLocals ++
361
-
362
- // delete 6th stack element
363
- spOffset --
364
-
365
- // delete 7th stack element
366
- spOffset --
367
370
} else if ( input === 'length' && ( opcode !== 'CALL' && opcode !== 'CALLCODE' && opcode !== 'DELEGATECALL' && opcode !== 'STATICCALL' ) ) {
368
371
locals += `(local $length${ numOfLocals } i32)`
369
372
body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
@@ -420,6 +423,9 @@ function generateManifest (interfaceManifest, opts) {
420
423
if ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL' ) {
421
424
// flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
422
425
call = `(i64.store ${ getStackItem ( spOffset ) } (i64.extend_u/i32 (i32.eqz ${ call } )))`
426
+
427
+ // FIXME: add callReturnMemory* handling here
428
+
423
429
} else {
424
430
call = `(i64.store ${ getStackItem ( spOffset ) } (i64.extend_u/i32 ${ call } ))`
425
431
}
0 commit comments