@@ -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 : {
@@ -228,7 +230,8 @@ function generateManifest (interfaceManifest, opts) {
228230 for ( let opcode in interfaceManifest ) {
229231 const op = interfaceManifest [ opcode ]
230232 // Translate input types to native wasm types
231- let inputs = op . input . map ( type => toWasmType ( type ) )
233+ // callReturnMemoryOffset and callReturnMemorySize are actually output and must be ignored here
234+ let inputs = op . input . filter ( type => type !== 'callReturnMemoryOffset' && type !== 'callReturnMemorySize' ) . map ( type => toWasmType ( type ) )
232235 // Also add output types which are non-basic because they need to be passed as inputs
233236 inputs = inputs . concat ( op . output . filter ( type => type !== 'i32' && type !== 'i64' ) . map ( type => toWasmType ( type ) ) )
234237 let params = ''
@@ -310,7 +313,13 @@ function generateManifest (interfaceManifest, opts) {
310313 locals += `(local $offset${ numOfLocals } i32)`
311314 body += `(set_local $offset${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
312315 call += `(get_local $offset${ numOfLocals } )`
313- } else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL' ) ) {
316+ } else if ( input === 'callReturnMemoryOffset' || input === 'callReturnMemorySize' ) {
317+ // FIXME: this should actually insert a wrapper for invoking returndatacopy
318+ // with these arguments in the postprocessing step
319+
320+ // Remove (ignore) this stack item here
321+ spOffset --
322+ } else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' ) ) {
314323 // CALLs in EVM have 7 arguments
315324 // but in ewasm CALLs only have 5 arguments
316325 // so delete the bottom two stack elements, after processing the 5th argument
@@ -324,12 +333,6 @@ function generateManifest (interfaceManifest, opts) {
324333
325334 call += `(get_local $length${ numOfLocals } )`
326335 numOfLocals ++
327-
328- // delete 6th stack element
329- spOffset --
330-
331- // delete 7th stack element
332- spOffset --
333336 } else if ( input === 'length' && ( opcode !== 'CALL' && opcode !== 'CALLCODE' && opcode !== 'DELEGATECALL' && opcode !== 'STATICCALL' ) ) {
334337 locals += `(local $length${ numOfLocals } i32)`
335338 body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
@@ -397,6 +400,8 @@ function generateManifest (interfaceManifest, opts) {
397400 (i32.eqz ${ call } ) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
398401 )))`
399402
403+ // FIXME: add callReturnMemory* handling here
404+
400405 } else {
401406 call =
402407 `(i64.store
0 commit comments