From 34dc4a004db04a0e0c7bb8c48e7978e376d0646d Mon Sep 17 00:00:00 2001 From: LSTM-Kirigaya <1193466151@qq.com> Date: Thu, 31 Oct 2024 19:59:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=AF=BB=E5=85=A5=20wasm=20b?= =?UTF-8?q?inary=20=E8=BF=9B=E8=A1=8C=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/vcd.js | 8 ++++---- deploy.sh | 2 +- test/test.js | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/test.js diff --git a/bin/vcd.js b/bin/vcd.js index 00f49cb..f5f15ee 100644 --- a/bin/vcd.js +++ b/bin/vcd.js @@ -110,8 +110,8 @@ function parseTimescale(timescale) { * clean: () => void * }} */ -async function makeVcdStream() { - const vcdstream = await getVcdStream(); +async function makeVcdStream(moduleArg) { + const vcdstream = await getVcdStream(moduleArg); // 使用 vcdstream 的 any 回调获取波形数据,并按照正确的格式进行解码和存储 // 这段处理来自 https://github.com/wavedrom/vcd 的 vcd-pipe-deso.js 的 58 行 // 请严格对准转换规则 @@ -203,8 +203,8 @@ function consume(vcdstream, arraybuffer, config) { } } -async function getVcdStream() { - const wasm = await createVCD(); +async function getVcdStream(moduleArg) { + const wasm = await createVCD(moduleArg); const vcdstream = await webVcdParser(wasm); return vcdstream; } diff --git a/deploy.sh b/deploy.sh index e86f20c..8875120 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,4 +1,4 @@ browserify ./bin/vcd.js | terser --compress -o ./out/vcd-web.js -sed -i -e 's/wasmBinaryFile=Module.locateFile?Module.locateFile(path,scriptDirectory):scriptDirectory+path/wasmBinaryFile=self.location.href.replace("worker.js", "vcd.wasm")/g' out/vcd-web.js +sed -i -e 's/wasmBinaryFile=Module.locateFile?Module.locateFile(path,scriptDirectory):scriptDirectory+path/wasmBinaryFile=Module.locateFile?Module.locateFile(path,scriptDirectory):scriptDirectory+path/g' out/vcd-web.js cp out/vcd-web.js $1/public/vcd.js cp out/vcd.wasm $1/public/vcd.wasm diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..197804b --- /dev/null +++ b/test/test.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const { makeVcdStream } = require('../bin/vcd'); +const createVcd = require('../out/vcd.js'); + +async function main() { + const wasmBinary = fs.readFileSync('./vcd.wasm'); + const wasm = await createVcd({ wasmBinary }); + console.log(wasm); + + + return; + + // const vcdstream = await makeVcdStream(); + // const arraybuffer = fs.readFileSync('./test/samples/iverilog.small.vcd'); + // const answers = JSON.parse(fs.readFileSync('./test/samples/iverilog.small.json')); + + // vcdstream.consume(arraybuffer); + // const info = vcdstream.getBasicInfo(); + // const values = info.signalValues; +} + + +main(); \ No newline at end of file