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

Commit

Permalink
Add proper input field for callReturnMemory* instead of workarounds (…
Browse files Browse the repository at this point in the history
…it is not fully supported yet)
  • Loading branch information
axic committed Aug 2, 2018
1 parent 2bdcb3b commit 1661d75
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions wasm/generateInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const wasmTypes = {
ipointer: 'i32',
opointer: 'i32',
gasLimit: 'i64',
callReturnMemoryOffset: 'i32',
callReturnMemorySize: 'i32',
// FIXME: these are handled wrongly currently
address: 'i32',
i128: 'i32',
Expand Down Expand Up @@ -140,19 +142,19 @@ const interfaceManifest = {
CALL: {
name: 'call',
async: true,
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length'],
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'callReturnMemoryOffset', 'callReturnMemorySize'],
output: ['i32']
},
CALLCODE: {
name: 'callCode',
async: true,
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length'],
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'callReturnMemoryOffset', 'callReturnMemorySize'],
output: ['i32']
},
DELEGATECALL: {
name: 'callDelegate',
async: true,
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length'],
input: ['gasLimit', 'address', 'i128', 'readOffset', 'length', 'writeOffset', 'length', 'callReturnMemoryOffset', 'callReturnMemorySize'],
output: ['i32']
},
SSTORE: {
Expand Down Expand Up @@ -207,7 +209,8 @@ function generateManifest (interfaceManifest, opts) {
for (let opcode in interfaceManifest) {
const op = interfaceManifest[opcode]
// Translate input types to native wasm types
let inputs = op.input.map(type => toWasmType(type))
// callReturnMemoryOffset and callReturnMemorySize are actually output and must be ignored here
let inputs = op.input.filter(type => type !== 'callReturnMemoryOffset' && type !== 'callReturnMemorySize').map(type => toWasmType(type))
// Also add output types which are non-basic because they need to be passed as inputs
inputs = inputs.concat(op.output.filter(type => type !== 'i32' && type !== 'i64').map(type => toWasmType(type)))
let params = ''
Expand Down Expand Up @@ -289,6 +292,12 @@ function generateManifest (interfaceManifest, opts) {
locals += `(local $offset${numOfLocals} i32)`
body += `(set_local $offset${numOfLocals} ${checkOverflowStackItem256(spOffset)})`
call += `(get_local $offset${numOfLocals})`
} else if (input === 'callReturnMemoryOffset' || input === 'callReturnMemorySize') {
// FIXME: this should actually insert a wrapper for invoking returndatacopy
// with these arguments in the postprocessing step

// Remove (ignore) this stack item here
spOffset--
} else if (input === 'length' && (opcode === 'CALL' || opcode === 'CALLCODE')) {
// CALLs in EVM have 7 arguments
// but in ewasm CALLs only have 5 arguments
Expand All @@ -303,12 +312,6 @@ function generateManifest (interfaceManifest, opts) {

call += `(get_local $length${numOfLocals})`
numOfLocals++

// delete 6th stack element
spOffset--

// delete 7th stack element
spOffset--
} else if (input === 'length' && (opcode !== 'CALL' && opcode !== 'CALLCODE')) {
locals += `(local $length${numOfLocals} i32)`
body += `(set_local $length${numOfLocals} ${checkOverflowStackItem256(spOffset)})`
Expand Down Expand Up @@ -376,6 +379,8 @@ function generateManifest (interfaceManifest, opts) {
(i32.eqz ${call}) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
)))`

// FIXME: add callReturnMemory* handling here

} else {
call =
`(i64.store
Expand Down

0 comments on commit 1661d75

Please sign in to comment.