-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const maxChunkLength = 1 << 17; // Number.MAX_SAFE_INTEGER; // 5e6; // 300000; // 1 << 23; | ||
|
||
const getVcd = async (readers, content, inst) => { | ||
const r = readers.find(reader => reader.ext === 'vcd'); | ||
if (r) { | ||
// console.log('VCD', r); | ||
document.title = r.baseName; | ||
content.innerHTML = '<div class="wd-progress">LOADING...</div>'; | ||
let total = 0; | ||
outerLoop: | ||
for (let i = 0; i < 1e5; i++) { | ||
const { done, value } = await r.reader.read(); | ||
|
||
if (done && (value === undefined)) { | ||
// console.log('the end'); | ||
inst.end(); | ||
break outerLoop; | ||
} | ||
const len = value.length; | ||
for (let j = 0; j < len; j += maxChunkLength) { | ||
const value1 = value.slice(j, j + maxChunkLength); | ||
const len1 = value1.length; | ||
total += len1; | ||
|
||
// const vh = u8toStr(value1.slice(0, 100)); | ||
// const vt = u8toStr(value1.slice(-100)); | ||
// console.log({len1, done, total, vh, vt}); | ||
|
||
content.innerHTML = '<div class="wd-progress">' + total.toLocaleString() + '</div>'; | ||
if (done && ((j + maxChunkLength) >= len)) { | ||
// console.log('last chunk'); | ||
inst.end(value1); | ||
break outerLoop; | ||
} | ||
inst.write(value1); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
module.exports = getVcd; | ||
|
||
/* eslint-env browser */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
'use strict'; | ||
|
||
const parseTimescale = require('./parse-time-scale.js'); | ||
|
||
const MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER); | ||
|
||
const numberOrString = val => { | ||
if (val < MAX_SAFE_INTEGER) { | ||
return Number(val); | ||
} | ||
return '0x' + val.toString(16); | ||
}; | ||
|
||
const gcd = (a, b) => { | ||
if (a === undefined) { | ||
return b; | ||
} | ||
let r; | ||
while (b !== 0) { | ||
r = a % b; | ||
a = b; | ||
b = r; | ||
} | ||
return (a < 0) ? -a : a; | ||
}; | ||
|
||
const tNorm = o => { | ||
const {tgcd, chango} = o; | ||
|
||
o.t0 /= tgcd; | ||
o.time /= tgcd; | ||
Object.keys(chango).map(key => { | ||
const {wave} = chango[key]; | ||
wave.map(e => { | ||
e[0] /= tgcd; | ||
}); | ||
}); | ||
|
||
const exp = Math.log10(tgcd) |0; | ||
if (exp > 0) { | ||
const scale = Math.pow(10, exp); | ||
const tgcd1 = tgcd / scale; | ||
if (tgcd1 === (tgcd1 |0)) { | ||
o.tgcd = tgcd1; | ||
o.timescale += exp; | ||
} | ||
} | ||
return o; | ||
}; | ||
|
||
|
||
module.exports = async (deso, inst, done) => { | ||
const chango = {}; | ||
let tgcd; | ||
deso.chango = chango; | ||
deso.view = []; | ||
|
||
const onAnyChange = (id, time, cmd, value, mask) => { | ||
// console.log(id, time, cmd, value, mask); | ||
const time53 = Number(time); | ||
tgcd = gcd(tgcd, time53); | ||
chango[id] = chango[id] || {wave: []}; | ||
if (cmd >= 14 && cmd <= 28) { | ||
chango[id].kind = 'bit'; | ||
chango[id].wave.push([time53, cmd - 14]); | ||
} else { | ||
chango[id].kind = 'vec'; | ||
const point = [time53, numberOrString(value)]; | ||
if (mask !== 0n) { | ||
point.push(numberOrString(mask)); | ||
} | ||
chango[id].wave.push(point); | ||
} | ||
}; | ||
|
||
const t0 = Date.now(); | ||
|
||
inst.on('$enddefinitions', () => { | ||
// console.log('$enddefinitions'); | ||
Object.assign(deso.wires, inst.info.wires); | ||
deso.timescale = parseTimescale(inst.info.timescale); | ||
}); | ||
|
||
inst.change.any(onAnyChange); | ||
|
||
inst.on('finish', () => { | ||
console.log((Date.now() - t0) / 1000); | ||
deso.tgcd = tgcd; | ||
deso.t0 = (inst.info.t0 || 0); | ||
// console.log(inst.getTime()); | ||
deso.time = Number(inst.getTime()); | ||
tNorm(deso); | ||
done(deso); | ||
}); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.