Skip to content

Commit fc85554

Browse files
committed
vscode plugin rework
1 parent 6ec03a5 commit fc85554

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

lib/get-vcd.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const maxChunkLength = 1 << 17; // Number.MAX_SAFE_INTEGER; // 5e6; // 300000; // 1 << 23;
4+
5+
const getVcd = async (readers, content, inst) => {
6+
const r = readers.find(reader => reader.ext === 'vcd');
7+
if (r) {
8+
// console.log('VCD', r);
9+
document.title = r.baseName;
10+
content.innerHTML = '<div class="wd-progress">LOADING...</div>';
11+
let total = 0;
12+
outerLoop:
13+
for (let i = 0; i < 1e5; i++) {
14+
const { done, value } = await r.reader.read();
15+
16+
if (done && (value === undefined)) {
17+
// console.log('the end');
18+
inst.end();
19+
break outerLoop;
20+
}
21+
const len = value.length;
22+
for (let j = 0; j < len; j += maxChunkLength) {
23+
const value1 = value.slice(j, j + maxChunkLength);
24+
const len1 = value1.length;
25+
total += len1;
26+
27+
// const vh = u8toStr(value1.slice(0, 100));
28+
// const vt = u8toStr(value1.slice(-100));
29+
// console.log({len1, done, total, vh, vt});
30+
31+
content.innerHTML = '<div class="wd-progress">' + total.toLocaleString() + '</div>';
32+
if (done && ((j + maxChunkLength) >= len)) {
33+
// console.log('last chunk');
34+
inst.end(value1);
35+
break outerLoop;
36+
}
37+
inst.write(value1);
38+
}
39+
}
40+
}
41+
};
42+
43+
module.exports = getVcd;
44+
45+
/* eslint-env browser */

lib/vcd-pipe-deso.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
3+
const parseTimescale = require('./parse-time-scale.js');
4+
5+
const MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
6+
7+
const numberOrString = val => {
8+
if (val < MAX_SAFE_INTEGER) {
9+
return Number(val);
10+
}
11+
return '0x' + val.toString(16);
12+
};
13+
14+
const gcd = (a, b) => {
15+
if (a === undefined) {
16+
return b;
17+
}
18+
let r;
19+
while (b !== 0) {
20+
r = a % b;
21+
a = b;
22+
b = r;
23+
}
24+
return (a < 0) ? -a : a;
25+
};
26+
27+
const tNorm = o => {
28+
const {tgcd, chango} = o;
29+
30+
o.t0 /= tgcd;
31+
o.time /= tgcd;
32+
Object.keys(chango).map(key => {
33+
const {wave} = chango[key];
34+
wave.map(e => {
35+
e[0] /= tgcd;
36+
});
37+
});
38+
39+
const exp = Math.log10(tgcd) |0;
40+
if (exp > 0) {
41+
const scale = Math.pow(10, exp);
42+
const tgcd1 = tgcd / scale;
43+
if (tgcd1 === (tgcd1 |0)) {
44+
o.tgcd = tgcd1;
45+
o.timescale += exp;
46+
}
47+
}
48+
return o;
49+
};
50+
51+
52+
module.exports = async (deso, inst, done) => {
53+
const chango = {};
54+
let tgcd;
55+
deso.chango = chango;
56+
deso.view = [];
57+
58+
const onAnyChange = (id, time, cmd, value, mask) => {
59+
// console.log(id, time, cmd, value, mask);
60+
const time53 = Number(time);
61+
tgcd = gcd(tgcd, time53);
62+
chango[id] = chango[id] || {wave: []};
63+
if (cmd >= 14 && cmd <= 28) {
64+
chango[id].kind = 'bit';
65+
chango[id].wave.push([time53, cmd - 14]);
66+
} else {
67+
chango[id].kind = 'vec';
68+
const point = [time53, numberOrString(value)];
69+
if (mask !== 0n) {
70+
point.push(numberOrString(mask));
71+
}
72+
chango[id].wave.push(point);
73+
}
74+
};
75+
76+
const t0 = Date.now();
77+
78+
inst.on('$enddefinitions', () => {
79+
// console.log('$enddefinitions');
80+
Object.assign(deso.wires, inst.info.wires);
81+
deso.timescale = parseTimescale(inst.info.timescale);
82+
});
83+
84+
inst.change.any(onAnyChange);
85+
86+
inst.on('finish', () => {
87+
console.log((Date.now() - t0) / 1000);
88+
deso.tgcd = tgcd;
89+
deso.t0 = (inst.info.t0 || 0);
90+
// console.log(inst.getTime());
91+
deso.time = Number(inst.getTime());
92+
tNorm(deso);
93+
done(deso);
94+
});
95+
};

out/vcd.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/vcd.wasm

-34 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)