diff --git a/src/com/xilinx/rapidwright/edif/EDIFNetlist.java b/src/com/xilinx/rapidwright/edif/EDIFNetlist.java index ddd8a1a16..fba55d696 100644 --- a/src/com/xilinx/rapidwright/edif/EDIFNetlist.java +++ b/src/com/xilinx/rapidwright/edif/EDIFNetlist.java @@ -1624,7 +1624,7 @@ public void expandMacroUnisims(Series series) { throw new RuntimeException("failed to find cell macro "+cellName+", we are in "+lib.getName()); } primsToRemoveOnCollapse.add(cellName); - EDIFCell copy = new EDIFCell(netlistPrims, macro); + EDIFCell copy = new EDIFCell(netlistPrims, macro, cellName); if (copy.getCellInsts().size() > 0) { for (EDIFCellInst copyInst : copy.getCellInsts()) { EDIFCell primCell = netlistPrims.getCell(copyInst.getCellType().getName()); diff --git a/test/src/com/xilinx/rapidwright/edif/TestEDIFNetlist.java b/test/src/com/xilinx/rapidwright/edif/TestEDIFNetlist.java index bf4e574ee..ff01040af 100644 --- a/test/src/com/xilinx/rapidwright/edif/TestEDIFNetlist.java +++ b/test/src/com/xilinx/rapidwright/edif/TestEDIFNetlist.java @@ -74,7 +74,7 @@ private Design createSamplePrimitiveDesign(String prim, Part part) { final EDIFCell prototypePrim = Design.getPrimitivesLibrary().getCell(prim); - EDIFCell primCell = new EDIFCell(netlist.getHDIPrimitivesLibrary(), prototypePrim); + EDIFCell primCell = new EDIFCell(netlist.getHDIPrimitivesLibrary(), prototypePrim, prim); primCell.createCellInst("test" + prim, netlist.getTopCell()); @@ -104,6 +104,33 @@ void testMacroExpansionException(@TempDir Path tempDir) { Assertions.assertFalse(testDesign2.getNetlist().getHDIPrimitivesLibrary().containsCell("OBUFDS_DUAL_BUF")); } + @Test + void testMacroExpansionPortParents() { + final Part part = PartNameTools.getPart(Device.KCU105); + Design testDesign = createSamplePrimitiveDesign("OBUFDS", part); + + EDIFCell cell = testDesign.getNetlist().getHDIPrimitivesLibrary().getCell("OBUFDS"); + for (EDIFPort p : cell.getPorts()) { + Assertions.assertSame(p.getParentCell(), cell); + } + + testDesign.getNetlist().expandMacroUnisims(part.getSeries()); + + EDIFCell expandedCell = testDesign.getNetlist().getHDIPrimitivesLibrary().getCell("OBUFDS_DUAL_BUF"); + Assertions.assertNotNull(expandedCell); + for (EDIFPort p : expandedCell.getPorts()) { + Assertions.assertSame(p.getParentCell(), expandedCell); + } + + testDesign.getNetlist().collapseMacroUnisims(part.getSeries()); + + EDIFCell collapsedCell = testDesign.getNetlist().getHDIPrimitivesLibrary().getCell("OBUFDS"); + Assertions.assertNotNull(collapsedCell); + for (EDIFPort p : collapsedCell.getPorts()) { + Assertions.assertEquals(p.getParentCell(), collapsedCell); + } + } + @Test public void testTrackChanges() { Design d = Design.readCheckpoint(RapidWrightDCP.getPath("microblazeAndILA_3pblocks.dcp"), true);