Esempio n. 1
0
        public void TestCompactStmContainer2()
        {
            var Node = (AstNode)ast.Statements(
                ast.Return()
                );

            Node = new AstOptimizer().Optimize(Node);
            Assert.AreEqual(
                "<AstNodeStmReturn />",
                AstSerializer.SerializeAsXml(Node, false)
                );
        }
Esempio n. 2
0
        public void RoundTrip()
        {
            var ast = TestExecutor.Parse(
                "z = 1 :a = z z = 2 a = :a * z a /= z",
                "flag=a==:a if flag then goto 5 else goto 6 end",
                "x = \"hello\" * 4 goto \"world\" x = 2",
                "b*=2 flag=b>30 if flag then :b=a end",
                "b=b-1 goto 4",
                "b=b+1 goto 4"
                );

            Console.WriteLine(ast);
            Console.WriteLine();

            var s = new AstSerializer().Serialize(ast);

            Console.WriteLine(s.ToString(Formatting.None));
            Console.WriteLine();

            var d = new AstDeserializer().Parse(s.ToString());

            Console.WriteLine(d);
        }
Esempio n. 3
0
        public void TestCompactStmContainer()
        {
            var Node = (AstNode)ast.Statements(
                ast.Return(),
                ast.Statements(
                    ast.Statements(
                        ast.Return()
                        ),
                    ast.Return(),
                    ast.Statements(ast.Statements(ast.Statements())),
                    ast.Return(),
                    ast.Statements(
                        ast.Return()
                        )
                    ),
                ast.Return()
                );

            Node = new AstOptimizer().Optimize(Node);
            Assert.AreEqual(
                "AstNodeStmContainer(AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn())",
                AstSerializer.Serialize(Node)
                );
        }
Esempio n. 4
0
        public void TestCompactStmContainer()
        {
            var node = (AstNode)_ast.Statements(
                _ast.Return(),
                _ast.Statements(
                    _ast.Statements(
                        _ast.Return()
                        ),
                    _ast.Return(),
                    _ast.Statements(_ast.Statements(_ast.Statements())),
                    _ast.Return(),
                    _ast.Statements(
                        _ast.Return()
                        )
                    ),
                _ast.Return()
                );

            node = new AstOptimizer().Optimize(node);
            Assert.Equal(
                "AstNodeStmContainer(AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn(), AstNodeStmReturn())",
                AstSerializer.Serialize(node)
                );
        }
Esempio n. 5
0
        private void UpdateText()
        {
            if (PcListBox.SelectedItem != null)
            {
                var        PCItem          = (PCItem)PcListBox.SelectedItem;
                var        MethodCacheInfo = PCItem.MethodCacheInfo;
                var        MinPC           = MethodCacheInfo.MinPc;
                var        MaxPC           = MethodCacheInfo.MaxPc;
                var        Memory          = CpuProcessor.Memory;
                AstNodeStm Node            = null;
                if (MethodCacheInfo.AstTree != null)
                {
                    Node = MethodCacheInfo.AstTree.Optimize(CpuProcessor);
                }

                var InfoLines = new List <string>();

                InfoLines.Add($"Name: {MethodCacheInfo.Name}");
                InfoLines.Add($"TotalInstructions: {MethodCacheInfo.TotalInstructions}");
                InfoLines.Add($"DisableOptimizations: {MethodCacheInfo.DynarecFunction.DisableOptimizations}");

                InfoLines.Add($"EntryPC: 0x{MethodCacheInfo.EntryPc:X8}");
                InfoLines.Add($"MinPC: 0x{MethodCacheInfo.MinPc:X8}");
                InfoLines.Add($"MaxPC: 0x{MethodCacheInfo.MaxPc:X8}");
                InfoLines.Add(
                    $"TimeAnalyzeBranches: {MethodCacheInfo.DynarecFunction.TimeAnalyzeBranches.TotalMilliseconds}");
                InfoLines.Add($"TimeGenerateAst: {MethodCacheInfo.DynarecFunction.TimeGenerateAst.TotalMilliseconds}");
                InfoLines.Add($"TimeOptimize: {MethodCacheInfo.DynarecFunction.TimeOptimize.TotalMilliseconds}");
                InfoLines.Add($"TimeGenerateIL: {MethodCacheInfo.DynarecFunction.TimeGenerateIl.TotalMilliseconds}");
                InfoLines.Add(
                    $"TimeCreateDelegate: {MethodCacheInfo.DynarecFunction.TimeCreateDelegate.TotalMilliseconds}");
                InfoLines.Add($"TimeLinking: {MethodCacheInfo.DynarecFunction.TimeLinking.TotalMilliseconds}");
                InfoLines.Add($"TimeTotal: {MethodCacheInfo.DynarecFunction.TimeTotal.TotalMilliseconds}");

                InfoLines.Add(string.Format(""));
                foreach (var Item in MethodCacheInfo.DynarecFunction.InstructionStats.OrderBy(Pair => Pair.Value))
                {
                    InfoLines.Add($"{Item.Key}: {Item.Value}");
                }

                InfoTextBox.Text = string.Join("\r\n", InfoLines);

                var OutString = "";
                switch (LanguageComboBox.SelectedItem.ToString())
                {
                case "C#":
                    if (Node != null)
                    {
                        OutString = Node.ToCSharpString().Replace("CpuThreadState.", "");
                    }
                    break;

                case "IL":
                    if (Node != null)
                    {
                        OutString = Node.ToIlString <Action <CpuThreadState> >();
                    }
                    break;

                case "Ast":
                    if (Node != null)
                    {
                        OutString = AstSerializer.SerializeAsXml(Node);
                    }
                    break;

                case "Mips":
                {
                    var MipsDisassembler = new MipsDisassembler();
                    try
                    {
                        for (uint PC = MinPC; PC <= MaxPC; PC += 4)
                        {
                            var Instruction = Memory.ReadSafe <Instruction>(PC);
                            var Result      = MipsDisassembler.Disassemble(PC, Instruction);
                            OutString += $"0x{PC:X8}: {Result.ToString()}\r\n";
                        }
                    }
                    catch (Exception Exception)
                    {
                        Console.Error.WriteLine(Exception);
                    }
                }
                break;

                default:
                    break;
                }

                ViewTextBox.Text = OutString.Replace("\n", "\r\n");
            }
        }