Skip to content

Commit 621df7a

Browse files
committed
Merge pull request #5 from itoshkov/issue-4/hw-sim-self-ref-def
Issue #4: HWSim hangs on self-referencing definitions
2 parents 6f28006 + 6e85a19 commit 621df7a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

SimulatorsPackage/src/main/java/Hack/Gates/GateClass.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public abstract class GateClass {
6565
// a table that maps a gate name with its GateClass
6666
protected static Hashtable GateClasses = new Hashtable();
6767

68+
protected static final Set<String> classesBeingLoaded = new HashSet<String>();
69+
6870

6971
// Constructs a new GateCLass (public access through the getGateClass method)
7072
protected GateClass(String gateName, PinInfo[] inputPinsInfo, PinInfo[] outputPinsInfo) {
@@ -110,9 +112,15 @@ public static GateClass getGateClass(String gateName, boolean containsPath) thro
110112

111113
// gate wasn't found in cache
112114
if (result == null) {
115+
if (classesBeingLoaded.contains(gateName))
116+
throw new HDLException("Cyclic dependency. Gate definition (possibly indirectly) depends on itself: "
117+
+ gateName);
118+
119+
classesBeingLoaded.add(gateName);
113120
HDLTokenizer input = new HDLTokenizer(fileName);
114121
result = readHDL(input, gateName);
115122
GateClasses.put(fileName, result);
123+
classesBeingLoaded.remove(gateName);
116124
}
117125

118126
return result;

0 commit comments

Comments
 (0)