Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor: function(args) {
args.constantCache = Vector3vl.fromBin(args.constant, args.constant.length);
args.bits = args.constant.length;
args.outputSignals = { out: args.constantCache };
this.markup = [
this.addWire(args, 'right', 0.5, { id: 'out', dir: 'out', bits: args.constant.length }),
'
'<a class="zoom">🔍</a>',
''].join(''));
this.markup = markup.join('');
this.fsmgraph = new joint.dia.Graph;
const statenodes = [];
for (let n = 0; n < args.states; n++) {
const node = new joint.shapes.standard.Circle({stateNo: n, id: 'state' + n, isInit: n == args.init_state});
node.attr('label/text', String(n));
node.resize(100,50);
node.addTo(this.fsmgraph);
statenodes.push(node);
}
for (const tr of args.trans_table) {
const trans = new joint.shapes.standard.Link({
ctrlIn: Vector3vl.fromBin(tr.ctrl_in, args.bits.in),
ctrlOut: Vector3vl.fromBin(tr.ctrl_out, args.bits.out)
});
trans.appendLabel({
attrs: {
text: {
text: trans.get('ctrlIn').toBin() + '/' + trans.get('ctrlOut').toBin()
}
}
});
trans.source({ id: 'state' + tr.state_in });
trans.target({ id: 'state' + tr.state_out });
trans.addTo(this.fsmgraph);
}
Box.prototype.constructor.apply(this, arguments);
this.last_clk = 0;
},
operation: function(data) {
export function base2sig(str, bits, base) {
switch(base) {
case 'bin': return Vector3vl.fromBin(str, bits);
case 'oct': return Vector3vl.fromOct(str, bits);
case 'hex': return Vector3vl.fromHex(str, bits);
case 'dec':
if (str == 'x') return Vector3vl.xes(bits);
return bigint2sig(bigInt(str), bits);
}
}
operation: function(data) {
const polarity = this.get('polarity');
const pol = what => polarity[what] ? 1 : -1
if ('enable' in polarity && data.en.get(0) != pol('enable'))
return this.get('outputSignals');
if ('arst' in polarity && data.arst.get(0) == pol('arst'))
return { out: Vector3vl.fromBin(this.get('arst_value'), this.get('bits')) };
if ('clock' in polarity) {
const last_clk = this.last_clk;
this.last_clk = data.clk.get(0);
if (data.clk.get(0) == pol('clock') && last_clk == -pol('clock'))
return { out: data.in };
else
return this.get('outputSignals');
} else return { out: data.in };
},
gateParams: Box.prototype.gateParams.concat(['polarity', 'bits'])
'',
'<a class="zoom">🔍</a>',
''].join(''));
this.markup = markup.join('');
this.fsmgraph = new joint.dia.Graph;
const statenodes = [];
for (let n = 0; n < args.states; n++) {
const node = new joint.shapes.standard.Circle({stateNo: n, id: 'state' + n, isInit: n == args.init_state});
node.attr('label/text', String(n));
node.resize(100,50);
node.addTo(this.fsmgraph);
statenodes.push(node);
}
for (const tr of args.trans_table) {
const trans = new joint.shapes.standard.Link({
ctrlIn: Vector3vl.fromBin(tr.ctrl_in, args.bits.in),
ctrlOut: Vector3vl.fromBin(tr.ctrl_out, args.bits.out)
});
trans.appendLabel({
attrs: {
text: {
text: trans.get('ctrlIn').toBin() + '/' + trans.get('ctrlOut').toBin()
}
}
});
trans.source({ id: 'state' + tr.state_in });
trans.target({ id: 'state' + tr.state_out });
trans.addTo(this.fsmgraph);
}
Box.prototype.constructor.apply(this, arguments);
this.last_clk = 0;
},
constructor: function(args) {
_.defaults(args, { bits: 1, polarity: {}, initial: 'x' });
if (!args.outputSignals)
args.outputSignals = {
out: Vector3vl.fromBin(args.initial, args.bits)
};
if ('arst' in args.polarity && !args.arst_value)
args.arst_value = Array(args.bits).fill('0').join('');
const markup = [];
const lblmarkup = [];
markup.push(this.addLabelledWire(args, lblmarkup, 'right', 0.5, { id: 'out', dir: 'out', bits: args.bits, label: 'Q' }));
let num = 0;
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'in', dir: 'in', bits: args.bits, label: 'D' }));
if ('clock' in args.polarity)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'clk', dir: 'in', bits: 1, polarity: args.polarity.clock, clock: true }));
if ('arst' in args.polarity)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'arst', dir: 'in', bits: 1, polarity: args.polarity.arst }));
if ('enable' in args.polarity)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'en', dir: 'in', bits: 1, polarity: args.polarity.enable }));
markup.push('