本文整理汇总了C#中Mosa.Runtime.CompilerFramework.BasicBlock类的典型用法代码示例。如果您正苦于以下问题:C# BasicBlock类的具体用法?C# BasicBlock怎么用?C# BasicBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicBlock类属于Mosa.Runtime.CompilerFramework命名空间,在下文中一共展示了BasicBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArgumentNullException
BasicBlock[] IDominanceProvider.GetDominators(BasicBlock block)
{
if (block == null)
throw new ArgumentNullException(@"block");
Debug.Assert(block.Sequence < _doms.Length, @"Invalid block index.");
if (block.Sequence >= _doms.Length)
throw new ArgumentException(@"Invalid block index.", @"block");
// Return value
BasicBlock[] result;
// Counter
int count, idx = block.Sequence;
// Count the dominators first
for (count = 1; 0 != idx; count++)
idx = _doms[idx].Sequence;
// Allocate a dominator array
result = new BasicBlock[count + 1];
result[0] = block;
for (idx = block.Sequence, count = 1; 0 != idx; idx = _doms[idx].Sequence)
result[count++] = _doms[idx];
result[count] = _doms[0];
return result;
}
示例2: CreateBlock
/// <summary>
/// Creates the block.
/// </summary>
/// <param name="label">The label.</param>
/// <param name="index">The index.</param>
/// <returns></returns>
protected BasicBlock CreateBlock(int label, int index)
{
// HACK: BasicBlock.Count for the sequence works for now since blocks are not removed
BasicBlock basicBlock = new BasicBlock (BasicBlocks.Count, label, index);
BasicBlocks.Add (basicBlock);
return basicBlock;
}
示例3: NextBlockHasInitialStack
/// <summary>
/// Nexts the block has initial stack.
/// </summary>
/// <param name="block">The block.</param>
/// <param name="nextBlock">The next block.</param>
/// <returns></returns>
private static bool NextBlockHasInitialStack(BasicBlock block, out BasicBlock nextBlock)
{
nextBlock = null;
foreach (BasicBlock b in block.NextBlocks)
{
if (b.InitialStack == null)
continue;
nextBlock = b;
return true;
}
return false;
}
示例4: FindAndLinkBlock
private void FindAndLinkBlock(BasicBlock block, int target)
{
BasicBlock next = this.FindBlock(target);
if (!block.NextBlocks.Contains(next)) {
this.LinkBlocks(block, next);
this.BuildBlockLinks(next);
}
}
示例5: LinkBlocks
/// <summary>
/// Links the Blocks.
/// </summary>
/// <param name="caller">The caller.</param>
/// <param name="callee">The callee.</param>
private void LinkBlocks(BasicBlock caller, BasicBlock callee)
{
// Chain the blocks together
caller.NextBlocks.Add(callee);
callee.PreviousBlocks.Add(caller);
}
示例6: Intersect
/// <summary>
/// Retrieves the highest common immediate dominator of the two given Blocks.
/// </summary>
/// <param name="b1">The first basic block.</param>
/// <param name="b2">The second basic block.</param>
/// <returns>The highest common dominator.</returns>
private BasicBlock Intersect(BasicBlock b1, BasicBlock b2)
{
BasicBlock f1 = b1, f2 = b2;
while (f2 != null && f1 != null && f1.Sequence != f2.Sequence)
{
while (f1 != null && f1.Sequence > f2.Sequence)
f1 = _doms[f1.Sequence];
while (f2 != null && f1 != null && f2.Sequence > f1.Sequence)
f2 = _doms[f2.Sequence];
}
return f1;
}
示例7: SpillActiveOperands
/// <summary>
/// Spills all active operands at the end of a basic block.
/// </summary>
/// <param name="block">The basic block to spill in.</param>
private void SpillActiveOperands(BasicBlock block)
{
int regIdx = 0;
foreach (Operand op in _activeOperands) {
if (op != null && op is MemoryOperand) {
Context ctx = new Context(InstructionSet, block);
ctx.GotoLast();
InsertMove(ctx, op, new RegisterOperand(op.Type, _registerSet[regIdx]));
}
regIdx++;
}
Array.Clear(_activeOperands, 0, _activeOperands.Length);
}
示例8: LinkTemporaryMoves
/// <summary>
/// Links the temporary moves.
/// </summary>
/// <param name="ctx">The CTX.</param>
/// <param name="block">The block.</param>
/// <param name="nextBlock">The next block.</param>
/// <param name="stack">The stack.</param>
private void LinkTemporaryMoves(Context ctx, BasicBlock block, BasicBlock nextBlock, Stack<Operand> stack)
{
Stack<Operand> initialStack = GetCurrentStack(stack);
Stack<Operand> nextInitialStack = GetCurrentStack(nextBlock.InitialStack);
for (int i = 0; i < nextBlock.InitialStack.Count; ++i)
ctx.AppendInstruction(IR.Instruction.MoveInstruction, nextInitialStack.Pop(), initialStack.Pop());
if (nextBlock.InitialStack.Count > 0)
foreach (BasicBlock nBlock in block.NextBlocks)
nBlock.InitialStack = GetCurrentStack(nextBlock.InitialStack);
}
示例9: AppendInstruction
/// <summary>
/// Inserts the instruction after.
/// </summary>
/// <param name="instruction">The instruction.</param>
/// <param name="code">The code.</param>
/// <param name="block">The block.</param>
public void AppendInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block)
{
AppendInstruction();
SetInstruction(instruction, code, block);
}
示例10: CreateTemporaryMoves
/// <summary>
/// Creates the temporary moves.
/// </summary>
/// <param name="ctx">The CTX.</param>
/// <param name="block">The block.</param>
/// <param name="stack">The stack.</param>
private void CreateTemporaryMoves(Context ctx, BasicBlock block, Stack<Operand> stack)
{
Context context = ctx.InsertBefore();
context.SetInstruction(IR.Instruction.NopInstruction);
BasicBlock nextBlock;
if (NextBlockHasInitialStack(block, out nextBlock))
LinkTemporaryMoves(context, block, nextBlock, stack);
else
CreateNewTemporaryMoves(context, block, stack);
}
示例11: IsNotProcessed
/// <summary>
/// Determines whether [is not processed] [the specified block].
/// </summary>
/// <param name="block">The block.</param>
/// <returns>
/// <c>true</c> if [is not processed] [the specified block]; otherwise, <c>false</c>.
/// </returns>
private bool IsNotProcessed(BasicBlock block)
{
return !_processed.Contains(block);
}
示例12: CreateNewTemporaryMoves
/// <summary>
/// Creates the new temporary moves.
/// </summary>
/// <param name="ctx">The CTX.</param>
/// <param name="block">The block.</param>
/// <param name="stack">The stack.</param>
private void CreateNewTemporaryMoves(Context ctx, BasicBlock block, Stack<Operand> stack)
{
Stack<Operand> nextStack = new Stack<Operand>();
foreach (Operand operand in stack)
{
Operand temp = MethodCompiler.CreateTemporary(operand.Type);
nextStack.Push(temp);
_operandStack.Pop();
ctx.AppendInstruction(IR.Instruction.MoveInstruction, temp, operand);
}
if (nextStack.Count > 0)
foreach (BasicBlock nextBlock in block.NextBlocks)
nextBlock.InitialStack = GetCurrentStack(nextStack);
}
示例13: AssignOperands
/// <summary>
/// Assigns the operands.
/// </summary>
/// <param name="block">The block.</param>
private void AssignOperands(BasicBlock block)
{
if (block.InitialStack != null)
foreach (Operand operand in block.InitialStack)
_operandStack.Push(operand);
for (Context ctx = new Context(InstructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
{
if (!(ctx.Instruction is IBranchInstruction) && !(ctx.Instruction is ICILInstruction))
continue;
if (!(ctx.Instruction is IR.JmpInstruction))
{
AssignOperandsFromCILStack(ctx, _operandStack);
(ctx.Instruction as ICILInstruction).Validate(ctx, MethodCompiler);
PushResultOperands(ctx, _operandStack);
}
if (ctx.Instruction is IBranchInstruction)
{
Stack<Operand> initialStack = GetCurrentStack(_operandStack);
CreateTemporaryMoves(ctx, block, initialStack);
break;
}
}
MarkAsProcessed(block);
foreach (BasicBlock b in block.NextBlocks)
{
if (IsNotProcessed(b))
AssignOperands(b);
}
}
示例14: Run
/// <summary>
/// Runs the specified compiler.
/// </summary>
public void Run()
{
if (!methodCount.ContainsKey(MethodCompiler.Method.Name))
methodCount[MethodCompiler.Method.Name] = 0;
++methodCount[MethodCompiler.Method.Name];
// Retreive the first block
firstBlock = FindBlock(-1);
workList = new Stack<BasicBlock>();
workList.Push(firstBlock);
workArray = new BitArray(BasicBlocks.Count);
string methodName = MethodCompiler.Method.Name;
methodName = methodName.Replace("<", "");
methodName = methodName.Replace(">", "");
methodName = methodName.Replace("$", "");
methodName = methodName.Replace(".", "");
IPipelineStage previousStage = MethodCompiler.GetPreviousStage(typeof(IMethodCompilerStage));
dotFile.WriteLine("subgraph cluster" + methodName + "_FlowGraph {");
dotFile.WriteLine("label = \"Method: " + methodName + "(" + MethodCompiler.Method.Signature + ") after " + previousStage.Name + "\"");
//dotFile.WriteLine("graph [rankdir = \"TB\"];");
string nodes = string.Empty;
string edges = string.Empty;
foreach (BasicBlock block in BasicBlocks)
{
string nodeName = string.Empty;
string nodeContent = string.Empty;
string nextNode = string.Empty;
nodeName = methodName + "_" + block.ToString();
//nodeName = nodeName.Replace("-", "_");
nodeContent += "<tr><td bgcolor=\"black\" align=\"center\" colspan=\"4\"><font face=\"Courier\" color=\"white\">L_" + block.Label.ToString("x4") + "</font></td></tr>";
int field = 0;
int i = 0;
for (Context ctx = new Context(InstructionSet, block); !ctx.EndOfInstruction; ctx.GotoNext())
{
if (ctx.Instruction == null)
continue;
string color;
string inst = ctx.Instruction.ToString(ctx).Replace("&", "&");
inst = inst.Replace("<", "<");
inst = inst.Replace(">", ">");
if (inst.StartsWith("IL") || inst.StartsWith("T_"))
color = "#0000ff5f";
else if (inst.StartsWith("IR"))
color = "#ff00005f";
else
color = "#CFD6CEff";
nodeContent += "<tr height=\"20\"><td bgcolor=\"white\" align=\"right\" width=\"20\"><img src=\"icon.png\"/></td><td bgcolor=\"white\" align=\"right\">" + (i++) + "</td><td bgcolor=\"" + color + "\" align=\"center\" colspan=\"2\"><font face=\"Courier\">" + inst + "</font></td></tr>";
++field;
}
if (nodeContent != string.Empty && nodeContent[nodeContent.Length - 1] == '|')
nodeContent = nodeContent.Substring(0, nodeContent.Length - 2);
if (nodeContent != string.Empty)
nodes += "\"" + nodeName + "\" [label = <<table border=\"1\" cellborder=\"0\" cellpadding=\"3\" bgcolor=\"white\">" + nodeContent + "</table>> shape = \"Mrecord\"];\r\n";
foreach (BasicBlock nextBlock in block.NextBlocks)
{
nextNode = methodName + "_" + nextBlock.ToString();
edges += "\"" + nodeName + "\"" + " -> " + "\"" + nextNode + "\";\r\n";
}
}
dotFile.WriteLine(nodes);
dotFile.WriteLine(edges);
dotFile.WriteLine("};");
}
示例15: BuildBlockLinks
/// <summary>
/// Builds the block links.
/// </summary>
/// <param name="block">The current block.</param>
private void BuildBlockLinks(BasicBlock block)
{
for (Context ctx = CreateContext(block); !ctx.EndOfInstruction; ctx.GotoNext())
{
switch (ctx.Instruction.FlowControl)
{
case FlowControl.Next: continue;
case FlowControl.Call: continue;
case FlowControl.Return:
if (!block.NextBlocks.Contains(_epilogue))
LinkBlocks(block, _epilogue);
return;
case FlowControl.Break: goto case FlowControl.Branch;
case FlowControl.Throw: goto case FlowControl.Branch;
case FlowControl.Switch: goto case FlowControl.ConditionalBranch;
case FlowControl.Branch:
{
FindAndLinkBlock(block, ctx.Branch.Targets[0]);
return;
}
case FlowControl.ConditionalBranch:
foreach (int target in ctx.Branch.Targets) {
FindAndLinkBlock(block, target);
}
// Conditional blocks are at least two way branches. The old way of adding jumps didn't properly
// resolve operands under certain circumstances. This does.
int nextIndex = ctx.Index + 1;
if (nextIndex < this.InstructionSet.Used)
{
FindAndLinkBlock(block, this.InstructionSet.Data[nextIndex].Label);
}
continue;
default:
Debug.Assert(false);
break;
}
}
}