static void Main(string[] args) { var fileName = args[0]; var stream = new AntlrInputStream(File.ReadAllText(fileName)); var lexer = new JavaLexer(stream); var tokenStream = new CommonTokenStream(lexer); var parser = new JavaParser(tokenStream); var classContext = parser.class_definition(); var methodContext = classContext.method(); var program = new IRVisitor().Visit(methodContext.body()); Console.WriteLine("IR:"); Console.WriteLine(string.Join("\n", program.Select(x => " " + x.ToString()))); Console.WriteLine(); var blocks = BasicBlockCreator.Create(program); Console.WriteLine("Basic Blocks:"); var graphViz = BasicBlockCreator.DumpGraphViz(blocks); Console.WriteLine(graphViz); var definitions = DFA.GetReachingDefinitions(blocks.Last()); Console.WriteLine("Reaching definitions: " + string.Join(", ", definitions)); }
static void TestDefinitions(string resourceName, IEnumerable <int> expected) { var resourceStream = typeof(Tests).Assembly.GetManifestResourceStream($"pt_dfa.tests.{resourceName}"); var stream = new AntlrInputStream(resourceStream); var lexer = new JavaLexer(stream); var tokenStream = new CommonTokenStream(lexer); var parser = new JavaParser(tokenStream); var classContext = parser.class_definition(); var methodContext = classContext.method(); var ir = methodContext.Accept(new IRVisitor()); var blocks = BasicBlockCreator.Create(ir); var definitions = DFA.GetReachingDefinitions(blocks.Last()); Assert.IsTrue(definitions.SequenceEqual(expected)); }