当前位置: 首页>>代码示例>>C#>>正文


C# ILLabel类代码示例

本文整理汇总了C#中ILLabel的典型用法代码示例。如果您正苦于以下问题:C# ILLabel类的具体用法?C# ILLabel怎么用?C# ILLabel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ILLabel类属于命名空间,在下文中一共展示了ILLabel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DefineLabel

 public IILLabel DefineLabel(string name = null)
 {
     var result = new ILLabel(name, _lastLabelIndex);
     _lastLabelIndex++;
     _instructions.Add(result);
     return result;
 }
开发者ID:mano-cz,项目名称:BTDB,代码行数:7,代码来源:CachingILGen.cs

示例2: ILLabelWrapper

        public ILLabelWrapper(ILLabel source, ILPanelEditor editor, string path, string name = null, string label = null)
            : base(source, editor, path, BuildName(name, editor.Panel, source, "Label"),
                   String.IsNullOrEmpty(label) ? GetLabel(source) : label)
        {
            this.source = source;

            this.source.MouseDoubleClick += OnMouseDoubleClick;
        }
开发者ID:profix898,项目名称:ILNEditor,代码行数:8,代码来源:ILLabelWrapper.cs

示例3: BuildGraph

		ControlFlowGraph BuildGraph(List<ILNode> nodes, ILLabel entryLabel)
		{
			int index = 0;
			List<ControlFlowNode> cfNodes = new List<ControlFlowNode>();
			ControlFlowNode entryPoint = new ControlFlowNode(index++, 0, ControlFlowNodeType.EntryPoint);
			cfNodes.Add(entryPoint);
			ControlFlowNode regularExit = new ControlFlowNode(index++, -1, ControlFlowNodeType.RegularExit);
			cfNodes.Add(regularExit);
			ControlFlowNode exceptionalExit = new ControlFlowNode(index++, -1, ControlFlowNodeType.ExceptionalExit);
			cfNodes.Add(exceptionalExit);
			
			// Create graph nodes
			labelToCfNode = new Dictionary<ILLabel, ControlFlowNode>();
			Dictionary<ILNode, ControlFlowNode> astNodeToCfNode = new Dictionary<ILNode, ControlFlowNode>();
			foreach(ILBasicBlock node in nodes) {
				ControlFlowNode cfNode = new ControlFlowNode(index++, -1, ControlFlowNodeType.Normal);
				cfNodes.Add(cfNode);
				astNodeToCfNode[node] = cfNode;
				cfNode.UserData = node;
				
				// Find all contained labels
                foreach (ILLabel label in node.EnumerateSelfAndChildrenRecursive().OfType<ILLabel>())
                {
					labelToCfNode[label] = cfNode;
				}
			}
			
			// Entry endge
			ControlFlowNode entryNode = labelToCfNode[entryLabel];
			ControlFlowEdge entryEdge = new ControlFlowEdge(entryPoint, entryNode, JumpType.Normal);
			entryPoint.Outgoing.Add(entryEdge);
			entryNode.Incoming.Add(entryEdge);
			
			// Create edges
			foreach(ILBasicBlock node in nodes) {
				ControlFlowNode source = astNodeToCfNode[node];

                var allBranchTargets =
                    from e in node.EnumerateSelfAndChildrenRecursive().OfType<ILExpression>()
                    where e.IsBranch()
                    from t in e.GetBranchTargets()
                    select t;

				// Find all branches
				foreach(ILLabel target in allBranchTargets) {
					ControlFlowNode destination;
					// Labels which are out of out scope will not be int the collection
					// Insert self edge only if we are sure we are a loop
					if (labelToCfNode.TryGetValue(target, out destination) && (destination != source || target == node.Body.FirstOrDefault())) {
						ControlFlowEdge edge = new ControlFlowEdge(source, destination, JumpType.Normal);
						source.Outgoing.Add(edge);
						destination.Incoming.Add(edge);
					}
				}
			}
			
			return new ControlFlowGraph(cfNodes.ToArray());
		}
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:58,代码来源:LoopsAndConditions.cs

示例4: BuildGraph

        ControlFlowGraph BuildGraph(List<ILNode> nodes, ILLabel entryLabel)
        {
            int index = 0;
            List<ControlFlowNode> cfNodes = new List<ControlFlowNode>();
            ControlFlowNode entryPoint = new ControlFlowNode(index++, 0, ControlFlowNodeType.EntryPoint);
            cfNodes.Add(entryPoint);
            ControlFlowNode regularExit = new ControlFlowNode(index++, -1, ControlFlowNodeType.RegularExit);
            cfNodes.Add(regularExit);
            ControlFlowNode exceptionalExit = new ControlFlowNode(index++, -1, ControlFlowNodeType.ExceptionalExit);
            cfNodes.Add(exceptionalExit);

            // Create graph nodes
            labelToCfNode = new Dictionary<ILLabel, ControlFlowNode>();
            Dictionary<ILNode, ControlFlowNode>  astNodeToCfNode = new Dictionary<ILNode, ControlFlowNode>();
            foreach(ILNode node in nodes) {
                ControlFlowNode cfNode = new ControlFlowNode(index++, -1, ControlFlowNodeType.Normal);
                cfNodes.Add(cfNode);
                astNodeToCfNode[node] = cfNode;
                cfNode.UserData = node;

                // Find all contained labels
                foreach(ILLabel label in node.GetSelfAndChildrenRecursive<ILLabel>()) {
                    labelToCfNode[label] = cfNode;
                }
            }

            // Entry endge
            ControlFlowNode entryNode = labelToCfNode[entryLabel];
            ControlFlowEdge entryEdge = new ControlFlowEdge(entryPoint, entryNode, JumpType.Normal);
            entryPoint.Outgoing.Add(entryEdge);
            entryNode.Incoming.Add(entryEdge);

            // Create edges
            foreach(ILNode node in nodes) {
                ControlFlowNode source = astNodeToCfNode[node];

                // Find all branches
                foreach(ILExpression child in node.GetSelfAndChildrenRecursive<ILExpression>()) {
                    IEnumerable<ILLabel> targets = child.GetBranchTargets();
                    if (targets != null) {
                        foreach(ILLabel target in targets) {
                            ControlFlowNode destination;
                            // Labels which are out of out scope will not be int the collection
                            if (labelToCfNode.TryGetValue(target, out destination) && destination != source) {
                                ControlFlowEdge edge = new ControlFlowEdge(source, destination, JumpType.Normal);
                                source.Outgoing.Add(edge);
                                destination.Incoming.Add(edge);
                            }
                        }
                    }
                }
            }

            return new ControlFlowGraph(cfNodes.ToArray());
        }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:55,代码来源:ILAstOptimizer.cs

示例5: BuildGraph

		ControlFlowGraph BuildGraph(List<ILNode> nodes, ILLabel entryLabel)
		{
			cached_ControlFlowGraph.Nodes.Clear();
			int index = 0;
			var cfNodes = cached_ControlFlowGraph.Nodes;
			ControlFlowNode entryPoint = new ControlFlowNode(index++, 0, ControlFlowNodeType.EntryPoint);
			cfNodes.Add(entryPoint);
			ControlFlowNode regularExit = new ControlFlowNode(index++, null, ControlFlowNodeType.RegularExit);
			cfNodes.Add(regularExit);
			ControlFlowNode exceptionalExit = new ControlFlowNode(index++, null, ControlFlowNodeType.ExceptionalExit);
			cfNodes.Add(exceptionalExit);

			// Create graph nodes
			labelToCfNode.Clear();
			Dictionary<ILNode, ControlFlowNode> astNodeToCfNode = new Dictionary<ILNode, ControlFlowNode>();
			List<ILLabel> listLabels = null;
			foreach(ILBasicBlock node in nodes) {
				ControlFlowNode cfNode = new ControlFlowNode(index++, null, ControlFlowNodeType.Normal);
				cfNodes.Add(cfNode);
				astNodeToCfNode[node] = cfNode;
				cfNode.UserData = node;
				
				// Find all contained labels
				foreach(ILLabel label in node.GetSelfAndChildrenRecursive<ILLabel>(listLabels ?? (listLabels = new List<ILLabel>()))) {
					labelToCfNode[label] = cfNode;
				}
			}
			
			// Entry endge
			ControlFlowNode entryNode = labelToCfNode[entryLabel];
			ControlFlowEdge entryEdge = new ControlFlowEdge(entryPoint, entryNode, JumpType.Normal);
			entryPoint.Outgoing.Add(entryEdge);
			entryNode.Incoming.Add(entryEdge);

			// Create edges
			List<ILExpression> listExpressions = null;
			foreach(ILBasicBlock node in nodes) {
				ControlFlowNode source = astNodeToCfNode[node];
				
				// Find all branches
				foreach(ILLabel target in node.GetSelfAndChildrenRecursive<ILExpression>(listExpressions ?? (listExpressions = new List<ILExpression>()), e => e.IsBranch()).SelectMany(e => e.GetBranchTargets())) {
					ControlFlowNode destination;
					// Labels which are out of out scope will not be in the collection
					// Insert self edge only if we are sure we are a loop
					if (labelToCfNode.TryGetValue(target, out destination) && (destination != source || target == node.Body.FirstOrDefault())) {
						ControlFlowEdge edge = new ControlFlowEdge(source, destination, JumpType.Normal);
						source.Outgoing.Add(edge);
						destination.Incoming.Add(edge);
					}
				}
			}

			return cached_ControlFlowGraph;
		}
开发者ID:levisre,项目名称:dnSpy,代码行数:54,代码来源:LoopsAndConditions.cs

示例6: ConvertBody

		void ConvertBody(List<ILNode> body, int startPos, int bodyLength, List<KeyValuePair<ILLabel, StateRange>> labels)
		{
			newBody = new List<ILNode>();
			newBody.Add(MakeGoTo(labels, 0));
			List<SetState> stateChanges = new List<SetState>();
			int currentState = -1;
			// Copy all instructions from the old body to newBody.
			for (int pos = startPos; pos < bodyLength; pos++) {
				ILExpression expr = body[pos] as ILExpression;
				if (expr != null && expr.Code == ILCode.Stfld && expr.Arguments[0].MatchThis()) {
					// Handle stores to 'state' or 'current'
					if (GetFieldDefinition(expr.Operand as FieldReference) == stateField) {
						if (expr.Arguments[1].Code != ILCode.Ldc_I4)
							throw new SymbolicAnalysisFailedException();
						currentState = (int)expr.Arguments[1].Operand;
						stateChanges.Add(new SetState(newBody.Count, currentState));
					} else if (GetFieldDefinition(expr.Operand as FieldReference) == currentField) {
						newBody.Add(new ILExpression(ILCode.YieldReturn, null, expr.Arguments[1]));
					} else {
						newBody.Add(body[pos]);
					}
				} else if (returnVariable != null && expr != null && expr.Code == ILCode.Stloc && expr.Operand == returnVariable) {
					// handle store+branch to the returnVariable
					ILExpression br = body.ElementAtOrDefault(++pos) as ILExpression;
					if (br == null || !(br.Code == ILCode.Br || br.Code == ILCode.Leave) || br.Operand != returnLabel || expr.Arguments[0].Code != ILCode.Ldc_I4)
						throw new SymbolicAnalysisFailedException();
					int val = (int)expr.Arguments[0].Operand;
					if (val == 0) {
						newBody.Add(new ILExpression(ILCode.YieldBreak, null));
					} else if (val == 1) {
						newBody.Add(MakeGoTo(labels, currentState));
					} else {
						throw new SymbolicAnalysisFailedException();
					}
				} else if (expr != null && expr.Code == ILCode.Ret) {
					if (expr.Arguments.Count != 1 || expr.Arguments[0].Code != ILCode.Ldc_I4)
						throw new SymbolicAnalysisFailedException();
					// handle direct return (e.g. in release builds)
					int val = (int)expr.Arguments[0].Operand;
					if (val == 0) {
						newBody.Add(new ILExpression(ILCode.YieldBreak, null));
					} else if (val == 1) {
						newBody.Add(MakeGoTo(labels, currentState));
					} else {
						throw new SymbolicAnalysisFailedException();
					}
				} else if (expr != null && expr.Code == ILCode.Call && expr.Arguments.Count == 1 && expr.Arguments[0].MatchThis()) {
					MethodDefinition method = GetMethodDefinition(expr.Operand as MethodReference);
					if (method == null)
						throw new SymbolicAnalysisFailedException();
					StateRange stateRange;
					if (method == disposeMethod) {
						// Explicit call to dispose is used for "yield break;" within the method.
						ILExpression br = body.ElementAtOrDefault(++pos) as ILExpression;
						if (br == null || !(br.Code == ILCode.Br || br.Code == ILCode.Leave) || br.Operand != returnFalseLabel)
							throw new SymbolicAnalysisFailedException();
						newBody.Add(new ILExpression(ILCode.YieldBreak, null));
					} else if (finallyMethodToStateRange.TryGetValue(method, out stateRange)) {
						// Call to Finally-method
						int index = stateChanges.FindIndex(ss => stateRange.Contains(ss.NewState));
						if (index < 0)
							throw new SymbolicAnalysisFailedException();
						
						ILLabel label = new ILLabel();
						label.Name = "JumpOutOfTryFinally" + stateChanges[index].NewState;
						newBody.Add(new ILExpression(ILCode.Leave, label));
						
						SetState stateChange = stateChanges[index];
						// Move all instructions from stateChange.Pos to newBody.Count into a try-block
						stateChanges.RemoveRange(index, stateChanges.Count - index); // remove all state changes up to the one we found
						ILTryCatchBlock tryFinally = new ILTryCatchBlock();
						tryFinally.TryBlock = new ILBlock(newBody.GetRange(stateChange.NewBodyPos, newBody.Count - stateChange.NewBodyPos));
						newBody.RemoveRange(stateChange.NewBodyPos, newBody.Count - stateChange.NewBodyPos); // remove all nodes that we just moved into the try block
						tryFinally.CatchBlocks = new List<ILTryCatchBlock.CatchBlock>();
						tryFinally.FinallyBlock = ConvertFinallyBlock(method);
						newBody.Add(tryFinally);
						newBody.Add(label);
					}
				} else {
					newBody.Add(body[pos]);
				}
			}
			newBody.Add(new ILExpression(ILCode.YieldBreak, null));
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:84,代码来源:YieldReturnDecompiler.cs

示例7: BranchIfGreaterThanUnsigned

 /// <summary>
 /// Branches to the given label if the first value on the stack is greater than the second
 /// value on the stack.  If the operands are integers then they are treated as if they are
 /// unsigned.  If the operands are floating point numbers then a NaN value will trigger a
 /// branch.
 /// </summary>
 /// <param name="label"> The label to branch to. </param>
 public abstract void BranchIfGreaterThanUnsigned(ILLabel label);
开发者ID:dusk0r,项目名称:Jurassic,代码行数:8,代码来源:ILGenerator.cs

示例8: GenerateCode

        /// <summary>
        /// Generates CIL for the statement.
        /// </summary>
        /// <param name="generator"> The generator to output the CIL to. </param>
        /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
        public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
        {
            // Generate code for the start of the statement.
            var statementLocals = new StatementLocals() { NonDefaultSourceSpanBehavior = true };
            GenerateStartOfStatement(generator, optimizationInfo, statementLocals);

            // Unlike in .NET, in javascript there are no restrictions on what can appear inside
            // try, catch and finally blocks.  The one restriction which causes problems is the
            // inability to jump out of .NET finally blocks.  This is required when break, continue
            // or return statements appear inside of a finally block.  To work around this, when
            // inside a finally block these instructions throw an exception instead.

            // Setting the InsideTryCatchOrFinally flag converts BR instructions into LEAVE
            // instructions so that the finally block is executed correctly.
            var previousInsideTryCatchOrFinally = optimizationInfo.InsideTryCatchOrFinally;
            optimizationInfo.InsideTryCatchOrFinally = true;

            // Finally requires two exception nested blocks.
            if (this.FinallyBlock != null)
                generator.BeginExceptionBlock();

            // Begin the exception block.
            generator.BeginExceptionBlock();

            // Generate code for the try block.
            this.TryBlock.GenerateCode(generator, optimizationInfo);

            // Generate code for the catch block.
            if (this.CatchBlock != null)
            {
                // Begin a catch block.  The exception is on the top of the stack.
                generator.BeginCatchBlock(typeof(JavaScriptException));

                // Create a new DeclarativeScope.
                this.CatchScope.GenerateScopeCreation(generator, optimizationInfo);

                // Store the error object in the variable provided.
                generator.Call(ReflectionHelpers.JavaScriptException_ErrorObject);
                var catchVariable = new NameExpression(this.CatchScope, this.CatchVariableName);
                catchVariable.GenerateSet(generator, optimizationInfo, PrimitiveType.Any, false);

                // Make sure the scope is reverted even if an exception is thrown.
                generator.BeginExceptionBlock();

                // Emit code for the statements within the catch block.
                this.CatchBlock.GenerateCode(generator, optimizationInfo);

                // Revert the scope.
                generator.BeginFinallyBlock();
                this.CatchScope.GenerateScopeDestruction(generator, optimizationInfo);
                generator.EndExceptionBlock();
            }

            // Generate code for the finally block.
            if (this.FinallyBlock != null)
            {
                generator.BeginFinallyBlock();

                var branches = new List<ILLabel>();
                var previousStackSize = optimizationInfo.LongJumpStackSizeThreshold;
                optimizationInfo.LongJumpStackSizeThreshold = optimizationInfo.BreakOrContinueStackSize;
                var previousCallback = optimizationInfo.LongJumpCallback;
                optimizationInfo.LongJumpCallback = (generator2, label) =>
                    {
                        // It is not possible to branch out of a finally block - therefore instead of
                        // generating LEAVE instructions we throw an exception then catch it to transfer
                        // control out of the finally block.
                        generator2.LoadInt32(branches.Count);
                        generator2.NewObject(ReflectionHelpers.LongJumpException_Constructor);
                        generator2.Throw();

                        // Record any branches that are made within the finally code.
                        branches.Add(label);
                    };

                // Emit code for the finally block.
                this.FinallyBlock.GenerateCode(generator, optimizationInfo);

                // End the main exception block.
                generator.EndExceptionBlock();

                // Begin a catch block to catch any LongJumpExceptions. The exception object is on
                // the top of the stack.
                generator.BeginCatchBlock(typeof(LongJumpException));

                if (branches.Count > 0)
                {
                    // switch (exception.RouteID)
                    // {
                    //    case 0: goto label1;
                    //    case 1: goto label2;
                    // }
                    ILLabel[] switchLabels = new ILLabel[branches.Count];
                    for (int i = 0; i < branches.Count; i++)
                        switchLabels[i] = generator.CreateLabel();
//.........这里部分代码省略.........
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:101,代码来源:TryCatchFinallyStatement.cs

示例9: GetBreakOrContinueLabelDepth

        /// <summary>
        /// Searches for the given label in the break/continue stack.
        /// </summary>
        /// <param name="label"></param>
        /// <returns> The depth of the label in the stack.  Zero indicates the bottom of the stack.
        /// <c>-1</c> is returned if the label was not found. </returns>
        private int GetBreakOrContinueLabelDepth(ILLabel label)
        {
            if (label == null)
                throw new ArgumentNullException("label");

            int depth = this.breakOrContinueStack.Count - 1;
            foreach (var info in this.breakOrContinueStack)
            {
                if (info.BreakTarget == label)
                    return depth;
                if (info.ContinueTarget == label)
                    return depth;
                depth --;
            }
            return -1;
        }
开发者ID:HaKDMoDz,项目名称:GNet,代码行数:22,代码来源:OptimizationInfo.cs

示例10: FindLoops

        List<ILNode> FindLoops(HashSet<ControlFlowNode> nodes, ControlFlowNode entryPoint, bool excludeEntryPoint)
        {
            List<ILNode> result = new List<ILNode>();

            Queue<ControlFlowNode> agenda  = new Queue<ControlFlowNode>();
            agenda.Enqueue(entryPoint);
            while(agenda.Count > 0) {
                ControlFlowNode node = agenda.Dequeue();

                if (nodes.Contains(node)
                        && node.DominanceFrontier.Contains(node)
                        && (node != entryPoint || !excludeEntryPoint))
                {
                    HashSet<ControlFlowNode> loopContents = new HashSet<ControlFlowNode>();
                    FindLoopContents(nodes, loopContents, node, node);

                    // Move the content into loop block
                    nodes.ExceptWith(loopContents);
                    ILLabel entryLabel = new ILLabel() { Name = "Loop_" + (nextBlockIndex++) };
                    ((ILBlock)node.UserData).Body.Insert(0, entryLabel);
                    result.Add(new ILLoop() { ContentBlock = new ILBlock(FindLoops(loopContents, node, true)) { EntryPoint = entryLabel } });
                }

                // Using the dominator tree should ensure we find the the widest loop first
                foreach(var child in node.DominatorTreeChildren) {
                    agenda.Enqueue(child);
                }
            }

            // Add whatever is left
            foreach(var node in nodes) {
                result.Add((ILNode)node.UserData);
            }

            return result;
        }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:36,代码来源:ILAstOptimizer.cs

示例11: CreateExpression

 protected  ILExpression CreateExpression(GMCode code,  GM_Type[] types, ILLabel operand)
 {
     Debug.Assert(operand != null);
     ILExpression e = new ILExpression(code, operand);
     e.Types = types;
     e.Extra = (int)(CurrentRaw & 0xFFFF);
     e.AddILRange(CurrentPC);
     return e;
 }
开发者ID:WarlockD,项目名称:GMdsam,代码行数:9,代码来源:IBuildAst.cs

示例12: BranchIfTrue

 /// <summary>
 /// Branches to the given label if the value on the top of the stack is non-zero, true or
 /// non-null.
 /// </summary>
 /// <param name="label"> The label to branch to. </param>
 public void BranchIfTrue(ILLabel label)
 {
     BranchIfNotZero(label);
 }
开发者ID:dusk0r,项目名称:Jurassic,代码行数:9,代码来源:ILGenerator.cs

示例13: BranchIfNull

 /// <summary>
 /// Branches to the given label if the value on the top of the stack is zero, false or
 /// null.
 /// </summary>
 /// <param name="label"> The label to branch to. </param>
 public void BranchIfNull(ILLabel label)
 {
     BranchIfZero(label);
 }
开发者ID:dusk0r,项目名称:Jurassic,代码行数:9,代码来源:ILGenerator.cs

示例14: BranchIfNotEqual

 /// <summary>
 /// Branches to the given label if the two values on the top of the stack are not equal.
 /// </summary>
 /// <param name="label"> The label to branch to. </param>
 public abstract void BranchIfNotEqual(ILLabel label);
开发者ID:dusk0r,项目名称:Jurassic,代码行数:5,代码来源:ILGenerator.cs

示例15: BranchIfLessThanUnsigned

 /// <summary>
 /// Branches to the given label if the first value on the stack is less than the second
 /// value on the stack.  If the operands are integers then they are treated as if they are
 /// unsigned.  If the operands are floating point numbers then a NaN value will trigger a
 /// branch.
 /// </summary>
 /// <param name="label"> The label to branch to. </param>
 public abstract void BranchIfLessThanUnsigned(ILLabel label);
开发者ID:dusk0r,项目名称:Jurassic,代码行数:8,代码来源:ILGenerator.cs


注:本文中的ILLabel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。