Bee2 branch landing: step 1
[fleet.git] / src / edu / berkeley / fleet / fpga / FpgaPath.java
1 package edu.berkeley.fleet.fpga;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.two.*;
4 import edu.berkeley.fleet.*;
5 import java.lang.reflect.*;
6 import java.util.*;
7 import java.io.*;
8 import static edu.berkeley.fleet.two.FleetTwoFleet.*;
9 import static edu.berkeley.fleet.fpga.verilog.Verilog.*;
10
11
12 public class FpgaPath extends FleetTwoPath {
13
14     private boolean[] path;
15     private FpgaDestination dest;
16     public final BitVector signal;
17
18     public Dock        getSource() { throw new RuntimeException("not implemented"); }
19     public Destination getDestination() { return dest; }
20     
21     private FpgaPath(boolean[] path, FpgaDestination dest, BitVector signal) {
22         this.signal = signal;
23         this.path = path;
24         this.dest = dest;
25     }
26
27     public BitVector toBitVector() {
28         BitVector bv = new BitVector(((Fpga)dest.dock.getShip().getFleet()).PACKET_DEST.getWidth() +
29                                      ((Fpga)dest.dock.getShip().getFleet()).PACKET_SIGNAL.getWidth());
30         bv.set(toLong());
31         return bv;
32     }
33     public long toLong() {
34         long ret = 0;
35         for(int i=0; i<path.length; i++) {
36             if (path[i]) ret |= (1 << i);
37         }
38         if (signal != null)
39             for(int i=0; i<signal.length(); i++) {
40                 if (signal.get(i))
41                     ret |= (1L << (i+11));
42             }
43         return ret;
44     }
45
46     public String toString() {
47         StringBuffer ret = new StringBuffer();
48         for(int i=0; i<path.length; i++) {
49             if (i>0) ret.append('_');
50             ret.append(path[i] ? "1" : "0");
51         }
52         return ret.toString()+(signal==null?"":(":"+signal));
53     }
54
55     public FpgaPath prepend(boolean b) {
56         boolean[] newpath = new boolean[path.length+1];
57         System.arraycopy(path, 0, newpath, 1, path.length);
58         newpath[0] = b;
59         return new FpgaPath(newpath, dest, signal);
60     }
61     public FpgaPath append(boolean b, FpgaDestination newdest) {
62         boolean[] newpath = new boolean[path.length+1];
63         System.arraycopy(path, 0, newpath, 0, path.length);
64         newpath[newpath.length-1] = b;
65         return new FpgaPath(newpath, newdest, signal);
66     }
67
68     public int getBufferingAmount() {
69         throw new RuntimeException("not implemented");
70     }
71
72     public int getLatencyMetric() {
73         return 0;
74     }
75
76     public static FpgaPath emptyPath(FpgaDestination dest, BitVector signal) {
77         return new FpgaPath(new boolean[0], dest, signal);
78     }
79
80     public BitVector getSignal() { return signal; }
81
82 }