本文整理汇总了C#中InstructionNode.GetOperand方法的典型用法代码示例。如果您正苦于以下问题:C# InstructionNode.GetOperand方法的具体用法?C# InstructionNode.GetOperand怎么用?C# InstructionNode.GetOperand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InstructionNode
的用法示例。
在下文中一共展示了InstructionNode.GetOperand方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Phi
private void Phi(InstructionNode node)
{
//if (Trace.Active) Trace.Log(node.ToString());
var result = GetVariableState(node.Result);
if (result.IsOverDefined)
return;
var sourceBlocks = node.PhiBlocks;
VariableState first = null;
var currentBlock = node.Block;
//if (Trace.Active) Trace.Log("Loop: " + currentBlock.PreviousBlocks.Count.ToString());
for (var index = 0; index < currentBlock.PreviousBlocks.Count; index++)
{
var op = node.GetOperand(index);
var predecessor = sourceBlocks[index];
bool executable = blockStates[predecessor.Sequence];
//if (Trace.Active) Trace.Log("# " + index.ToString() + ": " + predecessor.ToString() + " " + (executable ? "Yes" : "No"));
phiStatements.AddIfNew(predecessor, node);
if (!executable)
continue;
var operand = GetVariableState(op);
//if (Trace.Active) Trace.Log("# " + index.ToString() + ": " + operand.ToString());
if (operand.IsOverDefined)
{
UpdateToOverDefined(result);
return;
}
if (operand.IsConstant)
{
if (first == null)
{
first = operand;
continue;
}
if (!first.AreConstantsEqual(operand))
{
UpdateToOverDefined(result);
return;
}
}
}
if (first != null)
{
UpdateToConstant(result, first.ConstantUnsignedLongInteger);
}
}
示例2: ReplaceOperands
private void ReplaceOperands(InstructionNode node)
{
if (node.Result != null && repl.ContainsKey(node.Result))
node.Result = repl[node.Result];
if (node.Result2 != null && repl.ContainsKey(node.Result2))
node.Result2 = repl[node.Result2];
int count = node.OperandCount;
for (int i = 0; i < count; i++)
{
var operand = node.GetOperand(i);
if (operand != null && repl.ContainsKey(operand))
node.SetOperand(i, repl[operand]);
}
}
示例3: Phi
private void Phi(InstructionNode node)
{
//if (Trace.Active) Trace.Log(node.ToString());
var result = GetVariableState(node.Result);
//UpdateToOverDefined(result); // test
if (result.IsOverDefined)
return;
var sourceBlocks = node.PhiBlocks;
var currentBlock = node.Block;
//if (Trace.Active) Trace.Log("Loop: " + currentBlock.PreviousBlocks.Count.ToString());
for (var index = 0; index < currentBlock.PreviousBlocks.Count; index++)
{
var predecessor = sourceBlocks[index];
phiStatements.AddIfNew(predecessor, node);
bool executable = blockStates[predecessor.Sequence];
//if (Trace.Active) Trace.Log("# " + index.ToString() + ": " + predecessor.ToString() + " " + (executable ? "Yes" : "No"));
if (!executable)
continue;
if (result.IsOverDefined)
continue;
var op = node.GetOperand(index);
var operand = GetVariableState(op);
//if (Trace.Active) Trace.Log("# " + index.ToString() + ": " + operand.ToString());
if (operand.IsOverDefined)
{
UpdateToOverDefined(result);
continue;
}
else if (operand.IsSingleConstant)
{
UpdateToConstant(result, operand.ConstantUnsignedLongInteger);
continue;
}
else if (operand.HasMultipleConstants)
{
foreach (var c in operand.Constants)
{
UpdateToConstant(result, c);
if (result.IsOverDefined)
break;
}
}
}
}
示例4: Map
private Operand Map(Operand operand, Dictionary<Operand, Operand> map, InstructionNode callNode)
{
if (operand == null)
return null;
Operand mappedOperand;
if (map.TryGetValue(operand, out mappedOperand))
{
return mappedOperand;
}
if (operand.IsSymbol)
{
if (operand.StringData != null)
{
mappedOperand = Operand.CreateStringSymbol(operand.Type.TypeSystem, operand.Name, operand.StringData);
}
else if (operand.Method != null)
{
mappedOperand = Operand.CreateSymbolFromMethod(operand.Type.TypeSystem, operand.Method);
}
else if (operand.Name != null)
{
mappedOperand = Operand.CreateManagedSymbol(operand.Type, operand.Name);
}
}
else if (operand.IsParameter)
{
mappedOperand = callNode.GetOperand(operand.Index + 1);
}
else if (operand.IsStackLocal)
{
mappedOperand = MethodCompiler.StackLayout.AddStackLocal(operand.Type);
}
else if (operand.IsVirtualRegister)
{
mappedOperand = MethodCompiler.CreateVirtualRegister(operand.Type);
}
else if (operand.IsField)
{
mappedOperand = Operand.CreateField(operand.Field);
}
else if (operand.IsConstant)
{
mappedOperand = operand;
}
else if (operand.IsCPURegister)
{
mappedOperand = operand;
}
Debug.Assert(mappedOperand != null);
map.Add(operand, mappedOperand);
return mappedOperand;
}
示例5: PerformStaticAllocationOf
private void PerformStaticAllocationOf(InstructionNode allocation, InstructionNode assignment)
{
var allocatedType = (allocation.InvokeMethod != null) ? allocation.InvokeMethod.DeclaringType : allocation.Result.Type;
var assignmentField = assignment.MosaField;
// Get size of type
int typeSize = TypeLayout.GetTypeSize(allocatedType);
// If instruction is newarr then get the size of the element, multiply it by array size, and add array header size
// Also need to align to a 4-byte boundary
if (allocation.Instruction is NewarrInstruction)
{
int elements = GetConstant(allocation.Operand1);
typeSize = (TypeLayout.GetTypeSize(allocatedType.ElementType) * elements) + (TypeLayout.NativePointerSize * 3);
}
// Allocate a linker symbol to refer to this allocation. Use the destination field name as the linker symbol name.
var symbolName = MethodCompiler.Linker.CreateSymbol(assignmentField.FullName + @"<<$cctor", SectionKind.ROData, Architecture.NativeAlignment, typeSize);
// Try to get typeDefinitionSymbol if allocatedType isn't a value type
string typeDefinitionSymbol = GetTypeDefinition(allocatedType);
if (typeDefinitionSymbol != null)
{
MethodCompiler.Linker.Link(LinkType.AbsoluteAddress, PatchType.I4, symbolName, 0, 0, typeDefinitionSymbol, SectionKind.ROData, 0);
}
Operand staticAddress = Operand.CreateManagedSymbol(assignmentField.FieldType, symbolName.Name);
Operand result1 = MethodCompiler.CreateVirtualRegister(assignmentField.FieldType);
//Operand result2 = MethodCompiler.CreateVirtualRegister(assignmentField.FieldType);
// Issue a load request before the newobj and before the assignment.
new Context(allocation).InsertBefore().SetInstruction(CILInstruction.Get(OpCode.Ldc_i4), result1, staticAddress);
assignment.Operand1 = result1;
// If the instruction is a newarr
if (allocation.Instruction is NewarrInstruction)
{
allocation.SetInstruction(CILInstruction.Get(OpCode.Ldc_i4), allocation.Result, result1);
return;
}
//new Context(allocation).InsertBefore().SetInstruction(CILInstruction.Get(OpCode.Ldc_i4), result2, staticAddress);
// Change the newobj to a call and increase the operand count to include the this ptr.
// If the instruction is a newarr, then just replace with a nop instead
allocation.Result = null;
allocation.ResultCount = 0;
allocation.OperandCount++;
for (int i = allocation.OperandCount; i > 0; i--)
{
var op = allocation.GetOperand(i - 1);
allocation.SetOperand(i, op);
}
allocation.Operand1 = result1;
allocation.Instruction = CILInstruction.Get(OpCode.Call);
}