def testSimpleAssignment(self): x = VariableDecl(int_type, 'x') y = VariableDecl(int_type, 'y') stmt = Operation(AssignStatement(Name(x), Name(y))) cfg = CFG('f') cfg.connect(cfg.entry, stmt, cfg.exit) liveness = LivenessAnalysis(cfg) self.assertFalse(liveness.check(x, cfg.entry)) self.assertFalse(liveness.check(x, cfg.exit)) self.assertTrue(liveness.check(y, cfg.entry)) self.assertFalse(liveness.check(y, cfg.exit))
def run_phase(self): self.liveness = LivenessAnalysis(self.cfg) graph = InterferenceGraph(self.cfg, self.liveness) graph.colour(15) for var in self.cfg.symbol_table.symbols.values(): colour = graph.colours[var] var.register = REGISTERS[colour]
def testEmpty(self): x = VariableDecl(int_type, 'x') cfg = CFG('f') liveness = LivenessAnalysis(cfg) self.assertFalse(liveness.check(x, cfg.entry)) self.assertFalse(liveness.check(x, cfg.exit))