Skip to content

Commit

Permalink
直接读入 wasm binary 进行解析
Browse files Browse the repository at this point in the history
  • Loading branch information
LSTM-Kirigaya committed Oct 31, 2024
1 parent 4e53d54 commit 34dc4a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions bin/vcd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 行
// 请严格对准转换规则
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 34dc4a0

Please sign in to comment.