本文整理汇总了C#中BasicBlock类的典型用法代码示例。如果您正苦于以下问题:C# BasicBlock类的具体用法?C# BasicBlock怎么用?C# BasicBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicBlock类属于命名空间,在下文中一共展示了BasicBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildBlocks
public BuildBlocks(List<TExp> instList)
{
Dictionary<Temp.Label, BasicBlock> LabelToBlock = new Dictionary<Temp.Label, BasicBlock>();
foreach (TExp e in instList)
{
if (e is Label)
{
BasicBlock b = new BasicBlock();
Blocks.Add(b);
LabelToBlock[(e as Label).Lab] = b;
}
Blocks[Blocks.Count - 1].List.Add(e);
}
for (int i = 0; i < Blocks.Count; ++i)
{
BasicBlock b = Blocks[i];
if (b.List[b.List.Count - 1] is Jump)
{
b.AddEdge(LabelToBlock[(b.List[b.List.Count - 1] as Jump).Label.Lab]);
}
else
{
if (i + 1 < Blocks.Count)
b.AddEdge(Blocks[i + 1]);
if (b.List[b.List.Count - 1] is CJump)
b.AddEdge(LabelToBlock[(b.List[b.List.Count - 1] as CJump).Label.Lab]);
else if (b.List[b.List.Count - 1] is CJumpInt)
b.AddEdge(LabelToBlock[(b.List[b.List.Count - 1] as CJumpInt).Label.Lab]);
}
}
}
示例2: Load
public override BasicBlock<MilocInstruction> Load(int target)
{
var b = new BasicBlock<MilocInstruction>();
b.Add(new LoadaiFieldInstruction(addressReg, name, target) { ContainingType = containingType, FieldIndex = fieldIndex, FieldType = this.Type });
b.Reg = target;
return b;
}
示例3: Load
public override BasicBlock<MilocInstruction> Load(int target)
{
var b = new BasicBlock<MilocInstruction>();
b.Add(new LoadglobalInstruction(name, target) { Type = this.Type });
b.Reg = target;
return b;
}
示例4: Load
public override BasicBlock<MilocInstruction> Load(int target)
{
var b = new BasicBlock<MilocInstruction>();
b.Add(new LoadaiVarInstruction(name, target) { ArgIndex = ArgIndex });
b.Reg = target;
return b;
}
示例5: Load
public override BasicBlock<MilocInstruction> Load(int target)
{
var b = new BasicBlock<MilocInstruction>();
b.Add(new MovInstruction(this.reg, target) { ArgIndex = ArgIndex, ArgReg = reg });
b.Reg = target;
return b;
}
示例6: AddEdge
public void AddEdge(BasicBlock target)
{
if (target == null)
return;
Next.Add(target);
target.Prev.Add(this);
}
示例7: OptimizeComparisonToConstZero
/// <summary>
/// replaces comparisons where one operand has just been set to a const zero.
/// asumes that instruction is a comparison instruction with two registers.
/// </summary>
private bool OptimizeComparisonToConstZero(Instruction ins, BasicBlock bb)
{
var r1 = ins.Registers[0];
var r2 = ins.Registers[1];
bool? r1IsZero = null, r2IsZero = null;
if (r1.Category == RCategory.Argument || r1.PreventOptimization)
r1IsZero = false;
if (r2.Category == RCategory.Argument || r2.PreventOptimization)
r2IsZero = false;
for (var prev = ins.PreviousOrDefault; prev != null && prev.Index >= bb.Entry.Index; prev=prev.PreviousOrDefault)
{
if(r1IsZero.HasValue && r2IsZero.HasValue)
break;
if ((r1IsZero.HasValue && r1IsZero.Value) || (r2IsZero.HasValue && r2IsZero.Value))
break;
if (r1IsZero == null)
{
if (r1.IsDestinationIn(prev))
{
r1IsZero = prev.Code == RCode.Const && Convert.ToInt32(prev.Operand) == 0;
continue;
}
}
if (r2IsZero == null)
{
if (r2.IsDestinationIn(prev))
{
r2IsZero = prev.Code == RCode.Const && Convert.ToInt32(prev.Operand) == 0;
continue;
}
}
}
if (r2IsZero.HasValue && r2IsZero.Value)
{
ins.Code = ToComparisonWithZero(ins.Code);
ins.Registers.Clear();
ins.Registers.Add(r1);
return true;
}
if (r1IsZero.HasValue && r1IsZero.Value)
{
// swap the registers before converting to zero-comparison.
ins.Code = ToComparisonWithZero(SwapComparisonRegisters(ins.Code));
ins.Registers.Clear();
ins.Registers.Add(r2);
return true;
}
return false;
}
示例8: LinkBlockToClause
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public void LinkBlockToClause(Context context, BasicBlock block)
{
foreach (EhClause clause in this.Clauses)
{
if (clause.LinkBlockToClause(context, block))
return;
}
}
示例9: LinkBlocks
/// <summary>
/// Links the blocks.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="destination">The destination.</param>
protected void LinkBlocks(BasicBlock source, BasicBlock destination)
{
if (!source.NextBlocks.Contains(destination))
source.NextBlocks.Add(destination);
if (!destination.PreviousBlocks.Contains(source))
destination.PreviousBlocks.Add(source);
}
示例10: GetSuccessors
public IEnumerable<BasicBlock> GetSuccessors(BasicBlock source)
{
foreach (XRef xref in graph.GetReferencesFrom(source.Location))
{
// TODO: change Find to ExactMatch.
yield return blocks.Find(xref.Target);
}
}
示例11: BasicBlockEdge
public BasicBlockEdge(CFG cfg, int fromName, int toName)
{
From = cfg.CreateNode(fromName);
To = cfg.CreateNode(toName);
From.OutEdges.Add(To);
To.InEdges.Add(From);
cfg.AddEdge(this);
}
示例12:
List<BasicBlock> IDominanceAnalysis.GetChildren(BasicBlock block)
{
List<BasicBlock> child;
if (children.TryGetValue(block, out child))
return child;
else
return new List<BasicBlock>(); // Empty List
}
示例13: BBLoop
public BBLoop(BasicBlock head, BasicBlock tail, IMSet<BasicBlock> body, JST.Identifier label)
{
Head = head;
Tail = tail;
Body = body;
Label = label;
var headEscapes = false;
var headbranchbb = head as BranchBasicBlock;
foreach (var t in head.Targets)
{
if (!body.Contains(t))
headEscapes = true;
}
var tailEscapes = false;
var tailbranchbb = tail as BranchBasicBlock;
foreach (var t in tail.Targets)
{
if (!body.Contains(t))
tailEscapes = true;
}
if (!headEscapes && tailEscapes && tailbranchbb != null)
{
if (tailbranchbb.Target.Equals(head))
Flavor = LoopFlavor.DoWhile;
else if (tailbranchbb.Fallthrough.Equals(head))
Flavor = LoopFlavor.FlippedDoWhile;
else
throw new InvalidOperationException("invalid loop");
}
else if (headEscapes && !tailEscapes && headbranchbb != null)
{
if (body.Contains(headbranchbb.Target))
Flavor = LoopFlavor.WhileDo;
else if (body.Contains(headbranchbb.Fallthrough))
Flavor = LoopFlavor.FlippedWhileDo;
else
throw new InvalidOperationException("invalid loop");
}
else if (!headEscapes && !tailEscapes)
Flavor = LoopFlavor.Loop;
else if (headEscapes && tailEscapes && headbranchbb != null && tailbranchbb != null)
{
// Could encode as do-while with a break at start, or while-do with a break at end.
if (body.Contains(headbranchbb.Target))
Flavor = LoopFlavor.WhileDo;
else if (body.Contains(headbranchbb.Fallthrough))
Flavor = LoopFlavor.FlippedWhileDo;
else
throw new InvalidOperationException("invalid loop");
}
else
Flavor = LoopFlavor.Unknown;
}
示例14: RemoveDeadBlock
protected void RemoveDeadBlock(BasicBlock block)
{
if (trace.Active) trace.Log("*** RemoveBlock: " + block.ToString());
var nextBlocks = block.NextBlocks.ToArray();
EmptyBlockOfAllInstructions(block);
UpdatePhiList(block, nextBlocks);
}
示例15: doInvoke
private void doInvoke(string id, BasicBlock<MilocInstruction> b, List<int> regLocs)
{
var fun = CSC431.Program.Stable.Value.getType(id);
for (int i = 0; i < regLocs.Count; i++)
{
var t = fun.getArgs()[i];
b.Add(new StoreoutargumentInstruction(regLocs[i], i) { Type = t });
}
b.Add(new CallInstruction(id));
}