@@ -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,25 +142,25 @@ 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' ] ,
157+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
156158 output : [ 'i32' ]
157159 } ,
158160 STATICCALL : {
159161 name : 'callStatic' ,
160162 async : true ,
161- input : [ 'gasLimit' , 'address' , 'readOffset' , 'length' ] ,
163+ input : [ 'gasLimit' , 'address' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
162164 output : [ 'i32' ]
163165 } ,
164166 RETURNDATACOPY : {
@@ -262,7 +264,8 @@ function generateManifest (interfaceManifest, opts) {
262264 for ( let opcode in interfaceManifest ) {
263265 const op = interfaceManifest [ opcode ]
264266 // 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 ) )
266269 // Also add output types which are non-basic because they need to be passed as inputs
267270 inputs = inputs . concat ( op . output . filter ( type => type !== 'i32' && type !== 'i64' ) . map ( type => toWasmType ( type ) ) )
268271 let params = ''
@@ -344,7 +347,13 @@ function generateManifest (interfaceManifest, opts) {
344347 locals += `(local $offset${ numOfLocals } i32)`
345348 body += `(set_local $offset${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
346349 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' ) ) {
348357 // CALLs in EVM have 7 arguments
349358 // but in ewasm CALLs only have 5 arguments
350359 // so delete the bottom two stack elements, after processing the 5th argument
@@ -358,12 +367,6 @@ function generateManifest (interfaceManifest, opts) {
358367
359368 call += `(get_local $length${ numOfLocals } )`
360369 numOfLocals ++
361-
362- // delete 6th stack element
363- spOffset --
364-
365- // delete 7th stack element
366- spOffset --
367370 } else if ( input === 'length' && ( opcode !== 'CALL' && opcode !== 'CALLCODE' && opcode !== 'DELEGATECALL' && opcode !== 'STATICCALL' ) ) {
368371 locals += `(local $length${ numOfLocals } i32)`
369372 body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
@@ -420,6 +423,9 @@ function generateManifest (interfaceManifest, opts) {
420423 if ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL' ) {
421424 // flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
422425 call = `(i64.store ${ getStackItem ( spOffset ) } (i64.extend_u/i32 (i32.eqz ${ call } )))`
426+
427+ // FIXME: add callReturnMemory* handling here
428+
423429 } else {
424430 call = `(i64.store ${ getStackItem ( spOffset ) } (i64.extend_u/i32 ${ call } ))`
425431 }
0 commit comments