Esempio n. 1
0
        public static ForwardAnalysisSolver <AState, Type, EdgeData> Make <Local, Parameter, Method, Field, Source, Dest, Context>(
            IDecodeMSIL <APC, Local, Parameter, Method, Field, Type, Source, Dest, Context, EdgeData> decoder,
            IAnalysis <APC, AState, IVisitMSIL <APC, Local, Parameter, Method, Field, Type, Source, Dest, AState, AState>, EdgeData> driver,
            ILPrinter <APC> printer
            )
            where Context : IMethodContext <Field, Method>
        {
            Contract.Requires(decoder != null);
            Contract.Requires(driver != null);

            IVisitMSIL <APC, Local, Parameter, Method, Field, Type, Source, Dest, AState, AState> visitor = driver.Visitor();
            var result = new ForwardAnalysisSolver <AState, Type, EdgeData>(
                decoder.Context.MethodContext.CFG,
                delegate(APC pc, AState state) { return(decoder.ForwardDecode <AState, AState, IVisitMSIL <APC, Local, Parameter, Method, Field, Type, Source, Dest, AState, AState> >(pc, visitor, state)); },
                driver.EdgeConversion,
                driver.Join,
                driver.ImmutableVersion,
                driver.MutableVersion,
                driver.Dump,
                delegate(APC pc, AState state) { return(decoder.IsUnreachable(pc) || driver.IsBottom(pc, state)); },
                delegate(APC pc, AState state) { return(driver.IsTop(pc, state)); },
                printer,
                decoder.Display,
                decoder.EdgeData
                );

            result.CachePolicy = driver.CacheStates(result);
            return(result);
        }
Esempio n. 2
0
 public CodeLayer(IDecodeMSIL <APC, Local, Parameter, Method, Field, Type, Expression, Variable, ContextData, EdgeData> ildecoder, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, IDecodeContracts <Local, Parameter, Method, Field, Type> ctDecoder,
                  Converter <Expression, string> expression2String, Converter <Variable, string> variable2String,
                  ILPrinter <APC> printer, Func <Variable, Variable, bool> newerThan)
     : this(ildecoder, mdDecoder, ctDecoder, expression2String, variable2String, newerThan)
 {
     this.printer = printer;
 }
Esempio n. 3
0
        public void Print(TextWriter tw, ILPrinter <APC> printer,
                          Func <CFGBlock, IEnumerable <LispList <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                          LispList <Edge <CFGBlock, EdgeTag> > context)
        {
            var set = new HashSet <Pair <Subroutine, LispList <Edge <CFGBlock, EdgeTag> > > > ();

            this.method_subroutine.Print(tw, printer, contextLookup, context, set);
        }
Esempio n. 4
0
 public CodeLayer(IILDecoder <APC, Expression, Variable, ContextData, EdgeData> ilDecoder,
                  IMetaDataProvider metadataDecoder,
                  IContractProvider contractDecoder,
                  Func <Expression, string> expressionToString,
                  Func <Variable, string> variableToString, ILPrinter <APC> printer)
     : this(ilDecoder, metadataDecoder, contractDecoder, expressionToString, variableToString)
 {
     this.printer = new Lazy <ILPrinter <APC> > (() => printer);
 }
Esempio n. 5
0
 void ICFG.Print(TextWriter tw, ILPrinter <APC> printer, Func <CFGBlock, IEnumerable <LispList <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                 LispList <Edge <CFGBlock, EdgeTag> > context)
 {
     DecoratorHelper.Push(this);
     try {
         UnderlyingCFG.Print(tw, printer, contextLookup, context);
     } finally {
         DecoratorHelper.Pop();
     }
 }
Esempio n. 6
0
 public void Print(TextWriter tw, ILPrinter <APC> printer,
                   Func <CFGBlock, IEnumerable <LispList <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                   LispList <Edge <CFGBlock, EdgeTag> > context)
 {
     DecoratorHelper.Push <IEdgeSubroutineAdaptor> (this);
     try {
         this.underlying.Print(tw, printer, contextLookup, context);
     } finally {
         DecoratorHelper.Pop();
     }
 }
 public void Print(System.IO.TextWriter tw, ILPrinter <APC> ilPrinter, BlockInfoPrinter <APC> edgePrinter, Func <CFGBlock, IEnumerable <DataStructures.FList <DataStructures.STuple <CFGBlock, CFGBlock, string> > > > contextLookup, DataStructures.FList <DataStructures.STuple <CFGBlock, CFGBlock, string> > context)
 {
     CallAdaption.Push <IEdgeSubroutineAdaptor>(this);
     try
     {
         underlying.Print(tw, ilPrinter, edgePrinter, contextLookup, context);
     }
     finally
     {
         CallAdaption.Pop(this);
     }
 }
Esempio n. 8
0
 Create <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ContextData, EdgeData>(
     IDecodeMSIL <APC, Local, Parameter, Method, Field, Type, Expression, Variable, ContextData, EdgeData> ildecoder,
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
     IDecodeContracts <Local, Parameter, Method, Field, Type> ctDecoder,
     Converter <Expression, string> expression2String,
     Converter <Variable, string> variable2String,
     ILPrinter <APC> printer,
     Func <Variable, Variable, bool> newerThan
     )
     where Type : IEquatable <Type>
     where ContextData : IMethodContext <Field, Method>
 {
     return(new CodeLayer <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ContextData, EdgeData>(
                ildecoder, mdDecoder, ctDecoder,
                expression2String, variable2String,
                printer, newerThan
                ));
 }
Esempio n. 9
0
        public ForwardAnalysisSolver(
            ICFG cfg,
            Transformer <APC, AState, AState> transfer,
            EdgeConverter <APC, AState, EdgeData> edgeConverter,
            Joiner <APC, AState> joiner,
            Converter <AState, AState> immutableVersion,
            Converter <AState, AState> mutableVersion,
            Action <Pair <AState, TextWriter> > dumper,
            Func <APC, AState, bool> isBottom,
            Func <APC, AState, bool> isTop,
            ILPrinter <APC> printer,
            Printer <EdgeData> edgeDataPrinter,
            Func <APC, APC, EdgeData> edgeDataGetter
            )
            : base(cfg)
        {
            Contract.Requires(transfer != null);
            Contract.Requires(immutableVersion != null);
            Contract.Requires(isBottom != null);
            Contract.Requires(isTop != null);
            Contract.Requires(joiner != null);
            Contract.Requires(mutableVersion != null);
            Contract.Requires(edgeConverter != null);
            Contract.Requires(edgeDataGetter != null);

            this.transfer         = transfer;
            this.edgeConverter    = edgeConverter;
            this.joiner           = joiner;
            this.immutableVersion = immutableVersion;
            this.mutableVersion   = mutableVersion;
            this.dumper           = dumper;
            this.isBottom         = isBottom;
            this.isTop            = isTop;
            this.printer          = printer;
            this.edgeDataPrinter  = edgeDataPrinter;
            this.edgeDataGetter   = edgeDataGetter;
        }
Esempio n. 10
0
 protected virtual void PrintReferencedSubroutines(TextWriter tw, HashSet <Subroutine> subs, ILPrinter <APC> printer,
                                                   Func <CFGBlock, IEnumerable <LispList <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                                                   LispList <Edge <CFGBlock, EdgeTag> > context,
                                                   HashSet <Pair <Subroutine, LispList <Edge <CFGBlock, EdgeTag> > > > printed)
 {
     foreach (Subroutine subroutine in subs)
     {
         if (contextLookup == null)
         {
             subroutine.Print(tw, printer, contextLookup, context, printed);
         }
         else
         {
             foreach (var ctx in contextLookup(subroutine.Entry))
             {
                 subroutine.Print(tw, printer, contextLookup, ctx, printed);
             }
         }
     }
 }
Esempio n. 11
0
        public override void Print(TextWriter tw, ILPrinter <APC> printer, Func <CFGBlock,
                                                                                 IEnumerable <LispList <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                                   LispList <Edge <CFGBlock, EdgeTag> > context,
                                   HashSet <Pair <Subroutine, LispList <Edge <CFGBlock, EdgeTag> > > > printed)
        {
            var element = new Pair <Subroutine, LispList <Edge <CFGBlock, EdgeTag> > > (this, context);

            if (printed.Contains(element))
            {
                return;
            }
            printed.Add(element);
            var    subs       = new HashSet <Subroutine> ();
            var    methodInfo = this as IMethodInfo;
            string method     = (methodInfo != null) ? String.Format("({0})", this.SubroutineFacade.MetaDataProvider.FullName(methodInfo.Method)) : null;

            tw.WriteLine("Subroutine SR{0} {1} {2}", Id, Kind, method);
            tw.WriteLine("-------------");
            foreach (BlockWithLabels <Label> block in this.blocks)
            {
                tw.Write("Block {0} ({1})", block.Index, block.ReversePostOrderIndex);
                if (this.edge_info.DepthFirstInfo(block).TargetOfBackEdge)
                {
                    tw.WriteLine(" (target of backedge)");
                }
                else if (IsJoinPoint(block))
                {
                    tw.WriteLine(" (join point)");
                }
                else
                {
                    tw.WriteLine();
                }

                tw.Write("  Predecessors: ");
                foreach (var edge in block.Subroutine.PredecessorEdges[block])
                {
                    tw.Write("({0}, {1}) ", edge.Key, edge.Value.Index);
                }
                tw.WriteLine();
                PrintHandlers(tw, block);

                tw.WriteLine("  Code:");
                foreach (APC apc in block.APCs())
                {
                    printer(apc, "    ", tw);
                }

                tw.Write("  Successors: ");
                foreach (var edge in block.Subroutine.SuccessorEdges[block])
                {
                    tw.Write("({0}, {1}", edge.Key, edge.Value.Index);
                    if (this.edge_info.IsBackEdge(block, Dummy.Value, edge.Value))
                    {
                        tw.Write(" BE");
                    }

                    for (LispList <Pair <EdgeTag, Subroutine> > list = GetOrdinaryEdgeSubroutines(block, edge.Value, context); list != null; list = list.Tail)
                    {
                        subs.Add(list.Head.Value);
                        tw.Write(" SR{0}({1})", list.Head.Value.Id, list.Head.Key);
                    }
                    tw.Write(") ");
                }
                tw.WriteLine();
            }
            PrintReferencedSubroutines(tw, subs, printer, contextLookup, context, printed);
        }
 public void Print(TextWriter tw, ILPrinter <APC> ilPrinter, BlockInfoPrinter <APC> edgePrinter, Func <CFGBlock, IEnumerable <SubroutineContext> > contextLookup, SubroutineContext context)
 {
     throw new NotImplementedException();
 }
Esempio n. 13
0
 private static void PrintIL(LambdaExpression e)
 {
     PrintTitle("IL", ConsoleColor.Green);
     Console.WriteLine(ILPrinter.GetIL(e));
     Console.WriteLine();
 }
Esempio n. 14
0
		public void Print (TextWriter tw, ILPrinter<APC> printer,
		                   Func<CFGBlock, IEnumerable<LispList<Edge<CFGBlock, EdgeTag>>>> contextLookup,
		                   LispList<Edge<CFGBlock, EdgeTag>> context)
		{
			DecoratorHelper.Push<IEdgeSubroutineAdaptor> (this);
			try {
				this.underlying.Print (tw, printer, contextLookup, context);
			} finally {
				DecoratorHelper.Pop ();
			}
		}
Esempio n. 15
0
 Create <Expression, Variable, ContextData, EdgeConversionData> (
     IILDecoder <APC, Expression, Variable, ContextData, EdgeConversionData> ilDecoder,
     IMetaDataProvider metadataDecoder,
     IContractProvider contractDecoder, Func <Expression, string> expressionToString, Func <Variable, string> variableToString, ILPrinter <APC> printer)
     where ContextData : IMethodContextProvider
 {
     return(new CodeLayer <Expression, Variable, ContextData, EdgeConversionData>
                (ilDecoder, metadataDecoder, contractDecoder, expressionToString, variableToString, printer));
 }
Esempio n. 16
0
 public void Print (TextWriter tw, ILPrinter<APC> printer,
                    Func<CFGBlock, IEnumerable<Sequence<Edge<CFGBlock, EdgeTag>>>> contextLookup,
                    Sequence<Edge<CFGBlock, EdgeTag>> context)
 {
         var set = new HashSet<Pair<Subroutine, Sequence<Edge<CFGBlock, EdgeTag>>>> ();
         this.method_subroutine.Print (tw, printer, contextLookup, context, set);
 }
Esempio n. 17
0
        protected override void PrintReferencedSubroutines(TextWriter tw, HashSet <Subroutine> subs, ILPrinter <APC> printer,
                                                           Func <CFGBlock, IEnumerable <LispList <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                                                           LispList <Edge <CFGBlock, EdgeTag> > context,
                                                           HashSet <Pair <Subroutine, LispList <Edge <CFGBlock, EdgeTag> > > > printed)
        {
            foreach (Subroutine sub in this.FaultFinallySubroutines.Values)
            {
                if (contextLookup == null)
                {
                    sub.Print(tw, printer, contextLookup, context, printed);
                }
                else
                {
                    foreach (var ctx in contextLookup(sub.Entry))
                    {
                        sub.Print(tw, printer, contextLookup, ctx, printed);
                    }
                }
            }

            base.PrintReferencedSubroutines(tw, subs, printer, contextLookup, context, printed);
        }
Esempio n. 18
0
 public abstract void Print(TextWriter tw, ILPrinter <APC> printer,
                            Func <CFGBlock, IEnumerable <Sequence <Edge <CFGBlock, EdgeTag> > > > contextLookup,
                            Sequence <Edge <CFGBlock, EdgeTag> > context,
                            HashSet <Pair <Subroutine, Sequence <Edge <CFGBlock, EdgeTag> > > > set);