Skip to content

Commit 71f4e0c

Browse files
yuyichaotilk
authored andcommitted
Save IO orders
This is used in layout. Without saving this, the restored layout won't match the original one since the port position on a subcircuit might have changed. This happens with the `dff_masterslave.sv` example.
1 parent 69e40c6 commit 71f4e0c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/cells/io.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const IO = NumBase.define('IO', {
155155
selector: 'ioname'
156156
}
157157
]),
158-
_gateParams: NumBase.prototype._gateParams.concat(['bits','net'])
158+
_gateParams: NumBase.prototype._gateParams.concat(['bits','net','order'])
159159
});
160160
export const IOView = NumBaseView.extend({
161161
_calculateBoxWidth() {

tests/index.test.mjs

+37-1
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ class CircuitTestFixture {
122122
if (totbits <= 6) return this.testFunComplete(fun, opts);
123123
else return this.testFunRandomized(fun, opts);
124124
}
125-
testJSON() {
125+
testJSON(json) {
126126
test("serialization test", async () => {
127127
let json1 = this.circuit.toJSON();
128128
// Make sure the object can be serialized as JSON
129129
let jsonstr1 = JSON.stringify(json1);
130+
if (json)
131+
expect(json1).toMatchObject(json);
130132
// Test round trip
131133
let circuit2 = new HeadlessCircuit(JSON.parse(jsonstr1));
132134
let json2 = circuit2.toJSON();
@@ -743,6 +745,40 @@ describe('$fsm', () => {
743745
});
744746
});
745747

748+
describe('order', () => {
749+
// A circuit with order parameters on the ports
750+
const circuit = {
751+
subcircuits: {
752+
sub_mod: {
753+
devices: {
754+
dev0: { type: "Input", net: "in1", order: 0, bits: 1 },
755+
dev1: { type: "Input", net: "in2", order: 1, bits: 1 },
756+
dev2: { type: "Output", net: "out1", order: 2, bits: 1 },
757+
dev3: { type: "Output", net: "out2", order: 3, bits: 1 }
758+
},
759+
connectors: []
760+
}
761+
},
762+
devices: {
763+
dev0: { type: "Button", net: "in1", order: 0, bits: 1, label: "in1" },
764+
dev1: { type: "Button", net: "in2", order: 1, bits: 1, label: "in2" },
765+
dev2: { type: "Lamp", net: "out1", order: 2, bits: 1, label: "out1" },
766+
dev3: { type: "Lamp", net: "out2", order: 3, bits: 1, label: "out2" },
767+
dev4: { label: "m", type: "Subcircuit", celltype: "sub_mod" }
768+
},
769+
connectors: [
770+
{ to: { id: "dev4", port: "in1" }, from: { id: "dev0", port: "out" }, name: "in1" },
771+
{ to: { id: "dev4", port: "in2" }, from: { id: "dev1", port: "out" }, name: "in2" },
772+
{ to: { id: "dev2", port: "in" }, from: { id: "dev4", port: "out1" }, name: "out1" },
773+
{ to: { id: "dev3", port: "in" }, from: { id: "dev4", port: "out2" }, name: "out2" }
774+
]
775+
};
776+
const inlist = [{ name: 'in1', bits: 1 }, { name: 'in2', bits: 1 }];
777+
const outlist = [{ name: 'out1', bits: 1 }, { name: 'out2', bits: 1 }];
778+
new CircuitTestFixture(circuit, inlist, outlist, engine)
779+
.testJSON(circuit);
780+
});
781+
746782
});
747783

748784
// TODO: tests for public circuit interface

0 commit comments

Comments
 (0)