diff --git a/src/sixtypical/model.py b/src/sixtypical/model.py index 6b72321..230ea0b 100644 --- a/src/sixtypical/model.py +++ b/src/sixtypical/model.py @@ -107,6 +107,13 @@ class LocationRef(Ref): def is_constant(self): return isinstance(self.type, RoutineType) + def backpatch_labels(self, resolver): + if isinstance(self.type, ExecutableType): + t = self.type + t.inputs = set([resolver(w) for w in t.inputs]) + t.outputs = set([resolver(w) for w in t.outputs]) + t.trashes = set([resolver(w) for w in t.trashes]) + @classmethod def format_set(cls, location_refs): return '{%s}' % ', '.join([str(loc) for loc in sorted(location_refs)]) diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index 618ea2a..eca633b 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -51,17 +51,9 @@ class Parser(object): self.scanner.check_type('EOF') # now backpatch the executable types. for defn in defns: - if isinstance(defn.location.type, VectorType): - t = defn.location.type - t.inputs = set([self.lookup(w) for w in t.inputs]) - t.outputs = set([self.lookup(w) for w in t.outputs]) - t.trashes = set([self.lookup(w) for w in t.trashes]) + defn.location.backpatch_labels(lambda w: self.lookup(w)) for routine in routines: - if isinstance(routine.location.type, ExecutableType): - t = routine.location.type - t.inputs = set([self.lookup(w) for w in t.inputs]) - t.outputs = set([self.lookup(w) for w in t.outputs]) - t.trashes = set([self.lookup(w) for w in t.trashes]) + routine.location.backpatch_labels(lambda w: self.lookup(w)) return Program(defns=defns, routines=routines) def defn(self):