diff --git a/src/ram.py b/src/ram.py index a82f9ab..75d2d60 100644 --- a/src/ram.py +++ b/src/ram.py @@ -97,6 +97,49 @@ class Ram(object): print(*self.instr[self.current]['args']) self.instr[self.current]['op'](self, *self.instr[self.current]['args']) + def generate_graph(self): + graph_edges = [] + n_instr = len(self.instr) + for (n,instr) in enumerate(self.instr): + if ((instr['op'] == Ram.op) and (n0: + current = waitlist.pop() + accessible.append(current) + try: + temp = accessible_from_instr[current] + except KeyError: # no node reachable from this node + pass + for elem in temp: + if elem not in accessible and elem not in waitlist: + waitlist.append(elem) + return sorted(accessible) + + def remove_unreachable_instr(self): + accessible = self.accessible_instr() + new_instr = [instr for (i,instr) in enumerate(self.instr) if i in accessible] + for instr in new_instr: + print(instr) + self.instr = new_instr + + ### example