实现多线宽合并

This commit is contained in:
锦恢 2025-01-02 04:41:17 +08:00
parent c4c6605174
commit 4e52da5431

View File

@ -3,6 +3,7 @@
*/
import { globalLookup } from "../global";
import { pinkLog } from "../utils";
import { Cell, dotConnect, ModuleView } from "./yosys";
// 线段的宽度
@ -199,9 +200,12 @@ export class Module {
*/
makeConnectionElkNodes() {
const nodes = [];
// 完成去重
const id2EdgeCount = new Map();
const edges = [];
const tree = this.view
const tree = this.view;
for (const cellName of tree.nameToCell.keys()) {
const cell = tree.nameToCell.get(cellName);
@ -281,25 +285,40 @@ export class Module {
// 器件当前的口为 input那么所连接的 port 就必须是 input即便这个 port 是 output
if (connection.direction === 'input') {
const edge = {
// id 遵循 sourcePort-targetPort
id: makeEdgeId(port.id, connection.id),
source: port.id,
sourcePort: dotConnect(port.id, '0'),
target: cell.id,
targetPort: connection.id
};
const edgeId = makeEdgeId(port.id, connection.id);
if (!id2EdgeCount.has(edgeId)) {
id2EdgeCount.set(edgeId, 0);
const edge = {
// id 遵循 sourcePort-targetPort
id: edgeId,
source: port.id,
sourcePort: dotConnect(port.id, '0'),
target: cell.id,
targetPort: connection.id
};
edges.push(edge);
}
const counter = id2EdgeCount.get(edgeId);
id2EdgeCount.set(edgeId, counter + 1);
edges.push(edge);
} else {
const edge = {
id: makeEdgeId(connection.id, port.id),
source: cell.id,
sourcePort: connection.id,
target: port.id,
targetPort: dotConnect(port.id, '0')
};
edges.push(edge);
const edgeId = makeEdgeId(connection.id, port.id);
if (!id2EdgeCount.has(edgeId)) {
id2EdgeCount.set(edgeId, 0);
const edge = {
id: edgeId,
source: cell.id,
sourcePort: connection.id,
target: port.id,
targetPort: dotConnect(port.id, '0')
};
edges.push(edge);
}
const counter = id2EdgeCount.get(edgeId);
id2EdgeCount.set(edgeId, counter + 1);
}
} else if (tree.wireIdToConnection.has(wireId)) {
@ -312,25 +331,39 @@ export class Module {
}
if (conn.direction === 'input') {
const edge = {
// id 遵循 sourcePort-targetPort
id: makeEdgeId(conn.id, connection.id),
source: cell.id,
sourcePort: connection.id,
target: conn.cell.id,
targetPort: conn.id
};
const edgeId = makeEdgeId(conn.id, connection.id);
if (!id2EdgeCount.has(edgeId)) {
id2EdgeCount.set(edgeId, 0);
const edge = {
// id 遵循 sourcePort-targetPort
id: edgeId,
source: cell.id,
sourcePort: connection.id,
target: conn.cell.id,
targetPort: conn.id
};
edges.push(edge);
}
const counter = id2EdgeCount.get(edgeId);
id2EdgeCount.set(edgeId, counter + 1);
edges.push(edge);
} else {
const edge = {
id: makeEdgeId(connection.id, conn.id),
source: conn.cell.id,
sourcePort: conn.id,
target: cell.id,
targetPort: connection.id
};
edges.push(edge);
const edgeId = makeEdgeId(connection.id, conn.id);
if (!id2EdgeCount.has(edgeId)) {
id2EdgeCount.set(edgeId, 0);
const edge = {
id: edgeId,
source: conn.cell.id,
sourcePort: conn.id,
target: cell.id,
targetPort: connection.id
};
edges.push(edge);
}
const counter = id2EdgeCount.get(edgeId);
id2EdgeCount.set(edgeId, counter + 1);
}
}
}
@ -339,6 +372,9 @@ export class Module {
}
}
pinkLog('#edge: ' + edges.length);
this.id2EdgeCount = id2EdgeCount;
return [nodes, edges];
}