实现多线宽合并

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