Exemplo n.º 1
0
 public NodeGraph(SourcePawnFile file, NodeBlock[] blocks)
 {
     file_        = file;
     blocks_      = blocks;
     nameCounter_ = 0;
     function_    = file_.lookupFunction(blocks[0].lir.pc);
 }
Exemplo n.º 2
0
 public NodeBuilder(SourcePawnFile file, LGraph graph)
 {
     file_   = file;
     graph_  = graph;
     blocks_ = new NodeBlock[graph_.blocks.Length];
     for (int i = 0; i < graph_.blocks.Length; i++)
     {
         blocks_[i] = new NodeBlock(graph_.blocks[i]);
     }
 }
Exemplo n.º 3
0
 static Function FunctionByName(SourcePawnFile file, string name)
 {
     for (int i = 0; i < file.functions.Length; i++)
     {
         if (file.functions[i].name == name)
         {
             return(file.functions[i]);
         }
     }
     return(null);
 }
Exemplo n.º 4
0
        public override DNode applyType(SourcePawnFile file, Tag tag, VariableType type)
        {
            if (value == null)
            {
                return(null);
            }
            DNode replacement = value.applyType(file, tag, type);

            if (replacement != value)
            {
                replaceOperand(0, replacement);
            }
            return(this);
        }
Exemplo n.º 5
0
 public override DNode applyType(SourcePawnFile file, Tag tag, VariableType type)
 {
     switch (type)
     {
     case VariableType.Array:
     case VariableType.ArrayReference:
     case VariableType.Reference:
     case VariableType.Variadic:
     {
         Variable global = file.lookupGlobal(value);
         if (global != null)
         {
             return(new DGlobal(global));
         }
         if (tag.name == "String")
         {
             return(new DString(file.stringFromData(value)));
         }
         break;
     }
     }
     return(this);
 }
Exemplo n.º 6
0
 public MethodParser(SourcePawnFile file, uint addr)
 {
     file_ = file;
     pc_   = addr;
 }
Exemplo n.º 7
0
 public virtual DNode applyType(SourcePawnFile file, Tag tag, VariableType type)
 {
     return(this);
 }
Exemplo n.º 8
0
        static void DumpMethod(SourcePawnFile file, SourceBuilder source, uint addr)
        {
            MethodParser mp    = new MethodParser(file, addr);
            LGraph       graph = mp.parse();

            NodeBuilder nb = new NodeBuilder(file, graph);

            NodeBlock[] nblocks = nb.buildNodes();

            NodeGraph ngraph = new NodeGraph(file, nblocks);

            // Remove dead phis first.
            NodeAnalysis.RemoveDeadCode(ngraph);

            NodeRewriter rewriter = new NodeRewriter(ngraph);

            rewriter.rewrite();

            NodeAnalysis.CollapseArrayReferences(ngraph);

            // Propagate type information.
            ForwardTypePropagation ftypes = new ForwardTypePropagation(ngraph);

            ftypes.propagate();

            BackwardTypePropagation btypes = new BackwardTypePropagation(ngraph);

            btypes.propagate();

            // We're not fixpoint, so just iterate again.
            ftypes.propagate();
            btypes.propagate();

            // Try this again now that we have type information.
            NodeAnalysis.CollapseArrayReferences(ngraph);

            ftypes.propagate();
            btypes.propagate();

            // Coalesce x[y] = x[y] + 5 into x[y] += 5
            NodeAnalysis.CoalesceLoadStores(ngraph);

            // After this, it is not legal to run type analysis again, because
            // arguments expecting references may have been rewritten to take
            // constants, for pretty-printing.
            NodeAnalysis.AnalyzeHeapUsage(ngraph);

            // Do another DCE pass, this time, without guards.
            NodeAnalysis.RemoveGuards(ngraph);
            NodeAnalysis.RemoveDeadCode(ngraph);

            NodeRenamer renamer = new NodeRenamer(ngraph);

            renamer.rename();

            // Do a pass to coalesce declaration+stores.
            NodeAnalysis.CoalesceLoadsAndDeclarations(ngraph);

            // Simplify conditional expressions.
            // BlockAnalysis.NormalizeConditionals(ngraph);
            var sb        = new SourceStructureBuilder(ngraph);
            var structure = sb.build();

            source.write(structure);

            //System.Console.In.Read();
            //System.Console.In.Read();
        }