46150b9fac415eff25d83cb12b307ba7b0366e37
[Mograsim.git] /
1 package net.mograsim.logic.model.verilog.model.signals;
2
3 import net.mograsim.logic.core.types.BitVector;
4
5 public class Constant extends Signal
6 {
7         private final BitVector constant;
8
9         public Constant(BitVector constant)
10         {
11                 super(Type.CONSTANT, constant.length());
12                 this.constant = constant;
13
14                 check();
15         }
16
17         private void check()
18         {
19                 if (!constant.isBinary())
20                         throw new IllegalArgumentException("Constant is not binary: " + constant);
21         }
22
23         public BitVector getConstant()
24         {
25                 return constant;
26         }
27
28         @Override
29         public String toReferenceVerilogCode()
30         {
31                 return getWidth() + "'b" + constant.toBitstring();
32         }
33
34         @Override
35         public int hashCode()
36         {
37                 final int prime = 31;
38                 int result = super.hashCode();
39                 result = prime * result + ((constant == null) ? 0 : constant.hashCode());
40                 return result;
41         }
42
43         @Override
44         public boolean equals(Object obj)
45         {
46                 if (this == obj)
47                         return true;
48                 if (!super.equals(obj))
49                         return false;
50                 if (getClass() != obj.getClass())
51                         return false;
52                 Constant other = (Constant) obj;
53                 if (constant == null)
54                 {
55                         if (other.constant != null)
56                                 return false;
57                 } else if (!constant.equals(other.constant))
58                         return false;
59                 return true;
60         }
61 }