import byucc.edif.*;
import java.io.*;
import java.util.*;
+import java.awt.*;
import edu.berkeley.slipway.*;
import com.atmel.fpslic.*;
import static com.atmel.fpslic.FpslicConstants.*;
import static edu.berkeley.slipway.mpar.MPARDemo.*;
-public class NetList {
+public class NetList implements Iterable<NetList.Node> {
+
+ public NetList(String s) throws EdifNameConflictException, InvalidEdifNameException {
+ EdifEnvironment topEnv = new EdifEnvironment("top");
+ EdifLibraryManager elm = new EdifLibraryManager(topEnv);
+ EdifLibrary initLib = new EdifLibrary(elm, "initLib");
+ EdifEnvironment env = EdifMergeParser.parseAndMerge(new String[] { s }, initLib);
+ for(Iterator<EdifCellInstance> it = (Iterator<EdifCellInstance>)env.getTopCell().cellInstanceIterator();
+ it.hasNext();
+ ) {
+ createNode(it.next(), null);
+ }
+ }
private HashMap<String,Integer> ids = new HashMap<String,Integer>();
- public HashSet<Node> nodes = new HashSet<Node>();
+ public HashSet<Node> nodes = new HashSet<Node>();
+ public ArrayList<Node> nodes_ = new ArrayList<Node>();
+
public HashSet<LogicalNet> nets = new HashSet<LogicalNet>();
+ public Iterable<NetList.LogicalNet> getLogicalNets() { return nets; }
/** a node is some primitive element; a potential configuration of a CLB */
- public class Node {
- public PhysicalDevice.PhysicalCell physicalCell = null;
+ public class Node implements Iterable<Node.Port> {
private final String type;
private final int id;
- public int x = -1;
- public int y = -1;
-
private HashMap<String,Port> ports = new HashMap<String,Port>();
+ public Iterator<Port> iterator() { return ports.values().iterator(); }
public Node(String type) {
nodes.add(this);
+ nodes_.add(this);
this.type = type.toLowerCase();
Integer num = ids.get(type);
this.id = num == null ? 0 : num.intValue();
}
public String getType() { return type; }
public String toString() {
- if (x==-1 || y==-1)
- return type + "["+id+"]";
- return type + "@("+x+","+y+")";
+ return type;
}
public Port getPort(String name, boolean driver) {
Port p = ports.get(name);
return p;
}
- public Fpslic.Cell getPlacement(Fpslic fpslic) { return fpslic.cell(x, y); }
-
private int portIndex = 0;
-
/** a port is an input or output to a Node */
public class Port {
private final String name;
/** a Net is a collection of ports which are wired together */
public class LogicalNet implements Iterable<Node.Port> {
- private Node.Port driver = null;
- private HashSet<Node.Port> ports = new HashSet<Node.Port>();
- private HashSet<PhysicalDevice.PhysicalPip> pips = new HashSet<PhysicalDevice.PhysicalPip>();
- private HashSet<PhysicalDevice.PhysicalNet> pns = new HashSet<PhysicalDevice.PhysicalNet>();
-
- public void addPhysicalNet(PhysicalDevice.PhysicalNet pn) { pns.add(pn); }
- public void removePhysicalNet(PhysicalDevice.PhysicalNet pn) { pns.remove(pn); }
- public void addPhysicalPip(PhysicalDevice.PhysicalPip pip) { pips.add(pip); }
+ Node.Port driver = null;
+ HashSet<Node.Port> ports = new HashSet<Node.Port>();
public LogicalNet() { nets.add(this); }
public Iterator<Node.Port> iterator() { return ports.iterator(); }
public int getSize() { return ports.size(); }
- public boolean routed = false;
- public void unroute() {
- for(PhysicalDevice.PhysicalPip pip : pips) pip.set(false);
- while(pns.size() > 0) pns.iterator().next().removeLogicalNet(this);
- pips.clear();
- pns.clear();
- routed = false;
- }
- public void route(Fpslic fpslic, PhysicalDevice pd) {
- if (driver == null) return;
- if (routed) return;
- Node.Port[] dests = new Node.Port[ports.size() - (ports.contains(driver) ? 1 : 0)];
- int j = 0;
- for(Node.Port p : ports)
- if (p != driver)
- dests[j++] = p;
- PhysicalDevice.PhysicalNet[] destsp = new PhysicalDevice.PhysicalNet[dests.length];
- for(int i=0; i<dests.length; i++) {
- Node.Port dest = dests[i];
- switch(dest.index) {
- case 0: destsp[i] = dest.getNode().physicalCell.getNet("xi"); break;
- case 1: destsp[i] = dest.getNode().physicalCell.getNet("yi"); break;
- default: throw new Error();
- }
- }
- driver.getNode().physicalCell.getNet("out").route(destsp, this);
- routed = true;
- }
+
public void add(Node.Port p) {
if (p.driver) {
if (driver != null && driver != p)
}
return n;
}
+
+ public Node randomNode(Random rand) {
+ return nodes_.get(Math.abs(rand.nextInt()) % nodes_.size());
+ }
+
+ public Iterator<Node> iterator() { return nodes.iterator(); }
}