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

Commit

Permalink
Merge pull request #207 from ewasm/cli-fixes
Browse files Browse the repository at this point in the history
CLI fixes regarding parameters
  • Loading branch information
axic authored Mar 28, 2018
2 parents 7867206 + e81136a commit e050d24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@ matrix:
- LANG=cpp

before_install:
- git submodule update --init
- |
set -e
git submodule update --init
if [ $LANG = js ]; then
./tools/wabt/scripts/travis-before-install.sh
cd ./tools/wabt/ && make
(cd ./tools/wabt/ && make)
npm install
npm run validateBuild
fi
script:
- |
set -e
if [ $LANG = js ]; then
bin/evm2wasm.js 0x600160020200 trace
./bin/evm2wasm.js 600160020200 --trace
npm run $TEST_SUITE
fi
- |
if [ $LANG = cpp ]; then
mkdir build && cd build
cmake ..
Expand Down
27 changes: 13 additions & 14 deletions bin/evm2wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ const argv = require('minimist')(process.argv.slice(2))
const fs = require('fs')

// convert evm bytecode to WASM or WAST
function convert (bytecode, wast) {
function convert (bytecode, opts) {
return new Promise((resolve, reject) => {
outputFile = argv.o ? argv.o : undefined

if (!bytecode) {
resolve(Buffer.from(''))
return resolve(Buffer.from(''))
}

if (wast) {
if (opts.wast) {
let output = evm2wasm.evm2wast(bytecode, {
stackTrace: trace,
stackTrace: opts.trace,
tempName: 'temp',
inlineOps: true,
wabt: false
})
resolve(output)
} else {
evm2wasm.evm2wasm(bytecode, {
stackTrace: trace,
stackTrace: opts.trace,
tempName: 'temp',
inlineOps: true,
wabt: false
Expand All @@ -48,28 +46,29 @@ function storeOrPrintResult (output, outputFile) {
}
}

let outputFile = argv.o ? argv.o : undefined
let wast = argv.wast !== undefined
const outputFile = argv.o ? argv.o : undefined
const wast = argv.wast !== undefined
const trace = argv.trace !== undefined
let file = argv.e ? argv.e : undefined
const inputFile = argv.e ? argv.e : undefined

let bytecode

try {
if (!file) {
if (!inputFile) {
if (argv._.length > 0) {
bytecode = argv._[0]
// ensure it is a string even it was passed as a number
bytecode = argv._[0].toString()
} else {
throw new Error('must provide evm bytecode file or supply bytecode as a non-named argument')
}
} else {
bytecode = fs.readFileSync(file).toString()
bytecode = fs.readFileSync(inputFile).toString()
}

// always consider input EVM as a hex string and translate that into binary for the next stage
bytecode = Buffer.from(bytecode, 'hex')

convert(bytecode, wast).then((result) => {
convert(bytecode, { wast: wast, trace: trace }).then((result) => {
storeOrPrintResult(result, outputFile)
}).catch((err) => {
throw err
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"transcompiler"
],
"dependencies": {
"eslint": "^4.19.1",
"ethereumjs-block": "^1.2.2",
"ethereumjs-util": "^5.1.5",
"ewasm-kernel": "git+https://github.com/ewasm/ewasm-kernel.git#async-pojo",
Expand Down

0 comments on commit e050d24

Please sign in to comment.