1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-08-05 13:24:52 +00:00

Deploying to gh-pages from @ sehugg/8bitworkshop@3a960c3e6e 🚀

This commit is contained in:
sehugg
2022-02-21 15:35:52 +00:00
parent 4583cd1896
commit c2cec1701e
1873 changed files with 844165 additions and 0 deletions

48
gen/common/hdl/fuzz.js Normal file
View File

@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fuzz = void 0;
//import binaryen = require('binaryen');
//import { fn } from "jquery";
const hdlruntime_1 = require("./hdlruntime");
const hdlwasm_1 = require("./hdlwasm");
const vxmlparser_1 = require("./vxmlparser");
function fuzz(buf) {
var parser = new vxmlparser_1.VerilogXMLParser();
var str = buf.toString();
try {
parser.parse(str);
}
catch (e) {
if (e instanceof vxmlparser_1.CompileError)
return;
throw e;
}
if (1) {
var wmod = new hdlwasm_1.HDLModuleWASM(parser.modules['TOP'], parser.modules['@CONST-POOL@']);
wmod.traceBufferSize = 0x8000;
wmod.maxMemoryMB = 0.25;
wmod.initSync();
wmod.powercycle();
wmod.tick2(10000);
}
if (0) {
var jmod = new hdlruntime_1.HDLModuleJS(parser.modules['TOP'], parser.modules['@CONST-POOL@']);
jmod.init();
try {
jmod.powercycle();
jmod.tick2(10000);
}
catch (e) {
if (e instanceof hdlruntime_1.HDLError)
return;
const fs = require('fs');
fs.writeFileSync('hdlfuzz-output.js', jmod.getJSCode());
throw e;
}
finally {
jmod.dispose();
}
}
}
exports.fuzz = fuzz;
//# sourceMappingURL=fuzz.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fuzz.js","sourceRoot":"","sources":["../../../src/common/hdl/fuzz.ts"],"names":[],"mappings":";;;AACA,wCAAwC;AACxC,8BAA8B;AAC9B,6CAAqD;AACrD,uCAA0C;AAC1C,6CAA8D;AAE9D,SAAgB,IAAI,CAAC,GAAG;IACpB,IAAI,MAAM,GAAG,IAAI,6BAAgB,EAAE,CAAC;IACpC,IAAI,GAAG,GA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.HDLModuleJS = exports.HDLError = void 0;
const emu_1 = require("../emu");
const util_1 = require("../util");
const hdltypes_1 = require("./hdltypes");
class HDLError extends emu_1.EmuHalt {
constructor(obj, msg) {
super(msg, obj ? obj.$loc : null);
Object.setPrototypeOf(this, HDLError.prototype);
this.obj = obj;
if (obj)
console.log(obj);
}
}
exports.HDLError = HDLError;
class HDLModuleJS {
constructor(mod, constpool) {
this.finished = false;
this.stopped = false;
this.settleTime = 0;
this.specfuncs = [];
this.getFileData = null;
this.mod = mod;
this.constpool = constpool;
this.basefuncs = {};
this.state = {}; //new Object(this.funcs) as any;
this.globals = {};
// set built-in functions
Object.getOwnPropertyNames(Object.getPrototypeOf(this)).filter((f) => f.startsWith('$')).forEach((f) => {
this.basefuncs[f] = this[f].bind(this);
});
// set initial state
if (this.constpool) {
var cp = new HDLModuleJS(this.constpool, null);
cp.init();
Object.assign(this.state, cp.state);
Object.assign(this.globals, cp.globals);
}
for (var varname in this.mod.vardefs) {
var vardef = this.mod.vardefs[varname];
this.globals[varname] = vardef;
this.state[varname] = this.defaultValue(vardef.dtype, vardef);
}
// generate functions
this.basefuncs = this.genFuncs({});
this.curfuncs = this.basefuncs;
/*
for (var i=0; i<16; i++) {
this.specfuncs[i] = this.genFuncs({
//reset:(i&1),
//clk:(i&2),
//CPU16$state:i
test_CPU16_top$cpu$state:i
});
}
*/
}
init() {
}
dispose() {
}
genFuncs(constants) {
var funcs = Object.create(this.basefuncs);
this.curconsts = constants;
for (var block of this.mod.blocks) {
this.locals = {};
// if we have at least 1 constant value, check for it (set counter to zero)
this.constused = (Object.keys(this.curconsts).length == 0) ? 99999 : 0;
var s = this.block2js(block);
if (this.constused) {
try {
var funcname = block.name || '__anon';
var funcbody = `'use strict'; function ${funcname}(o) { ${s} }; return ${funcname};`;
var func = new Function('', funcbody)();
funcs[block.name] = func;
//console.log(funcbody);
}
catch (e) {
console.log(funcbody);
throw e;
}
}
//if (this.constused) console.log('FUNC',constants,funcname,this.constused);
}
return funcs;
}
getJSCode() {
var s = '';
for (var funcname in this.basefuncs) {
if (funcname && funcname.startsWith("_")) {
s += this.basefuncs[funcname].toString();
s += "\n";
}
}
return s;
}
powercycle() {
this.resetStartTimeMsec = new Date().getTime() - 1;
this.finished = false;
this.stopped = false;
this.basefuncs._ctor_var_reset(this.state);
this.basefuncs._eval_initial(this.state);
for (var i = 0; i < 100; i++) {
this.basefuncs._eval_settle(this.state);
this.basefuncs._eval(this.state);
var Vchange = this.basefuncs._change_request(this.state);
if (!Vchange) {
this.settleTime = i;
return;
}
}
throw new HDLError(null, `model did not converge on reset()`);
}
eval() {
var clk = this.state.clk;
var reset = this.state.reset;
var state = this.state.test_CPU16_top$cpu$state;
var opcode = this.state.CPU$opcode;
var aluop = this.state.CPU$aluop;
var fi = state;
//this.curfuncs = this.specfuncs[fi & 0xff];
this.curfuncs = this.basefuncs;
for (var i = 0; i < 100; i++) {
this.curfuncs._eval(this.state);
var Vchange = this.curfuncs._change_request(this.state);
/*
--- don't do it this way! it's like 4x slower...
this.call('_eval');
var Vchange = this.call('_change_request');
*/
if (!Vchange) {
this.settleTime = i;
return;
}
}
throw new HDLError(null, `model did not converge on eval()`);
}
tick2(iters) {
while (iters-- > 0) {
this.state.clk = 0;
this.eval();
this.state.clk = 1;
this.eval();
}
}
defaultValue(dt, vardef) {
if ((0, hdltypes_1.isLogicType)(dt)) {
if (dt.left <= 31)
return 0;
else
return BigInt(0);
}
else if ((0, hdltypes_1.isArrayType)(dt) && typeof dt.high.cvalue === 'number' && typeof dt.low.cvalue === 'number') {
let arr;
let arrlen = dt.high.cvalue - dt.low.cvalue + 1;
if (arrlen < 0)
arrlen = -arrlen; // TODO?
if ((0, hdltypes_1.isLogicType)(dt.subtype)) {
if (dt.subtype.left <= 7)
arr = new Uint8Array(arrlen);
else if (dt.subtype.left <= 15)
arr = new Uint16Array(arrlen);
else if (dt.subtype.left <= 31)
arr = new Uint32Array(arrlen);
else {
arr = []; // TODO?
}
}
else {
arr = [];
for (let i = 0; i < arrlen; i++) {
arr[i] = this.defaultValue(dt.subtype);
}
}
if (vardef != null && vardef.initValue != null) {
for (let i = 0; i < vardef.initValue.exprs.length; i++) {
let e = vardef.initValue.exprs[i];
if ((0, hdltypes_1.isArrayItem)(e) && (0, hdltypes_1.isConstExpr)(e.expr)) {
arr[e.index] = e.expr.cvalue;
}
else {
throw new HDLError(dt, `non-const expr in initarray`);
}
}
}
return arr;
}
throw new HDLError(dt, `no default value for var type: ${vardef.name}`);
}
constValue(expr) {
if ((0, hdltypes_1.isConstExpr)(expr)) {
return expr.cvalue;
}
else {
throw new HDLError(expr, `no const value for expr`);
}
}
block2js(block) {
return this.expr2js(block);
}
expr2js(e, options) {
if (e == null) {
return "/*null*/"; // TODO
}
if ((0, hdltypes_1.isVarRef)(e)) {
if (this.curconsts[e.refname] != null && !(options || {}).store) {
this.constused++;
return `${this.curconsts[e.refname]}`;
}
else if (this.locals[e.refname]) {
return `${e.refname}`;
}
else if (this.globals[e.refname]) {
return `o.${e.refname}`;
}
else
throw new HDLError(e, `cannot find variable '${e.refname}'`);
}
else if ((0, hdltypes_1.isVarDecl)(e)) {
this.locals[e.name] = e;
let s = `var ${e.name}`;
if (e.constValue != null) {
s += ` = ${this.constValue(e)}`; // TODO?
}
else if (e.initValue != null) {
// TODO?
throw new HDLError(e, `can't init array here`);
}
else if ((0, hdltypes_1.isLogicType)(e.dtype) && e.dtype.left > 31) {
// TODO: hack for big ints ($readmem)
s += ` = []`;
}
return s;
}
else if ((0, hdltypes_1.isConstExpr)(e)) {
return `0x${e.cvalue.toString(16)}`;
}
else if ((0, hdltypes_1.isBigConstExpr)(e)) {
return e.bigvalue.toString(); // TODO?
}
else if ((0, hdltypes_1.isTriop)(e)) {
switch (e.op) {
case 'if':
if (e.right == null || ((0, hdltypes_1.isBlock)(e.right) && e.right.exprs.length == 0))
return `if (${this.expr2js(e.cond, { cond: true })}) { ${this.expr2js(e.left)} }`;
else
return `if (${this.expr2js(e.cond, { cond: true })}) { ${this.expr2js(e.left)} } else { ${this.expr2js(e.right)} }`;
case 'cond':
case 'condbound':
return `(${this.expr2js(e.cond, { cond: true })} ? ${this.expr2js(e.left)} : ${this.expr2js(e.right)})`;
default:
throw new HDLError(e, `unknown triop ${e.op}`);
}
}
else if ((0, hdltypes_1.isBinop)(e)) {
switch (e.op) {
case 'contassign':
case 'assign':
case 'assignpre':
case 'assigndly':
case 'assignpost':
return `${this.expr2js(e.right, { store: true })} = ${this.expr2js(e.left)}`;
case 'arraysel':
case 'wordsel':
return `${this.expr2js(e.left)}[${this.expr2js(e.right)}]`;
case 'changedet':
// __req |= ((vlTOPp->control_test_top__02Ehsync ^ vlTOPp->__Vchglast__TOP__control_test_top__02Ehsync)
// vlTOPp->__Vchglast__TOP__control_test_top__02Ehsync = vlTOPp->control_test_top__02Ehsync;
return `$$req |= (${this.expr2js(e.left)} ^ ${this.expr2js(e.right)}); ${this.expr2js(e.right)} = ${this.expr2js(e.left)}`;
default:
var jsop = OP2JS[e.op];
if (!jsop) {
throw new HDLError(e, `unknown binop ${e.op}`);
}
if (jsop.startsWith('?')) {
jsop = jsop.substr(1);
if (!options || !options.cond) {
return `((${this.expr2js(e.left)} ${jsop} ${this.expr2js(e.right)})?1:0)`;
}
}
return `(${this.expr2js(e.left)} ${jsop} ${this.expr2js(e.right)})`;
}
}
else if ((0, hdltypes_1.isUnop)(e)) {
switch (e.op) {
case 'ccast': // TODO: cast ints, cast bools?
return this.expr2js(e.left);
case 'creturn':
return `return ${this.expr2js(e.left)}`;
case 'creset':
return this.expr2reset(e.left);
case 'not':
return `(~${this.expr2js(e.left)})`;
//return `(${this.expr2js(e.left)}?0:1)`;
case 'negate':
return `(-${this.expr2js(e.left)})`;
case 'extends':
let shift = 32 - e.widthminv;
return `((${this.expr2js(e.left)} << ${shift}) >> ${shift})`;
case 'redxor':
return `this.$$${e.op}(${this.expr2js(e.left)})`;
default:
throw new HDLError(e, `unknown unop ${e.op}`);
}
}
else if ((0, hdltypes_1.isBlock)(e)) {
// TODO: { e } ?
var body = e.exprs.map((x) => this.expr2js(x)).join(';\n');
if (e.name) {
if (e.name.startsWith('_change_request')) {
return `var $$req = 0;\n${body}\n;return $$req;`;
}
else if (e.blocktype == 'sformatf') {
var args = e.exprs.map((x) => this.expr2js(x));
args = [JSON.stringify(e.name)].concat(args);
return args.join(', ');
}
}
return body;
}
else if ((0, hdltypes_1.isWhileop)(e)) {
return `for (${this.expr2js(e.precond)}; ${this.expr2js(e.loopcond)}; ${this.expr2js(e.inc)}) { ${this.expr2js(e.body)} }`;
}
else if ((0, hdltypes_1.isFuncCall)(e)) {
if ((e.funcname == '$stop' || e.funcname == '$finish') && e.$loc) {
return `this.${e.funcname}(o, ${JSON.stringify(e.$loc)})`;
}
else if (e.args == null || e.args.length == 0) {
return `this.${e.funcname}(o)`;
}
else {
return `this.${e.funcname}(o, ${e.args.map(arg => this.expr2js(arg)).join(', ')})`;
}
}
console.log(e);
throw new Error(`unrecognized expr: ${JSON.stringify(e)}`);
}
expr2reset(e) {
if ((0, hdltypes_1.isVarRef)(e)) {
if (this.curconsts[e.refname] != null) {
return `${e.refname}`;
}
else if ((0, hdltypes_1.isLogicType)(e.dtype)) {
if (e.dtype.left <= 31)
return `${this.expr2js(e)} = 0`;
else
return `${this.expr2js(e)} = BigInt(0)`;
}
else if ((0, hdltypes_1.isArrayType)(e.dtype)) {
if ((0, hdltypes_1.isLogicType)(e.dtype.subtype)) {
return `${this.expr2js(e)}.fill(0)`;
}
else if ((0, hdltypes_1.isArrayType)(e.dtype.subtype) && (0, hdltypes_1.isLogicType)(e.dtype.subtype.subtype)) {
return `${this.expr2js(e)}.forEach((a) => a.fill(0))`;
}
else {
// TODO: 3d arrays?
throw new HDLError(e, `unsupported data type for reset: ${JSON.stringify(e.dtype)}`);
}
}
}
else {
throw new HDLError(e, `can only reset var refs`);
}
}
// runtime methods
// TODO: $time, $display, etc
$finish(o, loc) {
if (!this.finished) {
console.log("Simulation $finish", loc);
this.finished = true;
}
}
$stop(o, loc) {
if (!this.stopped) {
console.log("Simulation $stop", loc);
this.stopped = true;
}
}
$rand(o) {
return Math.random() | 0;
}
$display(o, fmt, ...args) {
// TODO: replace args, etc
console.log(fmt, args);
}
// TODO: implement arguments, XML
$readmem(o, filename, memp, lsbp, msbp, ishex) {
// parse filename from 32-bit values into characters
var barr = [];
for (var i = 0; i < filename.length; i++) {
barr.push((filename[i] >> 0) & 0xff);
barr.push((filename[i] >> 8) & 0xff);
barr.push((filename[i] >> 16) & 0xff);
barr.push((filename[i] >> 24) & 0xff);
}
barr = barr.filter(x => x != 0); // ignore zeros
barr.reverse(); // reverse it
var strfn = (0, util_1.byteArrayToString)(barr); // convert to string
// parse hex/binary file
var strdata = this.getFileData(strfn);
if (strdata == null)
throw new HDLError(null, "Could not $readmem '" + strfn + "'");
var data = strdata.split('\n').filter(s => s !== '').map(s => parseInt(s, ishex ? 16 : 2));
console.log('$readmem', ishex, strfn, data.length);
// copy into destination array
if (memp === null)
throw new HDLError(null, "No destination array to $readmem " + strfn);
if (memp.length < data.length)
throw new HDLError(null, "Destination array too small to $readmem " + strfn);
for (i = 0; i < data.length; i++)
memp[i] = data[i];
}
$time(o) {
return (new Date().getTime() - this.resetStartTimeMsec); // TODO: timescale
}
$$redxor(r) {
r = (r ^ (r >> 1));
r = (r ^ (r >> 2));
r = (r ^ (r >> 4));
r = (r ^ (r >> 8));
r = (r ^ (r >> 16));
return r;
}
//
isStopped() { return this.stopped; }
isFinished() { return this.finished; }
tick() {
this.state.clk ^= 1;
this.eval();
}
get(varname) {
return this.state[varname];
}
set(varname, value) {
if (varname in this.state) {
this.state[varname] = value;
}
}
saveState() {
return (0, util_1.safe_extend)(true, {}, this.state);
}
getGlobals() {
return this.saveState();
}
loadState(state) {
(0, util_1.safe_extend)(true, this.state, state);
}
}
exports.HDLModuleJS = HDLModuleJS;
const OP2JS = {
'eq': '?===',
'neq': '?!==',
'gt': '?>',
'lt': '?<',
'gte': '?>=',
'lte': '?<=',
'and': '&',
'or': '|',
'xor': '^',
'add': '+',
'sub': '-',
'shiftr': '>>>',
'shiftl': '<<',
// TODO: correct?
'mul': '*',
'moddiv': '%',
'div': '/',
// TODO: signed versions? functions?
'muls': '*',
'moddivs': '%',
'divs': '/',
'gts': '?>',
'gtes': '?>=',
'lts': '?<',
'ltes': '?<=',
};
/**
// SIMULATOR STUFF (should be global)
export var vl_finished = false;
export var vl_stopped = false;
export function VL_UL(x) { return x|0; }
//export function VL_ULL(x) { return x|0; }
export function VL_TIME_Q() { return (new Date().getTime())|0; }
/// Return true if data[bit] set
export function VL_BITISSET_I(data,bit) { return (data & (VL_UL(1)<<VL_UL(bit))); }
export function VL_EXTENDSIGN_I(lbits, lhs) { return (-((lhs)&(VL_UL(1)<<(lbits-1)))); }
export function VL_EXTEND_II(obits,lbits,lhs) { return lhs; }
export function VL_EXTENDS_II(x,lbits,lhs) {
return VL_EXTENDSIGN_I(lbits,lhs) | lhs;
}
export function VL_NEGATE_I(x) { return -x; }
export function VL_LTS_III(x,lbits,y,lhs,rhs) {
return (VL_EXTENDS_II(x,lbits,lhs) < VL_EXTENDS_II(x,lbits,rhs)) ? 1 : 0; }
export function VL_GTS_III(x,lbits,y,lhs,rhs) {
return (VL_EXTENDS_II(x,lbits,lhs) > VL_EXTENDS_II(x,lbits,rhs)) ? 1 : 0; }
export function VL_LTES_III(x,lbits,y,lhs,rhs) {
return (VL_EXTENDS_II(x,lbits,lhs) <= VL_EXTENDS_II(x,lbits,rhs)) ? 1 : 0; }
export function VL_GTES_III(x,lbits,y,lhs,rhs) {
return (VL_EXTENDS_II(x,lbits,lhs) >= VL_EXTENDS_II(x,lbits,rhs)) ? 1 : 0; }
export function VL_DIV_III(lbits,lhs,rhs) {
return (((rhs)==0)?0:(lhs)/(rhs)); }
export function VL_MULS_III(lbits,lhs,rhs) {
return (((rhs)==0)?0:(lhs)*(rhs)); }
export function VL_MODDIV_III(lbits,lhs,rhs) {
return (((rhs)==0)?0:(lhs)%(rhs)); }
export function VL_DIVS_III(lbits,lhs,rhs) {
var lhs_signed = VL_EXTENDS_II(32, lbits, lhs);
var rhs_signed = VL_EXTENDS_II(32, lbits, rhs);
return (((rhs_signed)==0)?0:(lhs_signed)/(rhs_signed));
}
export function VL_MODDIVS_III(lbits,lhs,rhs) {
var lhs_signed = VL_EXTENDS_II(32, lbits, lhs);
var rhs_signed = VL_EXTENDS_II(32, lbits, rhs);
return (((rhs_signed)==0)?0:(lhs_signed)%(rhs_signed));
}
export function VL_REDXOR_32(r) {
r=(r^(r>>1)); r=(r^(r>>2)); r=(r^(r>>4)); r=(r^(r>>8)); r=(r^(r>>16));
return r;
}
export var VL_WRITEF = console.log; // TODO: $write
export function vl_finish(filename,lineno,hier) {
if (!vl_finished) console.log("Finished at " + filename + ":" + lineno, hier);
vl_finished = true;
}
export function vl_stop(filename,lineno,hier) {
if (!vl_stopped) console.log("Stopped at " + filename + ":" + lineno, hier);
vl_stopped = true;
}
export function VL_RAND_RESET_I(bits) { return 0 | Math.floor(Math.random() * (1<<bits)); }
export function VL_RANDOM_I(bits) { return 0 | Math.floor(Math.random() * (1<<bits)); }
export function VL_READMEM_Q(ishex,width,depth,array_lsb,fnwords,filename,memp,start,end) {
VL_READMEM_W(ishex,width,depth,array_lsb,fnwords,filename,memp,start,end);
}
export function VL_READMEM_W(ishex,width,depth,array_lsb,fnwords,filename,memp,start,end) {
}
// SIMULATOR BASE
abstract class VerilatorBase {
totalTicks = 0;
maxVclockLoop = 0;
clk = 0;
reset = 0;
vl_fatal(msg:string) {
console.log(msg);
}
ticks() : number { return this.totalTicks; }
setTicks(T:number) { this.totalTicks = T|0; }
__reset() {
if (this.reset !== undefined) {
this.totalTicks = 0;
this.reset = 0;
this.tick2();
this.reset = 1;
}
}
tick2() {
this.clk = 0;
this.eval();
this.clk = 1;
this.eval();
}
abstract _eval(vlSymsp);
abstract __Vm_didInit : boolean;
abstract __Vm_activity : boolean;
abstract _change_request(vlSymsp);
abstract _eval_initial(vlSymsp);
abstract _eval_settle(vlSymsp);
eval() {
let vlSymsp = this; //{TOPp:this};
// Initialize
if (!vlSymsp.__Vm_didInit)
this._eval_initial_loop(vlSymsp);
// Evaluate till stable
//VL_DEBUG_IF(VL_PRINTF("\n----TOP Evaluate Vmain::eval\n"); );
var __VclockLoop = 0;
var __Vchange=1;
while (__Vchange) {
//VL_DEBUG_IF(VL_PRINTF(" Clock loop\n"););
vlSymsp.__Vm_activity = true;
this._eval(vlSymsp);
__Vchange = this._change_request(vlSymsp);
if (++__VclockLoop > 100) { this.vl_fatal("Verilated model didn't converge"); }
}
if (__VclockLoop > this.maxVclockLoop) {
this.maxVclockLoop = __VclockLoop;
if (this.maxVclockLoop > 1) {
console.log("Graph took " + this.maxVclockLoop + " iterations to stabilize");
$("#verilog_bar").show();
$("#settle_label").text(this.maxVclockLoop+"");
}
}
this.totalTicks++;
}
_eval_initial_loop(vlSymsp) {
vlSymsp.TOPp = this;
vlSymsp.__Vm_didInit = true;
this._eval_initial(vlSymsp);
vlSymsp.__Vm_activity = true;
var __VclockLoop = 0;
var __Vchange=1;
while (__Vchange) {
this._eval_settle(vlSymsp);
this._eval(vlSymsp);
__Vchange = this._change_request(vlSymsp);
if (++__VclockLoop > 100) { this.vl_fatal("Verilated model didn't DC converge"); }
}
}
}
*/
//# sourceMappingURL=hdlruntime.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isArrayItem = exports.isFuncCall = exports.isBlock = exports.isWhileop = exports.isTriop = exports.isBinop = exports.isUnop = exports.isVarRef = exports.isBigConstExpr = exports.isConstExpr = exports.isVarDecl = exports.hasDataType = exports.HDLFile = exports.isArrayType = exports.isLogicType = void 0;
function isLogicType(arg) {
return typeof arg.left === 'number' && typeof arg.right === 'number';
}
exports.isLogicType = isLogicType;
function isArrayType(arg) {
return arg.subtype != null && arg.low != null && arg.high != null
&& typeof arg.low.cvalue === 'number' && typeof arg.high.cvalue === 'number';
}
exports.isArrayType = isArrayType;
class HDLFile {
}
exports.HDLFile = HDLFile;
function hasDataType(arg) {
return typeof arg.dtype === 'object';
}
exports.hasDataType = hasDataType;
function isVarDecl(arg) {
return typeof arg.isParam !== 'undefined';
}
exports.isVarDecl = isVarDecl;
function isConstExpr(arg) {
return typeof arg.cvalue === 'number';
}
exports.isConstExpr = isConstExpr;
function isBigConstExpr(arg) {
return typeof arg.bigvalue === 'bigint';
}
exports.isBigConstExpr = isBigConstExpr;
function isVarRef(arg) {
return arg.refname != null;
}
exports.isVarRef = isVarRef;
function isUnop(arg) {
return arg.op != null && arg.left != null && arg.right == null;
}
exports.isUnop = isUnop;
function isBinop(arg) {
return arg.op != null && arg.left != null && arg.right != null && arg.cond == null;
}
exports.isBinop = isBinop;
function isTriop(arg) {
return arg.op != null && arg.cond != null;
}
exports.isTriop = isTriop;
function isWhileop(arg) {
return arg.op === 'while' && arg.loopcond != null;
}
exports.isWhileop = isWhileop;
function isBlock(arg) {
return arg.blocktype != null;
}
exports.isBlock = isBlock;
function isFuncCall(arg) {
return typeof arg.funcname === 'string';
}
exports.isFuncCall = isFuncCall;
function isArrayItem(arg) {
return typeof arg.index === 'number' && arg.expr != null;
}
exports.isArrayItem = isArrayItem;
//# sourceMappingURL=hdltypes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"hdltypes.js","sourceRoot":"","sources":["../../../src/common/hdl/hdltypes.ts"],"names":[],"mappings":";;;AA2CA,SAAgB,WAAW,CAAC,GAAO;IAC/B,OAAO,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC;AACzE,CAAC;AAFD,kCAEC;AAED,SAAgB,WAAW,CAAC,GAAO;IAC/B,OAAO,GAAG,CAAC,OAAO,IAAI,IAAI,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI;WAC5D,OAAO,GAAG,CAAC,GAAG,CAAC,MAA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BAEC;AAUD,SAAgB,SAAS,CAAC,GAAO;IAC7B,OAAO,GAAG,CAAC,EAAE,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC;AACtD,CAAC;AAFD,8BAEC;AAQD,SAAgB,OAAO,CAAC,GAAO;IAC3B,OAAO,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC;AACjC,CAAC;AAFD,0BAEC;AAqBD,SAAgB,UAAU,CAAC,GAAO;IAC9B,OAAO,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC5C,CAAC;AAFD,gCAEC;AAOD,SAAgB,WAAW,CAAC,GAAO;IAC/B,OAAO,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;AAC7D,CAAC;AAFD,kCAEC"}

1166
gen/common/hdl/hdlwasm.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,624 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerilogXMLParser = exports.CompileError = void 0;
const util_1 = require("../util");
const hdltypes_1 = require("./hdltypes");
/**
* Whaa?
*
* Each hierarchy takes (uint32[] -> uint32[])
* - convert to/from js object
* - JS or WASM
* - Fixed-size packets
* - state is another uint32[]
* Find optimal packing of bits
* Find clocks
* Find pivots (reset, state) concat them together
* Dependency cycles
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
*/
class CompileError extends Error {
constructor($loc, msg) {
super(msg);
this.$loc = $loc;
Object.setPrototypeOf(this, CompileError.prototype);
}
}
exports.CompileError = CompileError;
class VerilogXMLParser {
constructor() {
this.files = {};
this.dtypes = {};
this.modules = {};
this.hierarchies = {};
this.cur_deferred = [];
// TODO: other types?
this.dtypes['QData'] = { left: 63, right: 0, signed: false };
this.dtypes['IData'] = { left: 31, right: 0, signed: false };
this.dtypes['SData'] = { left: 15, right: 0, signed: false };
this.dtypes['CData'] = { left: 7, right: 0, signed: false };
this.dtypes['byte'] = { left: 7, right: 0, signed: true };
this.dtypes['shortint'] = { left: 15, right: 0, signed: true };
this.dtypes['int'] = { left: 31, right: 0, signed: true };
this.dtypes['integer'] = { left: 31, right: 0, signed: true };
this.dtypes['longint'] = { left: 63, right: 0, signed: true };
this.dtypes['time'] = { left: 63, right: 0, signed: false };
}
defer(fn) {
this.cur_deferred.unshift(fn);
}
defer2(fn) {
this.cur_deferred.push(fn);
}
run_deferred() {
this.cur_deferred.forEach((fn) => fn());
this.cur_deferred = [];
}
name2js(s) {
if (s == null)
throw new CompileError(this.cur_loc, `no name`);
return s.replace(/[^a-z0-9_]/gi, '$');
}
findChildren(node, type, required) {
var arr = node.children.filter((n) => n.type == type);
if (arr.length == 0 && required)
throw new CompileError(this.cur_loc, `no child of type ${type}`);
return arr;
}
parseSourceLocation(node) {
var loc = node.attrs['loc'];
if (loc) {
if (loc == this.cur_loc_str) {
return this.cur_loc; // cache last parsed $loc object
}
else {
var [fileid, line, col, end_line, end_col] = loc.split(',');
var $loc = {
hdlfile: this.files[fileid],
path: this.files[fileid].filename,
line: parseInt(line),
start: parseInt(col) - 1,
end_line: parseInt(end_line),
end: parseInt(end_col) - 1,
};
this.cur_loc = $loc;
this.cur_loc_str = loc;
return $loc;
}
}
else {
return null;
}
}
open_module(node) {
var module = {
$loc: this.parseSourceLocation(node),
name: node.attrs['name'],
origName: node.attrs['origName'],
blocks: [],
instances: [],
vardefs: {},
};
if (this.cur_module)
throw new CompileError(this.cur_loc, `nested modules not supported`);
this.cur_module = module;
return module;
}
deferDataType(node, def) {
var dtype_id = node.attrs['dtype_id'];
if (dtype_id != null) {
this.defer(() => {
def.dtype = this.dtypes[dtype_id];
if (!def.dtype) {
throw new CompileError(this.cur_loc, `Unknown data type ${dtype_id} for ${node.type}`);
}
});
}
}
parseConstValue(s) {
const re_const = /(\d+)'([s]?)h([0-9a-f]+)/i;
var m = re_const.exec(s);
if (m) {
var numstr = m[3];
if (numstr.length <= 8)
return parseInt(numstr, 16);
else
return BigInt('0x' + numstr);
}
else {
throw new CompileError(this.cur_loc, `could not parse constant "${s}"`);
}
}
resolveVar(s, mod) {
var def = mod.vardefs[s];
if (def == null)
throw new CompileError(this.cur_loc, `could not resolve variable "${s}"`);
return def;
}
resolveModule(s) {
var mod = this.modules[s];
if (mod == null)
throw new CompileError(this.cur_loc, `could not resolve module "${s}"`);
return mod;
}
//
visit_verilator_xml(node) {
}
visit_package(node) {
}
visit_module(node) {
this.findChildren(node, 'var', false).forEach((n) => {
if ((0, hdltypes_1.isVarDecl)(n.obj)) {
this.cur_module.vardefs[n.obj.name] = n.obj;
}
});
this.modules[this.cur_module.name] = this.cur_module;
this.cur_module = null;
}
visit_var(node) {
var name = node.attrs['name'];
name = this.name2js(name);
var vardef = {
$loc: this.parseSourceLocation(node),
name: name,
origName: node.attrs['origName'],
isInput: node.attrs['dir'] == 'input',
isOutput: node.attrs['dir'] == 'output',
isParam: node.attrs['param'] == 'true',
dtype: null,
};
this.deferDataType(node, vardef);
var const_nodes = this.findChildren(node, 'const', false);
if (const_nodes.length) {
vardef.constValue = const_nodes[0].obj;
}
var init_nodes = this.findChildren(node, 'initarray', false);
if (init_nodes.length) {
vardef.initValue = init_nodes[0].obj;
}
return vardef;
}
visit_const(node) {
var name = node.attrs['name'];
var cvalue = this.parseConstValue(name);
var constdef = {
$loc: this.parseSourceLocation(node),
dtype: null,
cvalue: typeof cvalue === 'number' ? cvalue : null,
bigvalue: typeof cvalue === 'bigint' ? cvalue : null,
};
this.deferDataType(node, constdef);
return constdef;
}
visit_varref(node) {
var name = node.attrs['name'];
name = this.name2js(name);
var varref = {
$loc: this.parseSourceLocation(node),
dtype: null,
refname: name
};
this.deferDataType(node, varref);
var mod = this.cur_module;
/*
this.defer2(() => {
varref.vardef = this.resolveVar(name, mod);
});
*/
return varref;
}
visit_sentree(node) {
// TODO
}
visit_always(node) {
// TODO
var sentree;
var expr;
if (node.children.length == 2) {
sentree = node.children[0].obj;
expr = node.children[1].obj;
// TODO: check sentree
}
else {
sentree = null;
expr = node.children[0].obj;
}
var always = {
$loc: this.parseSourceLocation(node),
blocktype: node.type,
name: null,
senlist: sentree,
exprs: [expr],
};
this.cur_module.blocks.push(always);
return always;
}
visit_begin(node) {
var exprs = [];
node.children.forEach((n) => exprs.push(n.obj));
return {
$loc: this.parseSourceLocation(node),
blocktype: node.type,
name: node.attrs['name'],
exprs: exprs,
};
}
visit_initarray(node) {
return this.visit_begin(node);
}
visit_inititem(node) {
this.expectChildren(node, 1, 1);
return {
index: parseInt(node.attrs['index']),
expr: node.children[0].obj
};
}
visit_cfunc(node) {
if (this.cur_module == null) { // TODO?
//console.log('no module open, skipping', node);
return;
}
var block = this.visit_begin(node);
block.exprs = [];
node.children.forEach((n) => block.exprs.push(n.obj));
this.cur_module.blocks.push(block);
return block;
}
visit_cuse(node) {
}
visit_instance(node) {
var instance = {
$loc: this.parseSourceLocation(node),
name: node.attrs['name'],
origName: node.attrs['origName'],
ports: [],
module: null,
};
node.children.forEach((child) => {
instance.ports.push(child.obj);
});
this.cur_module.instances.push(instance);
this.defer(() => {
instance.module = this.resolveModule(node.attrs['defName']);
});
return instance;
}
visit_iface(node) {
throw new CompileError(this.cur_loc, `interfaces not supported`);
}
visit_intfref(node) {
throw new CompileError(this.cur_loc, `interfaces not supported`);
}
visit_port(node) {
this.expectChildren(node, 1, 1);
var varref = {
$loc: this.parseSourceLocation(node),
name: node.attrs['name'],
expr: node.children[0].obj
};
return varref;
}
visit_netlist(node) {
}
visit_files(node) {
}
visit_module_files(node) {
node.children.forEach((n) => {
if (n.obj) {
var file = this.files[n.obj.id];
if (file)
file.isModule = true;
}
});
}
visit_file(node) {
return this.visit_file_or_module(node, false);
}
// TODO
visit_scope(node) {
}
visit_topscope(node) {
}
visit_file_or_module(node, isModule) {
var file = {
id: node.attrs['id'],
filename: node.attrs['filename'],
isModule: isModule,
};
this.files[file.id] = file;
return file;
}
visit_cells(node) {
this.expectChildren(node, 1, 9999);
var hier = node.children[0].obj;
if (hier != null) {
var hiername = hier.name;
this.hierarchies[hiername] = hier;
}
}
visit_cell(node) {
var hier = {
$loc: this.parseSourceLocation(node),
name: node.attrs['name'],
module: null,
parent: null,
children: node.children.map((n) => n.obj),
};
if (node.children.length > 0)
throw new CompileError(this.cur_loc, `multiple non-flattened modules not yet supported`);
node.children.forEach((n) => n.obj.parent = hier);
this.defer(() => {
hier.module = this.resolveModule(node.attrs['submodname']);
});
return hier;
}
visit_basicdtype(node) {
let id = node.attrs['id'];
var dtype;
var dtypename = node.attrs['name'];
switch (dtypename) {
case 'logic':
case 'integer': // TODO?
case 'bit':
let dlogic = {
$loc: this.parseSourceLocation(node),
left: parseInt(node.attrs['left'] || "0"),
right: parseInt(node.attrs['right'] || "0"),
signed: node.attrs['signed'] == 'true'
};
dtype = dlogic;
break;
case 'string':
let dstring = {
$loc: this.parseSourceLocation(node),
jstype: 'string'
};
dtype = dstring;
break;
default:
dtype = this.dtypes[dtypename];
if (dtype == null) {
throw new CompileError(this.cur_loc, `unknown data type ${dtypename}`);
}
}
this.dtypes[id] = dtype;
return dtype;
}
visit_refdtype(node) {
}
visit_enumdtype(node) {
}
visit_enumitem(node) {
}
visit_packarraydtype(node) {
// TODO: packed?
return this.visit_unpackarraydtype(node);
}
visit_memberdtype(node) {
throw new CompileError(null, `structs not supported`);
}
visit_constdtype(node) {
// TODO? throw new CompileError(null, `constant data types not supported`);
}
visit_paramtypedtype(node) {
// TODO? throw new CompileError(null, `constant data types not supported`);
}
visit_unpackarraydtype(node) {
let id = node.attrs['id'];
let sub_dtype_id = node.attrs['sub_dtype_id'];
let range = node.children[0].obj;
if ((0, hdltypes_1.isConstExpr)(range.left) && (0, hdltypes_1.isConstExpr)(range.right)) {
var dtype = {
$loc: this.parseSourceLocation(node),
subtype: null,
low: range.left,
high: range.right,
};
this.dtypes[id] = dtype;
this.defer(() => {
dtype.subtype = this.dtypes[sub_dtype_id];
if (!dtype.subtype)
throw new CompileError(this.cur_loc, `Unknown data type ${sub_dtype_id} for array`);
});
return dtype;
}
else {
throw new CompileError(this.cur_loc, `could not parse constant exprs in array`);
}
}
visit_senitem(node) {
var edgeType = node.attrs['edgeType'];
if (edgeType != "POS" && edgeType != "NEG")
throw new CompileError(this.cur_loc, "POS/NEG required");
return {
$loc: this.parseSourceLocation(node),
edgeType: edgeType,
expr: node.obj
};
}
visit_text(node) {
}
visit_cstmt(node) {
}
visit_cfile(node) {
}
visit_typetable(node) {
}
visit_constpool(node) {
}
visit_comment(node) {
}
expectChildren(node, low, high) {
if (node.children.length < low || node.children.length > high)
throw new CompileError(this.cur_loc, `expected between ${low} and ${high} children`);
}
__visit_unop(node) {
this.expectChildren(node, 1, 1);
var expr = {
$loc: this.parseSourceLocation(node),
op: node.type,
dtype: null,
left: node.children[0].obj,
};
this.deferDataType(node, expr);
return expr;
}
visit_extend(node) {
var unop = this.__visit_unop(node);
unop.width = parseInt(node.attrs['width']);
unop.widthminv = parseInt(node.attrs['widthminv']);
if (unop.width != 32)
throw new CompileError(this.cur_loc, `extends width ${unop.width} != 32`);
return unop;
}
visit_extends(node) {
return this.visit_extend(node);
}
__visit_binop(node) {
this.expectChildren(node, 2, 2);
var expr = {
$loc: this.parseSourceLocation(node),
op: node.type,
dtype: null,
left: node.children[0].obj,
right: node.children[1].obj,
};
this.deferDataType(node, expr);
return expr;
}
visit_if(node) {
this.expectChildren(node, 2, 3);
var expr = {
$loc: this.parseSourceLocation(node),
op: 'if',
dtype: null,
cond: node.children[0].obj,
left: node.children[1].obj,
right: node.children[2] && node.children[2].obj,
};
return expr;
}
// while and for loops
visit_while(node) {
this.expectChildren(node, 2, 4);
var expr = {
$loc: this.parseSourceLocation(node),
op: 'while',
dtype: null,
precond: node.children[0].obj,
loopcond: node.children[1].obj,
body: node.children[2] && node.children[2].obj,
inc: node.children[3] && node.children[3].obj,
};
return expr;
}
__visit_triop(node) {
this.expectChildren(node, 3, 3);
var expr = {
$loc: this.parseSourceLocation(node),
op: node.type,
dtype: null,
cond: node.children[0].obj,
left: node.children[1].obj,
right: node.children[2].obj,
};
this.deferDataType(node, expr);
return expr;
}
__visit_func(node) {
var expr = {
$loc: this.parseSourceLocation(node),
dtype: null,
funcname: node.attrs['func'] || ('$' + node.type),
args: node.children.map(n => n.obj)
};
this.deferDataType(node, expr);
return expr;
}
visit_not(node) { return this.__visit_unop(node); }
visit_negate(node) { return this.__visit_unop(node); }
visit_redand(node) { return this.__visit_unop(node); }
visit_redor(node) { return this.__visit_unop(node); }
visit_redxor(node) { return this.__visit_unop(node); }
visit_initial(node) { return this.__visit_unop(node); }
visit_ccast(node) { return this.__visit_unop(node); }
visit_creset(node) { return this.__visit_unop(node); }
visit_creturn(node) { return this.__visit_unop(node); }
visit_contassign(node) { return this.__visit_binop(node); }
visit_assigndly(node) { return this.__visit_binop(node); }
visit_assignpre(node) { return this.__visit_binop(node); }
visit_assignpost(node) { return this.__visit_binop(node); }
visit_assign(node) { return this.__visit_binop(node); }
visit_arraysel(node) { return this.__visit_binop(node); }
visit_wordsel(node) { return this.__visit_binop(node); }
visit_eq(node) { return this.__visit_binop(node); }
visit_neq(node) { return this.__visit_binop(node); }
visit_lte(node) { return this.__visit_binop(node); }
visit_gte(node) { return this.__visit_binop(node); }
visit_lt(node) { return this.__visit_binop(node); }
visit_gt(node) { return this.__visit_binop(node); }
visit_and(node) { return this.__visit_binop(node); }
visit_or(node) { return this.__visit_binop(node); }
visit_xor(node) { return this.__visit_binop(node); }
visit_add(node) { return this.__visit_binop(node); }
visit_sub(node) { return this.__visit_binop(node); }
visit_concat(node) { return this.__visit_binop(node); } // TODO?
visit_shiftl(node) { return this.__visit_binop(node); }
visit_shiftr(node) { return this.__visit_binop(node); }
visit_shiftrs(node) { return this.__visit_binop(node); }
visit_mul(node) { return this.__visit_binop(node); }
visit_div(node) { return this.__visit_binop(node); }
visit_moddiv(node) { return this.__visit_binop(node); }
visit_muls(node) { return this.__visit_binop(node); }
visit_divs(node) { return this.__visit_binop(node); }
visit_moddivs(node) { return this.__visit_binop(node); }
visit_gts(node) { return this.__visit_binop(node); }
visit_lts(node) { return this.__visit_binop(node); }
visit_gtes(node) { return this.__visit_binop(node); }
visit_ltes(node) { return this.__visit_binop(node); }
// TODO: more?
visit_range(node) { return this.__visit_binop(node); }
visit_cond(node) { return this.__visit_triop(node); }
visit_condbound(node) { return this.__visit_triop(node); }
visit_sel(node) { return this.__visit_triop(node); }
visit_changedet(node) {
if (node.children.length == 0)
return null; //{ op: "changedet", dtype:null, left:null, right:null }
else
return this.__visit_binop(node);
}
visit_ccall(node) { return this.__visit_func(node); }
visit_finish(node) { return this.__visit_func(node); }
visit_stop(node) { return this.__visit_func(node); }
visit_rand(node) { return this.__visit_func(node); }
visit_time(node) { return this.__visit_func(node); }
visit_display(node) { return null; }
visit_sformatf(node) { return null; }
visit_scopename(node) { return null; }
visit_readmem(node) { return this.__visit_func(node); }
//
xml_open(node) {
this.cur_node = node;
var method = this[`open_${node.type}`];
if (method) {
return method.bind(this)(node);
}
}
xml_close(node) {
this.cur_node = node;
var method = this[`visit_${node.type}`];
if (method) {
return method.bind(this)(node);
}
else {
throw new CompileError(this.cur_loc, `no visitor for ${node.type}`);
}
}
parse(xmls) {
(0, util_1.parseXMLPoorly)(xmls, this.xml_open.bind(this), this.xml_close.bind(this));
this.cur_node = null;
this.run_deferred();
}
}
exports.VerilogXMLParser = VerilogXMLParser;
//# sourceMappingURL=vxmlparser.js.map

File diff suppressed because one or more lines are too long

112
gen/common/hdl/vxmltest.js Normal file
View File

@@ -0,0 +1,112 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("../util");
const hdlruntime_1 = require("./hdlruntime");
const hdlwasm_1 = require("./hdlwasm");
const vxmlparser_1 = require("./vxmlparser");
var fs = require('fs');
var xmltxt = fs.readFileSync(process.argv[2], 'utf8');
var parser = new vxmlparser_1.VerilogXMLParser();
try {
parser.parse(xmltxt);
}
catch (e) {
console.log(parser.cur_node);
throw e;
}
//console.log(parser);
var modname = 'TOP'; //process.argv[3];
async function testWASM() {
var bmod = new hdlwasm_1.HDLModuleWASM(parser.modules[modname], parser.modules['@CONST-POOL@']);
await bmod.init();
bmod.powercycle();
//console.log(this.globals);
bmod.state.reset = 1;
for (var i = 0; i < 10; i++) {
bmod.tick2(1);
if (i == 5)
bmod.state.reset = 0;
bmod.nextTrace();
}
console.log(bmod.databuf);
var t1 = new Date().getTime();
var tickiters = 10000;
var looplen = Math.round(100000000 / tickiters);
for (var i = 0; i < looplen; i++) {
bmod.tick2(tickiters);
}
var t2 = new Date().getTime();
console.log('wasm:', t2 - t1, 'msec', i * tickiters, 'iterations');
console.log(bmod.databuf);
}
async function testJS() {
var mod = new hdlruntime_1.HDLModuleJS(parser.modules[modname], parser.modules['@CONST-POOL@']);
mod.init();
console.log(mod.getJSCode());
mod.powercycle();
var t1 = new Date().getTime();
for (var i = 0; i < 100000000; i++) {
mod.tick2(1);
}
mod.state.reset = 1;
for (var j = 0; j < 10000000; j++) {
mod.tick2(1);
}
var t2 = new Date().getTime();
console.log(mod.state);
console.log('js:', t2 - t1, 'msec', i, 'iterations', i / 1000 / (t2 - t1), 'MHz');
//console.log(emitter);
}
async function testJSvsWASM() {
const top = parser.modules[modname];
const constpool = parser.modules['@CONST-POOL@'];
var jmod = new hdlruntime_1.HDLModuleJS(top, constpool);
jmod.init();
jmod.powercycle();
var bmod = new hdlwasm_1.HDLModuleWASM(top, constpool);
await bmod.init();
bmod.powercycle();
var varnames = Object.keys(top.vardefs);
var exit = false;
for (var i = 0; i < 100000000; i++) {
for (var vname of varnames) {
var jvalue = jmod.state[vname];
var bvalue = bmod.state[vname];
if (typeof jvalue === 'number') {
if (jvalue != bvalue) {
console.log('*** Value for', vname, 'differs', jvalue, bvalue);
exit = true;
}
}
else if (jvalue.buffer != null) {
if (!(0, util_1.arrayCompare)(jvalue, bvalue)) {
console.log('*** Value for', vname, 'differs', jvalue, bvalue);
exit = true;
}
}
}
if (jmod.isFinished() || bmod.isFinished()) {
if (jmod.isFinished() != bmod.isFinished()) {
console.log('*** Abnormal finish', jmod.isFinished(), bmod.isFinished());
}
exit = true;
}
if (jmod.isStopped() || bmod.isStopped()) {
if (jmod.isStopped() != bmod.isStopped()) {
console.log('*** Abnormal stop', jmod.isStopped(), bmod.isStopped());
}
exit = true;
}
if (exit) {
console.log('exit iteration', i);
break;
}
jmod.tick2(1);
bmod.tick2(1);
}
}
//testJS();
testWASM();
//testJSvsWASM();
//testWASM().then(testJS).then(testJSvsWASM);
//# sourceMappingURL=vxmltest.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"vxmltest.js","sourceRoot":"","sources":["../../../src/common/hdl/vxmltest.ts"],"names":[],"mappings":";;AACA,kCAAuC;AACvC,6CAA2C;AAC3C,uCAA0C;AAC1C,6CAAgD;AAEhD,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,IAAI,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACtD,IAAI,MAAM,GAAG,IAAI,6BAAgB,EAAE,CAAC;AACpC,IAAI;IACA,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB;AAAC,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7B,MAAM,CAAC,CAAC;CACX;AACD,sBAAsB;AACtB,IAAI,OAAO,GAAG,KAAK,CAAC,CAAC,kBAAkB;AAEvC,KAAK,UAAU,QAAQ;IACnB,IAAI,IAAI,GAAG,IAAI,uBAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;IACtF,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IAClB,IAAI,CAAC,UAAU,EAAE,CAAC;IAClB,4BAA4B;IAC5B,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