BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<PIP> path = new ArrayList<PIP>();
ArrayList<PIP> pipList = new ArrayList<PIP>();
Node currNode = null;
WireConnection currWire;
WireConnection[] wiresList = null;
ArrayList<Node> choices;
// This keeps track of all the possible starting points (or sources) that
// we can use to route this net.
ArrayList<Node> sources = new ArrayList<Node>();
// Add the original source from the net
sources.add(new Node(net.getSourceTile(), // Add the tile of the source
dev.getPrimitiveExternalPin(net.getSource()), // wire on the source
null, // This is used for retracing the route once it is completed
0)); // Number of switches needed to reach this point in the route
// In this loop we'll route each sink pin of the net separately
for(Pin sinkPin : net.getPins()){
if(sinkPin.isOutPin()) continue; // Don't try to route the source to the source
boolean start = true;
boolean finishedRoute = false;
// Here is where we create the current sink that we intend to target in this
//routing iteration.
Node sink = new Node(sinkPin.getTile(), // A node is a specific tile and wire pair
dev.getPrimitiveExternalPin(sinkPin), // we need the external pin
// name of the primitive pin
// (ex: F1_PINWIRE0 vs. F1)
null, // This is a parent node
0); // This value is used to keep track
// length in hops of the route.
MessageGenerator.printHeader("Current Sink: " + sink.getTile() +
" " + we.getWireName(sink.getWire()));
// Almost all routes must pass through a particular switch matrix and wire to arrive
// at the particular sink. Here we obtain that information to help us target the routing.
Node switchMatrixSink = sink.getSwitchBoxSink(dev);
System.out.println("** Sink must pass through switch matrix: " + switchMatrixSink.getTile() +
", wire: " + we.getWireName(switchMatrixSink.getWire())+ " **");
while(!finishedRoute){
// Here we prompt the user to choose a source to start the route from. If this
// is the first tile we are routing in this net there will only be one choice.
if(start){
start = false;
System.out.println("Sources:");
for(int i=0; i < sources.size(); i++){
Node src = sources.get(i);
System.out.println(" " + i+". " + src.getTile() + " " + we.getWireName(src.getWire()));
}
System.out.print("Choose a source from the list above: ");
try {
choice = Integer.parseInt(br.readLine());
} catch (Exception e){
System.out.println("Error, could not get choice, defaulting to 0");
choice = 0;
}
// Once we get the user's choice, we can determine what wires the source
// can connect to by calling Tile.getWireConnections(int wire)
currNode = sources.get(choice);
wiresList = currNode.getTile().getWireConnections(currNode.getWire());
if(wiresList == null || wiresList.length == 0){
// We'll have to choose something else, this source had no other connections.
System.out.println("Wire had no connections");
continue;
}
}
// Print out some information about the sink we are targeting
if(sink.getTile().getSinks().get(sink.getWire()).switchMatrixSinkWire == -1){
System.out.println("\n\nSINK: "
+ sink.getTile().getName()
+ " "
+ we.getWireName(sink.getWire())
+ " "
+ net.getName());
}
else{
System.out.println("\n\nSINK: "
+ sink.getTile().getName()
+ " "
+ we.getWireName(sink.getWire())
+ " "
+ net.getName()
+ " thru("
+ switchMatrixSink.getTile() + " "
+ we.getWireName(sink.getTile().getSinks().get(sink.getWire()).switchMatrixSinkWire) + ")");
}
// Print out a part of the corresponding PIP that we have chosen
System.out.println(" pip " + currNode.getTile().getName() + " "
+ we.getWireName(currNode.getWire()) + " -> ");
// Check if we have reached the sink node
if (sink.getTile().equals(currNode.getTile())
&& sink.getWire() == currNode.getWire()){
System.out.println("You completed the route!");
// If we have, let's print out all the PIPs we used
for (PIP pip : path){
System.out.print(pip.toString(we));
pipList.add(pip);
finishedRoute = true;
}
}
if(!finishedRoute){
// We didn't find the sink yet, let's print out the set of
// choices we can follow given our current wire
choices = new ArrayList<Node>();
for (int i = 0; i < wiresList.length; i++) {
currWire = wiresList[i];
choices.add(new Node(currWire.getTile(currNode.getTile()),
currWire.getWire(), currNode, currNode.getLevel() + 1));
System.out.println(" " + i + ". "
+ currWire.getTile(currNode.getTile()).getName()
+ " " + we.getWireName(currWire.getWire()) + " "