1 package net.mograsim.logic.model.verilog.model.statements;
4 import java.util.Objects;
6 import java.util.stream.Collectors;
8 import net.mograsim.logic.model.verilog.model.VerilogComponentDeclaration;
9 import net.mograsim.logic.model.verilog.model.signals.IOPort;
10 import net.mograsim.logic.model.verilog.model.signals.Signal;
12 public class ComponentReference extends Statement
14 private final String name;
15 private final VerilogComponentDeclaration referencedComponent;
16 private final List<Signal> arguments;
18 public ComponentReference(String name, VerilogComponentDeclaration referencedComponent, List<Signal> arguments)
20 this.name = Objects.requireNonNull(name);
21 this.referencedComponent = Objects.requireNonNull(referencedComponent);
22 this.arguments = List.copyOf(arguments);
29 List<IOPort> ioPorts = referencedComponent.getIOPorts();
30 if (ioPorts.size() != arguments.size())
31 throw new IllegalArgumentException(
32 "Incorrect nubmer of arguments given: " + arguments.size() + ", but should be " + ioPorts.size());
34 for (int i = 0; i < ioPorts.size(); i++)
35 if (ioPorts.get(i).getWidth() != arguments.get(i).getWidth())
36 throw new IllegalArgumentException("Argument #" + i + "(" + ioPorts.get(i) + "): Incorrect width: "
37 + arguments.get(i).getWidth() + ", but shoud be " + ioPorts.get(i).getWidth());
40 public String getName()
45 public VerilogComponentDeclaration getReferencedComponent()
47 return referencedComponent;
50 public List<Signal> getArguments()
56 public String toVerilogCode()
58 StringBuilder sb = new StringBuilder();
60 sb.append(referencedComponent.getID() + " " + name);
61 sb.append(arguments.stream().map(Signal::toReferenceVerilogCode).collect(Collectors.joining(", ", "(", ")")));
68 public Set<String> getDefinedNames()
74 public Set<Signal> getDefinedSignals()
80 public Set<Signal> getReferencedSignals()
82 return Set.copyOf(arguments);
86 public String toString()
88 return name + "[" + referencedComponent.getID() + "]";
96 result = prime * result + ((arguments == null) ? 0 : arguments.hashCode());
97 result = prime * result + ((name == null) ? 0 : name.hashCode());
98 result = prime * result + ((referencedComponent == null) ? 0 : referencedComponent.hashCode());
103 public boolean equals(Object obj)
109 if (getClass() != obj.getClass())
111 ComponentReference other = (ComponentReference) obj;
112 if (arguments == null)
114 if (other.arguments != null)
116 } else if (!arguments.equals(other.arguments))
120 if (other.name != null)
122 } else if (!name.equals(other.name))
124 if (referencedComponent == null)
126 if (other.referencedComponent != null)
128 } else if (!referencedComponent.equals(other.referencedComponent))