|
The following is a demo of how to use the EDIF tools API. It parses a specified EDIF file,
prints information about the structures in it, and rewrites the EDIF file from the java data
structure that the original EDIF file was parsed into. Be sure to put the EDIF tools library
on your classpath as described on the downloads page.
Code
/* Demo of the EDIF api */
import java.io.IOException;
import java.util.Iterator;
import byucc.edif.EdifCell;
import byucc.edif.EdifCellInstance;
import byucc.edif.EdifEnvironment;
import byucc.edif.EdifLibrary;
import byucc.edif.EdifLibraryManager;
import byucc.edif.EdifNet;
import byucc.edif.EdifPortRef;
import byucc.edif.EdifPrintWriter;
import byucc.edif.libraries.xilinx.XilinxLibrary;
import byucc.edif.tools.merge.EdifMergeParser;
//////////////////////////////////////////////////////////////////////////
//// EdifDemo
public class EdifDemo {
///////////////////////////////////////////////////////////////////
//// public methods ////
/**
* This main method will parse a given Edif file and merge any appropriate
* EDIF files as specified by arguments in the args parameter. It will
* then print all libraries in the EDIF file, all cells in each library,
* all cellRefs in each cell, all nets in each cell, and all portRefs in
* each net. Finally, it will rewrite the EDIF file to a new file using
* the java data structure that the original EDIF file was parsed into.
*
* The following invocation of this method demonstrates the use of
* appropriate arguments:
*
* java EdifDemo <EDIF filename> <new EDIF filename> -L <search dir #1> -L \
* <search dir #2> -f <external EDIF filename>
*
* The arguments are interpreted as follows:
*
* args[0] - original EDIF filename.
* args[1] - new EDIF filename
* Search directories - this method needs to search multiple
* directories in an attempt to find matching edif files.
* To add a search directories, use the "-L" flag
* (one external directory for each invokation of "-L").
* A specific edif filename can be specified for merging using
* the "-f" flag. Only one external filename should be specified for
* each external edif file.
*/
public static void main(String[] args) {
if (args.length < 2) {
System.err
.println("Error: must specify at least an input and an output filename.");
System.exit(1);
}
// the EdifMergeParser.parseAndMerge(String[], EdifLibrary) expects an
// args[] array without the output filename, so make a new copy without
// the output
String[] parserArgs = new String[args.length - 1];
parserArgs[0] = args[0];
for (int i = 1; i < args.length - 1; i++)
parserArgs[i] = args[i + 1];
String edifOutFile = args[1];
// pass in null for the primitive library
EdifEnvironment top = EdifMergeParser.parseAndMerge(parserArgs, null);
// print all libraries in the file
EdifLibraryManager elm = top.getLibraryManager();
System.out.println("Libraries:");
for (Iterator libraries = elm.getLibraries().iterator(); libraries
.hasNext();) {
EdifLibrary el = (EdifLibrary) libraries.next();
System.out.println(el.getName());
// print all cells in each library
System.out.println("cells:");
for (Iterator cells = el.getCells().iterator(); cells.hasNext();) {
EdifCell cell = (EdifCell) cells.next();
System.out.println("\t" + cell.getName());
// print all cellRefs in each cell
Iterator cellRefs = cell.cellInstanceIterator();
if (cellRefs.hasNext()) {
System.out.println("\tcellRefs in " + cell.getName() + ":");
while (cellRefs.hasNext()) {
EdifCellInstance eci = (EdifCellInstance) cellRefs
.next();
System.out.println("\t\t" + eci);
}
}
// print all nets in each cell
Iterator nets = cell.netListIterator();
if (nets.hasNext()) {
System.out.println("\tnets in " + cell.getName() + ":");
while (nets.hasNext()) {
EdifNet net = (EdifNet) nets.next();
System.out.print("\t\t" + net.getName() + " ");
// print all portRefs in each net
Iterator portRefs = net.getPortRefIterator();
if (portRefs.hasNext()) {
//System.out.println("\t\tportRefs for " + net.getName());
System.out.print("(");
boolean first = true;
while (portRefs.hasNext()) {
EdifPortRef epr = (EdifPortRef) portRefs.next();
if (!first)
System.out.print(", ");
System.out.print(epr);
first = false;
}
System.out.println(")");
}
}
}
}
}
EdifPrintWriter epw = null;
try {
epw = new EdifPrintWriter(edifOutFile);
} catch (IOException e) {
System.err.println("Error writing to file: " + edifOutFile);
}
top.toEdif(epw);
}
}
|
|
|
Download
|