private void GetNodesInBlock(ILBlock block) { foreach (ILNode child in block.GetChildren()) { GetNodes(child); } }
protected virtual ILBlock VisitBlock(ILBlock block) { foreach (var child in block.GetChildren()) { Visit(child); } return(block); }
Ast.BlockStatement TransformBlock(ILBlock block) { Ast.BlockStatement astBlock = new BlockStatement(); if (block != null) { foreach(ILNode node in block.GetChildren()) { astBlock.AddRange(TransformNode(node)); } } return astBlock; }
void FlattenBasicBlocks(ILNode node) { ILBlock block = node as ILBlock; if (block != null) { List <ILNode> flatBody = new List <ILNode>(); foreach (ILNode child in block.GetChildren()) { FlattenBasicBlocks(child); ILBasicBlock childAsBB = child as ILBasicBlock; if (childAsBB != null) { if (!(childAsBB.Body.FirstOrDefault() is ILLabel)) { throw new Exception("Basic block has to start with a label. \n" + childAsBB.ToString()); } if (childAsBB.Body.LastOrDefault() is ILExpression && !childAsBB.Body.LastOrDefault().IsUnconditionalControlFlow()) { throw new Exception("Basci block has to end with unconditional control flow. \n" + childAsBB.ToString()); } flatBody.AddRange(childAsBB.GetChildren()); } else { flatBody.Add(child); } } block.EntryGoto = null; block.Body = flatBody; } else if (node is ILExpression) { // Optimization - no need to check expressions } else if (node != null) { // Recursively find all ILBlocks foreach (ILNode child in node.GetChildren()) { FlattenBasicBlocks(child); } } }
Ast.BlockStatement TransformBlock(ILBlock block) { Ast.BlockStatement astBlock = new BlockStatement(); if (block != null) { astBlock.HiddenStart = NRefactoryExtensions.CreateHidden(block.ILRanges, astBlock.HiddenStart); astBlock.HiddenEnd = NRefactoryExtensions.CreateHidden(block.EndILRanges, astBlock.HiddenEnd); foreach(ILNode node in block.GetChildren()) { astBlock.Statements.AddRange(TransformNode(node)); } } return astBlock; }
Ast.BlockStatement TransformBlock(ILBlock block) { Ast.BlockStatement astBlock = new BlockStatement(); if (block != null) { astBlock.HiddenStart = NRefactoryExtensions.CreateHidden(!context.CalculateILRanges ? null : ILRange.OrderAndJoin(block.ILRanges), astBlock.HiddenStart); astBlock.HiddenEnd = NRefactoryExtensions.CreateHidden(!context.CalculateILRanges ? null : ILRange.OrderAndJoin(block.EndILRanges), astBlock.HiddenEnd); foreach(ILNode node in block.GetChildren()) { var stmt = TransformNode(node); if (stmt != null) astBlock.Statements.Add(stmt); } } return astBlock; }
protected virtual ILBlock VisitBlock(ILBlock block) { foreach (var child in block.GetChildren()) Visit(child); return block; }