PHDLTran - Translate the PHDL Netlist into your Specific Netlist Format

PHDLTran


The PHDLTran utility translates the generic PHDL Netlist (the .net file generated by the compiler) into any format that you need to for your specific layout tool. The two major tools that we use are PADS and Eagle, so the compiler automatically generates netlists for these two tools, but through extending a class within the PHDLTran utility, you can use PHDL to generate a netlist for just about any tool you desire, simply by specifying the format in which you would like the data to be outputed.

You can download the translator called phdltran.jar here.

Creating Your Netlist Translator


Within the PHDLTran java utility there is a class called DefaultTranslator.java, the format you need for your netlist can be specified by extending this DefaultTranslator class and overriding or creating methods to specify things such as the file extension, the header or footer, the format of how nets and parts are defined, and in what order they need to be defined.

There are two essential things you need to do for your translator to work:

Setting the File Extension

Setting the file extension, is relatively easy, within the constructor you simply set the fileExtension String field equal to the extension that you desire. As shown:

public class MyTranslator extends DefaultTranslator {

	public OsmondTranslator() {
		fileExtension = ".myext";
	}
//...
}
						

The translateNetlist(PhdlNetlist netlist) Method

The translateNetlist(PhdlNetlist netlist) method is called by the PHDLTran utility. It is passed an in memory representation of the netlist generated by the PHDL Compiler and needs to return your correctly formatted netlist in string form. The PHDLNetlist object passed into the method as a parameter, is a class that contains a Name for your design, as well as a set of PHDLNet objects and a set of PHDLPart objects. Each PHDLPart object has Name, Footprint, and Library fields, which can be used while generating your formated netlist. Likewise, each PHDLNet object contains a Name field and a set of PHDLPin objects which in turn have both a PartName and a PinName field.

In order to use these classes they need to be imported into the file as shown below:

import edu.byu.ee.phdl.netlist.PhdlNet;
import edu.byu.ee.phdl.netlist.PhdlNetlist;
import edu.byu.ee.phdl.netlist.PhdlPart;
import edu.byu.ee.phdl.netlist.PhdlPin;
import edu.byu.ee.phdl.translate.DefaultTranslator;

public class MyTranslator extends DefaultTranslator {

	public MyTranslator() {
		fileExtension = ".myext";
	}
}
						



Below is a list of the necessary/available accessor methods of each of the classes, PHDLNetlist, PHDLPart, PHDLNet, and PHDLPin, that you can use inorder to itterate through the nets and parts within the netlist and generate the netlist string in the specific format required by your tool:

public class PhdlNetlist {
	
	public String getName() {}

	public SortedSet<PhdlNet> getNets() {}

	public SortedSet<PhdlPart> getParts() {}
}

public class PhdlPart implements Comparable<Object> {
	
	public String getFootprint() {}

	public String getLibrary() {}

	public String getName() {}
}

public class PhdlNet implements Comparable<Object> {
	
	public String getName() {}

	public List<PhdlPin> getPins() {}
}

public class PhdlPin {
	
	public String getPartName() {}

	public String getPinName() {}
}

Generating the Netlist by Overwritting the Necessary Methods

The default implementation of the translateNetlist(PhdlNetlist netlist) method calls the following methods: translateHeader(), translateParts(netlist), and translateNets(netlist), which all return Strings and then concatenates the Strings together in the above order and returns that as the netlist String. You can either overwrite these three specified sub methods to return Strings in the needed format and have them automatically called by the translateNetlist(PhdlNetlist netlist) method or you can overwrite the entire translateNetlist(PhdlNetlist netlist) method itself in the case that you need to change the ordering of the netlist or need to add another section, such as a footer.


Below is shown the default implementations of these four methods, as well as two methods translateNet() and translatePart() called by the translateNets() and translateParts() methods:

	
	//Get the Header, Parts List and Netlist in the required formats and append 
	//them all together to form the complete netlist String
	
	//If you desired to change the order of the sections within the 
	//netlist you would overwrite this method and change the order
	//of the methods it calls.
	protected String translateNetlist(PhdlNetlist netlist) {
		StringBuilder sb = new StringBuilder();
		sb.append(translateHeader());
		sb.append(translateParts(netlist));
		sb.append(translateNets(netlist));
		//If you desired to add footer you would add it here too
		return sb.toString();
	}
	
	//Generate the Netlist header
	protected String translateHeader() {
		String header = "/**** Generated from PHDL Translator (DefaultTranslator) ****/ \n";
		return header;
	}
	
	//Generate the Parts section of the Netlist
	protected String translateParts(PhdlNetlist netlist) {
		StringBuilder sb = new StringBuilder();
		sb.append("\n/**** Parts ****/\n");
		for (PhdlPart part : netlist.getParts()) {
			sb.append(translatePart(part));
		}
		return sb.toString();
	}
	
	//Generate the Nets/Signals section of th Netlist
	protected String translateNets(PhdlNetlist netlist) {
		StringBuilder sb = new StringBuilder();
		sb.append("\n/**** Signals ****/\n");
		for (PhdlNet net : netlist.getNets()) {
			sb.append(translateNet(net));
		}
		return sb.toString();
	}
	
	//Called by the translateParts() method
	protected String translatePart(PhdlPart part) {
		return "part " + part.getName() + " {" + part.getFootprint() + ", " + 
			part.getLibrary() + "}\n";
	}
	
	//Called by the translateNets() method
	protected String translateNet(PhdlNet net) {
		StringBuilder sb = new StringBuilder();
		sb.append("signal '" + net.getName() + "'\n  { ");
		for (PhdlPin pin : net.getPins()) {
			sb.append(pin.getPartName() + "." + pin.getPinName() + " ");
		}
		sb.append("}\n");
		return sb.toString();
	}
					


Below is an example of what a translator created for the Osmond Netlist format might look like:

Disclaimer: Because we don't have the Osmond design tools, we haven't been able to personally test yet if this translator creates a netlist in the required format, so we display it here just as an example of how a translator can be created.

import edu.byu.ee.phdl.netlist.PhdlNet;
import edu.byu.ee.phdl.netlist.PhdlNetlist;
import edu.byu.ee.phdl.netlist.PhdlPart;
import edu.byu.ee.phdl.netlist.PhdlPin;
import edu.byu.ee.phdl.translate.DefaultTranslator;

public class OsmondTranslator extends DefaultTranslator {

	public OsmondTranslator() {
		fileExtension = ".osm";
	}

	@Override
	protected String translateHeader() {
		// In the case a header is unneeded
		String header = "";
		return header;
	}

	@Override
	protected String translateNet(PhdlNet net) {
		StringBuilder sb = new StringBuilder();
		sb.append("Signal \"" + net.getName() + "\"\n  { ");
		for (PhdlPin pin : net.getPins()) {
			sb.append(pin.getPartName() + "-" + pin.getPinName() + " ");
		}
		sb.append("}\n");
		return sb.toString();
	}

	@Override
	protected String translateNets(PhdlNetlist netlist) {
		StringBuilder sb = new StringBuilder();
		for (PhdlNet net : netlist.getNets()) {
			sb.append(translateNet(net));
		}
		return sb.toString();
	}

	@Override
	protected String translatePart(PhdlPart part) {
		return "Part " + part.getFootprint() + " { Name \"" + part.getName() + "\" }\n";
	}

	@Override
	protected String translateParts(PhdlNetlist netlist) {
		StringBuilder sb = new StringBuilder();
		for (PhdlPart part : netlist.getParts()) {
			sb.append(translatePart(part));
		}
		return sb.toString();
	}
}


After finishing your translator save it to a file with the same name as your class and the .java extension.

Running PHDLTran with your Personal Netlist Translator


In order to get the PHDLTran to use your translator rather than the default you need to set the classpath to see both your code and the jar file. You do this by using the following command:

   $javac -classpath phdltran.jar <my_translator_name>.java


   (Where <my_translator_name> is the name of your class.)

Then execute the translator with the class name as the parameter for the -tool flag:

   $ java -jar phdltran.jar -tool <my_translator_name> -src <my_source_folder>


   (Where <my_translator_name> is the name of your class and <my_source_folder> is the path to the source folder where the .net file generated by the PHDL compiler is located.)

Run the following command to show all options:

   $ java -jar phdltran.jar -?
						
PHDL translator v2.1, August 27, 2012 release.  

usage: java -jar phdltran.jar [-?] [-gen <file_name>] [-o] [-src
       <file_name>] [-tool <class_name>]
 -?,--help            print this message.
 -gen <file_name>     Output file name (with or without extension). If not
                      specified, output name(s) will be constructed from
                      the *.net netlist file name.
 -o,--overwrite       overwrite files silently.
 -src <file_name>     PHDL netlist source directory or file name with
                      *.net extension.  If not specified, the translator
                      will attempt to translate all *.net files in the
                      current directory.
 -tool <class_name>   fully qualified class name extending
                      DefaultTranslator for generating arbitrarily
                      formatted netlists for a particular layout tool.


The translator can also be called directly from the phdlcomp.jar compiler by using the -tran option:

usage: java -jar phdlcomp.jar [-?] [-a] [-e] [-gen <directory>] [-h] [-p]
       [-q] [-src <directory>] [-top <design_name>] [-tran <class_name>]
       [-v] [-x]
 -?,--help            print this message
 -a,--all             generate all output formats
 -e,--eagle           generate EAGLE script output
 -gen <directory>     directory to output generated files
 -h,--hierarchy       display design hierarchy
 -p,--pads            generate PADS netlist output
 -q,--quiet           supress reporting of warnings
 -src <directory>     directory containing PHDL source files
 -top <design_name>   specify top-level design name
 -tran <class_name>   optional translator class name
 -v,--verbose         report any extra information
 -x,--xml             generate XML netlist output




Check for contributions under the community tab to see if someone has already created a translator for your tool. And if you create a translator and would like to contribute, let us know so that we can get others access to what you've done.

Getting Started With PHDL

The best place to start is to visit our installation instructions which will help you get PHDL up and running on your machine. Then, be sure to visit the tutorial page.