ModelComponentToVerilogConverter can now convert TriStateBuffers
[Mograsim.git] / plugins / net.mograsim.logic.model.verilog / src / net / mograsim / logic / model / verilog / model / signals / Signal.java
1 package net.mograsim.logic.model.verilog.model.signals;
2
3 import java.util.Objects;
4
5 public abstract class Signal
6 {
7         private final Type type;
8         private final String name;
9         private final int width;
10
11         public Signal(Type type, String name, int width)
12         {
13                 this.type = Objects.requireNonNull(type);
14                 this.name = Objects.requireNonNull(name);
15                 this.width = width;
16
17                 check();
18         }
19
20         private void check()
21         {
22                 if (width <= 0)
23                         throw new IllegalArgumentException("Signal width is negative: " + width);
24         }
25
26         public Type getType()
27         {
28                 return type;
29         }
30
31         public String getName()
32         {
33                 return name;
34         }
35
36         public int getWidth()
37         {
38                 return width;
39         }
40
41         public String toReferenceVerilogCode()
42         {
43                 return name;
44         }
45
46         @Override
47         public String toString()
48         {
49                 return name + "[" + getWidth() + "]";
50         }
51
52         @Override
53         public int hashCode()
54         {
55                 final int prime = 31;
56                 int result = 1;
57                 result = prime * result + ((name == null) ? 0 : name.hashCode());
58                 result = prime * result + ((type == null) ? 0 : type.hashCode());
59                 result = prime * result + width;
60                 return result;
61         }
62
63         @Override
64         public boolean equals(Object obj)
65         {
66                 if (this == obj)
67                         return true;
68                 if (obj == null)
69                         return false;
70                 if (getClass() != obj.getClass())
71                         return false;
72                 Signal other = (Signal) obj;
73                 if (name == null)
74                 {
75                         if (other.name != null)
76                                 return false;
77                 } else if (!name.equals(other.name))
78                         return false;
79                 if (type != other.type)
80                         return false;
81                 if (width != other.width)
82                         return false;
83                 return true;
84         }
85
86         public static enum Type
87         {
88                 WIRE, IO_INPUT, IO_OUTPUT;
89         }
90 }