From 10bfbf3876c6d4cd9f20f16b50e5fff6bdb920ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Wed, 13 Apr 2022 22:31:41 +0200 Subject: [PATCH] remove commander dependency --- Makefile | 4 ++-- package.json | 1 - src/tools/process.js | 26 ++++++++++++-------------- yarn.lock | 5 ----- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index b9d839b..32825fc 100644 --- a/Makefile +++ b/Makefile @@ -26,13 +26,13 @@ src/waforth.wasm: src/waforth.wat $(WAT2WASM) $(WAT2WASM_FLAGS) -o $@ $< src/waforth.vanilla.wat: src/waforth.wat - ./src/tools/process.js $< > $@ + ./src/tools/process.js $< $@ src/waforth.bulkmem.wasm: src/waforth.bulkmem.wat $(WAT2WASM) $(WAT2WASM_FLAGS) --enable-bulk-memory -o $@ $< src/waforth.bulkmem.wat: src/waforth.wat - ./src/tools/process.js --enable-bulk-memory $< > $@ + ./src/tools/process.js --enable-bulk-memory $< $@ src/benchmarks/sieve-vanilla.wasm: src/benchmarks/sieve-vanilla.wat $(WAT2WASM) $(WAT2WASM_FLAGS) -o $@ $< diff --git a/package.json b/package.json index bb3bb7d..f437b80 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "@babel/preset-env": "^7.16.11", "@babel/register": "^7.17.7", "chai": "^4.3.6", - "commander": "^9.1.0", "esbuild": "^0.14.36", "eslint": "^8.13.0", "eslint-plugin-prettier": "^4.0.0", diff --git a/src/tools/process.js b/src/tools/process.js index b8a5598..5ce9381 100755 --- a/src/tools/process.js +++ b/src/tools/process.js @@ -3,25 +3,21 @@ const process = require("process"); const fs = require("fs"); const _ = require("lodash"); -const program = require("commander"); -let file; -program - .arguments("") - .option( - "--enable-bulk-memory", - "use bulk memory operations instead of own implementation" - ) - .action((f) => { - file = f; - }); -program.parse(process.argv); +const args = process.argv.slice(2); +let enableBulkMemory = false; +if (args[0] === "--enable-bulk-memory") { + enableBulkMemory = true; + args.shift(); +} +const [file, outfile] = args; const lines = fs.readFileSync(file).toString().split("\n"); const definitions = {}; let skipLevel = 0; let skippingDefinition = false; +let out = []; lines.forEach((line) => { // Constants Object.keys(definitions).forEach((k) => { @@ -39,7 +35,7 @@ lines.forEach((line) => { } // Bulk memory operations - if (program.enableBulkMemory) { + if (enableBulkMemory) { line = line .replace(/\(call \$memcopy/g, "(memory.copy") .replace(/\(call \$memset/g, "(memory.fill"); @@ -55,10 +51,12 @@ lines.forEach((line) => { // Output line if (!skippingDefinition) { - console.log(line); + out.push(line); } if (skippingDefinition && skipLevel <= 0) { skippingDefinition = false; } }); + +fs.writeFileSync(outfile, out.join("\n")); diff --git a/yarn.lock b/yarn.lock index d78adcb..1bdcefc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1225,11 +1225,6 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -commander@^9.1.0: - version "9.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-9.1.0.tgz#a6b263b2327f2e188c6402c42623327909f2dbec" - integrity sha512-i0/MaqBtdbnJ4XQs4Pmyb+oFQl+q0lsAmokVUH92SlSw4fkeAcG3bVon+Qt7hmtF+u3Het6o4VgrcY3qAoEB6w== - commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"