Exemple #1
0
        private static void Main(string[] args)
        {
#if false
            TypeManager typeMgr = new TypeManager();
            typeMgr.Load(@"../../CodeGenTester/bin/debug/CodeGenTester.exe");
            TestCodeGen(typeMgr);
#endif

#if true
            TypeManager typeMgr = new TypeManager();
            typeMgr.Load(@"../../MSILTester/bin/debug/MSILTester.exe");
            TestReferenceMarker(typeMgr);
#endif

#if false
            var sw = new Stopwatch();
            sw.Start();

            typeMgr.AddEntry(typeMgr.Module.EntryPoint);
            typeMgr.Process();

            sw.Stop();
            Console.WriteLine("Elapsed: {0}ms", sw.ElapsedMilliseconds);

            TypeGenerator typeGen = new TypeGenerator(typeMgr);
            typeGen.GenerateAll();
#endif
        }
Exemple #2
0
        private static void TestCodeGen(TypeManager typeMgr)
        {
            TypeGenerator typeGen = new TypeGenerator(typeMgr);

            // typeGen.IsAllInOne = true;

            foreach (var typeDef in typeMgr.Module.Types)
            {
                if (GetTestClassResult(typeDef, out string expected))
                {
                    var oldColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("{0}: ", typeDef.FullName);
                    Console.ForegroundColor = oldColor;

                    typeMgr.AddEntry(typeDef.FindMethod("Entry"));
                    typeMgr.Process();
                    typeGen.GenerateAll();

                    string result = typeGen.ToString();
                    typeGen.ToFolder("../gen");

                    if (result == expected)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("PASSED");
                        Console.ForegroundColor = oldColor;
                    }
                    else
                    {
                        result   = result.Replace("\t", "    ");
                        expected = expected.Replace("\t", "    ");

                        int diff = 0;
                        for (; diff < Math.Min(result.Length, expected.Length); ++diff)
                        {
                            if (result[diff] != expected[diff])
                            {
                                break;
                            }
                        }

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("FAILED");
                        Console.ForegroundColor = oldColor;
                        Console.Write(result.Substring(0, diff));
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine('[' + result.Substring(diff) + ']');
                        Console.ForegroundColor = oldColor;
                    }

                    typeMgr.Reset();
                }
            }
        }
Exemple #3
0
        private static void TestReferenceMarker(TypeManager typeMgr)
        {
            foreach (var typeDef in typeMgr.Module.Types)
            {
                //if (typeDef.FullName != "TestIL.TestExplicitOverride2")
                //	continue;

                if (GetTestClassResult(typeDef, out string expected))
                {
                    var oldColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("{0}: ", typeDef.FullName);
                    Console.ForegroundColor = oldColor;

                    typeMgr.AddEntry(typeDef.FindMethod("Entry"));
                    typeMgr.Process();
                    string result = PrintAllTypes(typeMgr, false);

                    if (result == expected)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("PASSED");
                        Console.ForegroundColor = oldColor;
                    }
                    else
                    {
                        int diff = 0;
                        for (; diff < Math.Min(result.Length, expected.Length); ++diff)
                        {
                            if (result[diff] != expected[diff])
                            {
                                break;
                            }
                        }

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("FAILED");
                        Console.ForegroundColor = oldColor;
                        Console.Write(result.Substring(0, diff));
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine('[' + result.Substring(diff) + ']');
                        Console.ForegroundColor = oldColor;
                    }

                    typeMgr.Reset();
                }
            }
        }