Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle EDIF export bussed port name collision with identically named bit ports #616

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/com/xilinx/rapidwright/edif/EDIFPort.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
*
* Copyright (c) 2017-2022, Xilinx, Inc.
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* Copyright (c) 2022-2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Author: Chris Lavin, Xilinx Research Labs.
Expand Down Expand Up @@ -260,7 +260,12 @@ public void exportEDIF(OutputStream os, EDIFWriteLegalNameCache<?> cache, boolea
os.write(EXPORT_CONST_INDENT);
os.write(EXPORT_CONST_PORT_BEGIN);
if (width > 1) os.write(EXPORT_CONST_ARRAY_BEGIN);
exportEDIFName(os, cache);
if (isBus()) {
exportEDIFBusName(os, cache);
} else {
exportEDIFName(os, cache);
}

if (width > 1) {
os.write(' ');
os.write(Integer.toString(width).getBytes(StandardCharsets.UTF_8));
Expand All @@ -278,6 +283,17 @@ public void exportEDIF(OutputStream os, EDIFWriteLegalNameCache<?> cache, boolea
os.write('\n');
}

/**
* Writes out valid EDIF syntax the name and/or rename of this port to the
* provided output writer.
*
* @param os The stream to export the EDIF syntax to.
* @throws IOException
*/
public void exportEDIFBusName(OutputStream os, EDIFWriteLegalNameCache<?> cache) throws IOException {
exportSomeEDIFName(os, getName(), cache.getEDIFRename(busName));
}

/**
* @return the parentCell
*/
Expand Down
4 changes: 2 additions & 2 deletions src/com/xilinx/rapidwright/edif/EDIFPortInst.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
*
* Copyright (c) 2017-2022, Xilinx, Inc.
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* Copyright (c) 2022-2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Author: Chris Lavin, Xilinx Research Labs.
Expand Down Expand Up @@ -278,7 +278,7 @@ public void writeEDIFExport(OutputStream os, byte[] indent, EDIFWriteLegalNameCa
}
else {
os.write(EXPORT_CONST_MEMBER);
os.write(cache.getLegalEDIFName(getPort().getName()));
os.write(cache.getLegalEDIFName(getPort().getBusName(true)));
os.write(' ');
os.write(Integer.toString(index).getBytes(StandardCharsets.UTF_8));
os.write(')');
Expand Down
36 changes: 33 additions & 3 deletions test/src/com/xilinx/rapidwright/edif/TestEDIFNetlist.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021-2022, Xilinx, Inc.
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* Copyright (c) 2022-2023, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Author: Chris Lavin, Xilinx Research Labs.
Expand Down Expand Up @@ -32,15 +32,16 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import com.xilinx.rapidwright.design.Design;
import com.xilinx.rapidwright.device.Device;
import com.xilinx.rapidwright.device.IOStandard;
import com.xilinx.rapidwright.device.Part;
import com.xilinx.rapidwright.device.PartNameTools;
import com.xilinx.rapidwright.edif.compare.EDIFNetlistComparator;
import com.xilinx.rapidwright.support.RapidWrightDCP;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class TestEDIFNetlist {

Expand Down Expand Up @@ -287,4 +288,33 @@ public void testMigrateCellsAndSubCells(boolean uniquify) {
Assertions.assertEquals(dstLibrary.getCells().size(), 1);
}
}

@Test
public void testBussedPortNamingCollision(@TempDir Path path) {
final EDIFNetlist origNetlist = EDIFTools.createNewNetlist("test");

EDIFCell top = origNetlist.getTopCell();

EDIFCellInst ff = top.createChildCellInst("ff", Design.getPrimitivesLibrary().getCell("FDRE"));
origNetlist.getHDIPrimitivesLibrary().addCell(ff.getCellType());

// Create two ports, one single-bit and another bussed with the same root name
EDIFPort port0 = top.createPort("unfortunate_name", EDIFDirection.INOUT, 1);
EDIFPort port1 = top.createPort("unfortunate_name[1:0]", EDIFDirection.INOUT, 2);

EDIFNet net0 = top.createNet("net0");
net0.createPortInst(port0);
net0.createPortInst("D", ff);

EDIFNet net1 = top.createNet("net1");
net1.createPortInst(port1, 1);
net1.createPortInst("R", ff);

Path tempFile = path.resolve("test.edf");
origNetlist.exportEDIF(tempFile);

EDIFNetlist testNetlist = EDIFTools.readEdifFile(tempFile);
EDIFNetlistComparator comparer = new EDIFNetlistComparator();
Assertions.assertEquals(0, comparer.compareNetlists(origNetlist, testNetlist));
}
}