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) {
if (!args.bits) args.bits = 1;
if (!args.abits) args.abits = 1;
if (!args.rdports) args.rdports = [];
if (!args.wrports) args.wrports = [];
if (!args.words) args.words = 1 << args.abits;
if (!args.offset) args.offset = 0;
if (args.memdata)
this.memdata = Mem3vl.fromJSON(args.bits, args.memdata);
else
this.memdata = new Mem3vl(args.bits, args.words);
delete args.memdata; // performance hack
console.assert(this.memdata.words == args.words);
this.last_clk = {};
const markup = [];
const lblmarkup = [];
let num = 0;
const portsplits = [];
function num_y(num) { return num * 16 + 12; }
for (const [pnum, port] of args.rdports.entries()) {
const portname = "rd" + pnum;
markup.push(this.addLabelledWire(args, lblmarkup, 'right', num_y(num), { id: portname + 'data', dir: 'out', bits: args.bits, label: 'data' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'addr', dir: 'in', bits: args.abits, label: 'addr' }));
if ('enable_polarity' in port)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'en', dir: 'in', bits: 1, label: 'en', polarity: port.enable_polarity }));
if ('clock_polarity' in port) {
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'clk', dir: 'in', bits: 1, label: 'clk', polarity: port.clock_polarity, clock: true }));
constructor: function(args) {
if (!args.bits) args.bits = 1;
if (!args.abits) args.abits = 1;
if (!args.rdports) args.rdports = [];
if (!args.wrports) args.wrports = [];
if (!args.words) args.words = 1 << args.abits;
if (!args.offset) args.offset = 0;
if (args.memdata)
this.memdata = Mem3vl.fromJSON(args.bits, args.memdata);
else
this.memdata = new Mem3vl(args.bits, args.words);
delete args.memdata; // performance hack
console.assert(this.memdata.words == args.words);
this.last_clk = {};
const markup = [];
const lblmarkup = [];
let num = 0;
const portsplits = [];
function num_y(num) { return num * 16 + 12; }
for (const [pnum, port] of args.rdports.entries()) {
const portname = "rd" + pnum;
markup.push(this.addLabelledWire(args, lblmarkup, 'right', num_y(num), { id: portname + 'data', dir: 'out', bits: args.bits, label: 'data' }));
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'addr', dir: 'in', bits: args.abits, label: 'addr' }));
if ('enable_polarity' in port)
markup.push(this.addLabelledWire(args, lblmarkup, 'left', num_y(num++), { id: portname + 'en', dir: 'in', bits: 1, label: 'en', polarity: port.enable_polarity }));
const settext = () => {
this.attr('text.value/text', help.sig2base(this.get('inputSignals').in, this.get('numbase')));
}
settext();
this.listenTo(this, 'change:inputSignals', settext);
this.listenTo(this, 'change:numbase', settext);
},
gateParams: NumBase.prototype.gateParams.concat(['bits'])
});
export const NumDisplayView = NumBaseView;
// Numeric entry -- parses a number from a text box
export const NumEntry = NumBase.define('NumEntry', {
bits: 1,
propagation: 0,
buttonState: Vector3vl.xes(1),
attrs: {
'.body': { fill: 'white', stroke: 'black', 'stroke-width': 2 },
'foreignObject.valinput': {
'ref-x': 5, 'ref-y': 0,
width: 60, height: 30
}
}
}, {
initialize: function(args) {
this.listenTo(this, 'change:size', (x, size) => {
this.attr('foreignObject.valinput/width', size.width - 10)
});
NumBase.prototype.initialize.apply(this, arguments);
},
constructor: function(args) {
if (!args.bits) args.bits = 1;
}
},
render() {
joint.dia.ElementView.prototype.render.apply(this, arguments);
this.updatePortSignals('in', this.model.get('inputSignals'));
this.updatePortSignals('out', this.model.get('outputSignals'));
}
});
// Connecting wire model
export const Wire = joint.dia.Link.define('Wire', {
attrs: {
'.connection': { 'stroke-width': 2 },
'.marker-vertex': { r: 7 }
},
signal: Vector3vl.xes(1),
bits: 1,
router: { name: 'orthogonal' },
connector: { name: 'rounded', args: { radius: 10 }}
}, {
markup: [
'
} else {
bits_args['ref-y'] = -3;
bits_args['text-anchor'] = 'middle';
}
if (side == 'left') {
bits_args['ref-dx'] = 6;
} else if (side == 'right') {
bits_args['ref-x'] = -6;
} else if (side == 'top') {
bits_args['ref-y'] = 6;
} else console.assert(false);
_.set(args, ['attrs', 'text.bits.port_' + port.id], bits_args);
}
const signame = port.dir == 'in' ? 'inputSignals' : 'outputSignals';
if (_.get(args, [signame, port.id]) === undefined) {
_.set(args, [signame, port.id], Vector3vl.xes(port.bits));
}
return '';
},
getGateParams: function() {
operation: function(data) {
const ex = this.get('extend');
return { out: data.in.concat(Vector3vl.make(ex.output - ex.input, this.extbit(data.in))) };
},
gateParams: Gate.prototype.gateParams.concat(['extend'])
};
const pol = what => polarity[what] ? 1 : -1;
if (data.arst.get(0) == pol('arst')) {
this.set('current_state', this.get('init_state'));
} else {
const last_clk = this.last_clk;
this.last_clk = data.clk.get(0);
if (data.clk.get(0) == pol('clock') && last_clk == -pol('clock')) {
const trans = next_trans();
this.set('current_state',
trans ? trans.getTargetElement().get('stateNo') : this.get('init_state'));
}
}
const trans = next_trans();
this.set('next_trans', trans.id);
if (!trans) return { out: Vector3vl.xes(bits.out) };
else return { out: trans.get('ctrlOut') };
}
});
function clearInput(end, gate) {
setInput(Vector3vl.xes(gate.ports[end.port].bits), end, gate);
}
this.listenTo(graph, 'change:target', function(wire, end) {
const do_read = (portname, port) => {
if (!check_enabled(portname, port)) {
if ('clock_polarity' in port)
out[portname + 'data'] = this.get('outputSignals')[portname + 'data'];
else
out[portname + 'data'] = Vector3vl.xes(this.get('bits'));
return;
}
if (!data[portname + 'addr'].isFullyDefined)
out[portname + 'data'] = Vector3vl.xes(this.get('bits'));
else {
const addr = calc_addr(data[portname + 'addr']);
if (valid_addr(addr))
out[portname + 'data'] = this.memdata.get(addr);
else
out[portname + 'data'] = Vector3vl.xes(this.get('bits'));
}
};
const do_write = (portname, port) => {
operation: function(data) {
const i = this.muxInput(data.sel);
if (i === undefined) return { out: Vector3vl.xes(this.get('bits').in) };
return { out: data['in' + i] };
},
gateParams: Gate.prototype.gateParams.concat(['bits'])