本文整理汇总了C#中IR类的典型用法代码示例。如果您正苦于以下问题:C# IR类的具体用法?C# IR怎么用?C# IR使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IR类属于命名空间,在下文中一共展示了IR类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AllocateRegisters
public List<int> AllocateRegisters(Stack<int> registers, IR.MethodEntry method)
{
List<int> used = new List<int>();
Dictionary<int, int> usageCount = new Dictionary<int, int>();
foreach (IR.InstructionElement i in method.Childnodes)
AllocateRegistersRecursive(i, registers, method, used, usageCount);
return used;
}
开发者ID:kenkendk,项目名称:ac3il,代码行数:10,代码来源:SimpleAllocator.cs
示例2: AllocateRegistersRecursive
public void AllocateRegistersRecursive(IR.InstructionElement current, Stack<int> registers, IR.MethodEntry method, List<int> used, Dictionary<int, int> usageCount)
{
//Does this instruction have an output?
if (current.Register != null)
{
//Have we already assigned a register?
if (current.Register.RegisterNumber < 0 && registers.Count > 0)
{
int regno = registers.Pop();
used.Add(regno);
usageCount.Add(regno, 0);
current.Register.RegisterNumber = regno;
}
if (current.Register.RegisterNumber > 0 && usageCount.ContainsKey(current.Register.RegisterNumber))
usageCount[current.Register.RegisterNumber]++;
//Assign the target register to the child node
if (current.Register.RegisterNumber > 0 && current.Childnodes.Length != 0 && current.Childnodes[0].Register != null)
current.Childnodes[0].Register = current.Register;
}
foreach (IR.InstructionElement i in current.Childnodes)
AllocateRegistersRecursive(i, registers, method, used, usageCount);
foreach(IR.InstructionElement i in current.Childnodes)
if (i.Register != null && usageCount.ContainsKey(i.Register.RegisterNumber))
{
usageCount[i.Register.RegisterNumber]--;
if (usageCount[i.Register.RegisterNumber] == 0)
{
usageCount.Remove(i.Register.RegisterNumber);
registers.Push(i.Register.RegisterNumber);
}
}
/*if (current.Register != null && current.Register.RegisterNumber > 0 && usageCount.ContainsKey(current.Register.RegisterNumber))
{
usageCount[current.Register.RegisterNumber]--;
if (usageCount[current.Register.RegisterNumber] == 0)
{
usageCount.Remove(current.Register.RegisterNumber);
registers.Push(current.Register.RegisterNumber);
}
}*/
}
开发者ID:kenkendk,项目名称:ac3il,代码行数:48,代码来源:SimpleAllocator.cs
示例3: Endfilter
/// <summary>
/// Implements the 'endfilter' IL instruction.
/// </summary>
private void Endfilter (IR.Instructions.Endfilter instruction)
{
IR.Operands.Register value = instruction.Use [0] as IR.Operands.Register;
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (R32.ESP, this.GetExceptionHandlingSPSlot);
this.assembly.RET ();
}
开发者ID:sharpos,项目名称:SharpOS,代码行数:16,代码来源:IR.cs
示例4: SetInstruction
/// <summary>
/// Sets the instruction.
/// </summary>
/// <param name="instruction">The instruction.</param>
/// <param name="code">The code.</param>
/// <param name="block">The block.</param>
public void SetInstruction(IInstruction instruction, IR.ConditionCode code, BasicBlock block)
{
SetInstruction(instruction);
ConditionCode = code;
SetBranch(block);
}
开发者ID:illuminus86,项目名称:MOSA-Project,代码行数:12,代码来源:Context.cs
示例5: 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);
}
开发者ID:illuminus86,项目名称:MOSA-Project,代码行数:11,代码来源:Context.cs
示例6: Optimize
public void Optimize(IR.MethodEntry method, OptimizationLevel level)
{
throw new InvalidOperationException("The register allocator must be invoked via the IRegisterAllocator interface instead of the IOptimizer interface");
}
开发者ID:kenkendk,项目名称:ac3il,代码行数:4,代码来源:SimpleAllocator.cs
示例7: CreateBinaryOperationIC
public static void CreateBinaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, mdr.ValueTypes i1Type, bool i0TypeCheck, bool i1TypeCheck)
{
ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex);
var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf);
ilGen.Ldarg_CallFrame();
ilGen.Ldfld(CodeGen.Types.CallFrame.Values);
ilGen.Stloc(values);
///Try to make a better guess on the unknown types.
if (i0Type == mdr.ValueTypes.DValueRef)
{
if (i1Type != mdr.ValueTypes.DValueRef)
i0Type = i1Type;
else
i0Type = i1Type = mdr.ValueTypes.Int32; //Just a guess!
}
else if (i1Type == mdr.ValueTypes.DValueRef)
i1Type = i0Type;
var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
//if (i0TypeCheck)
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(CodeGen.Types.DValue.GetValueType);
ilGen.Stloc(t0);
}
var t1 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
//if (i0TypeCheck)
{
LoadValue(ilGen, values, resultIndex + 1, mdr.ValueTypes.DValueRef);
ilGen.Call(CodeGen.Types.DValue.GetValueType);
ilGen.Stloc(t1);
}
var guardFail = ilGen.DefineLabel();
var done = ilGen.DefineLabel();
ilGen.Ldloc(t0);
ilGen.Ldc_I4(8);
ilGen.Shl();
ilGen.Ldloc(t1);
ilGen.Or();
ilGen.Ldc_I4(((int)i0Type << 8) | (int)i1Type);
ilGen.Bne_Un(guardFail);
var operation = CodeGen.Types.Operations.Binary.Get(nodeType);
var mi = operation.Get(i0Type, i1Type);
var returnType = operation.ReturnType(i0Type, i1Type);
if (returnType == mdr.ValueTypes.DValueRef)
{
Debug.Assert(mi.GetParameters().Length == 3 && mi.GetParameters()[2].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a third parameter of type 'ref DValue'", mi);
LoadValue(ilGen, values, resultIndex, i0Type);
LoadValue(ilGen, values, resultIndex + 1, i1Type);
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(mi);
}
else
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
LoadValue(ilGen, values, resultIndex, i0Type);
LoadValue(ilGen, values, resultIndex + 1, i1Type);
ilGen.Call(mi);
ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType));
}
ilGen.Br(done);
ilGen.MarkLabel(guardFail);
ilGen.Ldarg_CallFrame();
ilGen.Ldarg_1();
ilGen.Ldc_I4((int)nodeType);
ilGen.Ldc_I4(resultIndex);
ilGen.Ldloc(t0);
ilGen.Ldloc(t1);
ilGen.Ldc_I4(i0TypeCheck);
ilGen.Ldc_I4(i1TypeCheck);
ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateBinaryOperationIC);
ilGen.Ret();
ilGen.MarkLabel(done);
}
开发者ID:reshadi2,项目名称:mcjs,代码行数:82,代码来源:ICMethods.cs
示例8: Ldind
/// <summary>
/// Implements the ldind.* family of instructions
/// </summary>
private void Ldind (IR.Instructions.Ldind instruction)
{
IR.Operands.Register assignee = instruction.Def as IR.Operands.Register;
IR.Operands.Register register = instruction.Use [0] as IR.Operands.Register;
if (register.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (register.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (register)));
switch (instruction.InternalType) {
case InternalType.I1:
this.assembly.MOVSX (R32.EAX, new ByteMemory (null, R32.EAX, null, 0));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.U1:
this.assembly.MOVZX (R32.EAX, new ByteMemory (null, R32.EAX, null, 0));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.I2:
this.assembly.MOVSX (R32.EAX, new WordMemory (null, R32.EAX, null, 0));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.U2:
this.assembly.MOVZX (R32.EAX, new WordMemory (null, R32.EAX, null, 0));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.O:
case InternalType.I:
case InternalType.I4:
case InternalType.U4:
case InternalType.SZArray:
case InternalType.Array:
this.assembly.MOV (R32.EAX, new DWordMemory (null, R32.EAX, null, 0));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.I8:
case InternalType.U8:
Memory address = this.GetAddress (assignee);
address.DisplacementDelta = 4;
this.assembly.MOV (R32.EDX, R32.EAX);
this.assembly.ADD (R32.EDX, 4);
this.assembly.MOV (R32.EAX, new DWordMemory (null, R32.EAX, null, 0));
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
this.assembly.MOV (R32.EAX, new DWordMemory (null, R32.EDX, null, 0));
this.assembly.MOV (new DWordMemory (address), R32.EAX);
break;
case InternalType.R4:
case InternalType.R8:
case InternalType.F:
case InternalType.ValueType:
case InternalType.M:
case InternalType.U:
case InternalType.TypedReference:
default:
throw new NotImplementedEngineException ("Ldind not supported for InternalType." + instruction.InternalType);
//.........这里部分代码省略.........
开发者ID:sharpos,项目名称:SharpOS,代码行数:101,代码来源:IR.cs
示例9: Ldc
/// <summary>
/// Implements the 'ldc.*' family of IL instructions.
/// </summary>
private void Ldc (IR.Instructions.Ldc instruction)
{
IR.Operands.Register assignee = instruction.Def as IR.Operands.Register;
switch (assignee.InternalType) {
case InternalType.I4:
uint intConstant = (uint) (instruction.Use [0] as IntConstant).Value;
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), intConstant);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), intConstant);
break;
case InternalType.I8:
ulong longConstant = (ulong) (instruction.Use [0] as LongConstant).Value;
uint hiValue = (uint) (longConstant >> 32);
uint loValue = (uint) (longConstant & 0xFFFFFFFF);
Memory address = this.GetAddress (assignee);
address.DisplacementDelta = 4;
this.assembly.MOV (new DWordMemory (address), hiValue);
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), loValue);
break;
default:
throw new NotImplementedEngineException ("LDC of " + assignee.InternalType + " not supported yet");
}
}
开发者ID:sharpos,项目名称:SharpOS,代码行数:36,代码来源:IR.cs
示例10: Initialize
private void Initialize (IR.Operands.Identifier identifier)
{
int size = this.method.Engine.GetTypeSize (identifier.TypeFullName, 4) / 4;
if (size == 1) {
this.assembly.XOR (R32.EAX, R32.EAX);
if (identifier.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (identifier.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (identifier)), R32.EAX);
} else {
this.assembly.PUSH (R32.ECX);
this.assembly.PUSH (R32.EDI);
this.assembly.XOR (R32.EAX, R32.EAX);
if (identifier.IsRegisterSet)
this.assembly.MOV (R32.EDI, Assembly.GetRegister (identifier.Register));
else
this.assembly.LEA (R32.EDI, new DWordMemory (this.GetAddress (identifier)));
this.assembly.MOV (R32.ECX, (uint) size);
this.assembly.CLD ();
this.assembly.REP ();
this.assembly.STOSD ();
this.assembly.POP (R32.EDI);
this.assembly.POP (R32.ECX);
}
}
开发者ID:sharpos,项目名称:SharpOS,代码行数:33,代码来源:IR.cs
示例11: GetAssemblyStubMemoryAddress
/// <summary>
/// Creates an instance of the Memory class which has been used in the kernel to interact with the Asm stubs.
/// In the example "Asm.MOV (R32.EAX, new Memory (...))", the AOT emulates the instantiation of the Memory
/// parameter at compile-time, instead of literally translating the 'newobj' and constructor calls into the
/// encoded result.
/// </summary>
private Memory GetAssemblyStubMemoryAddress (IR.Instructions.Newobj call)
{
if (call.Use.Length == 1) {
string parameter = (Operand.GetNonRegister (call.Use [0], typeof (StringConstant)) as SharpOS.AOT.IR.Operands.StringConstant).Value;
if (call.Method.Class.TypeFullName.EndsWith (".Memory")) {
return new Memory (parameter);
} else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) {
return new ByteMemory (parameter);
} else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) {
return new WordMemory (parameter);
} else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) {
return new DWordMemory (parameter);
} else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) {
return new QWordMemory (parameter);
} else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) {
return new TWordMemory (parameter);
} else {
throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported.");
}
} else if (call.Use.Length == 2) {
SegType segment = Seg.GetByID ((Operand.GetNonRegister (call.Use [0], typeof (FieldOperand)) as FieldOperand).ShortFieldTypeName);
string label = (Operand.GetNonRegister (call.Use [1], typeof (StringConstant)) as SharpOS.AOT.IR.Operands.StringConstant).Value;
if (call.Method.Class.TypeFullName.EndsWith (".Memory")) {
return new Memory (segment, label);
} else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) {
return new ByteMemory (segment, label);
} else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) {
return new WordMemory (segment, label);
} else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) {
return new DWordMemory (segment, label);
} else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) {
return new QWordMemory (segment, label);
} else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) {
return new TWordMemory (segment, label);
} else {
throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported.");
}
} else if (call.Use.Length == 3) {
SegType segment = Seg.GetByID (Operand.GetNonRegister (call.Use [0], typeof (FieldOperand)));
R16Type _base = R16.GetByID (Operand.GetNonRegister (call.Use [1], typeof (FieldOperand)));
R16Type index = R16.GetByID (Operand.GetNonRegister (call.Use [2], typeof (FieldOperand)));
if (call.Method.Class.TypeFullName.EndsWith (".Memory")) {
return new Memory (segment, _base, index);
} else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) {
return new ByteMemory (segment, _base, index);
} else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) {
return new WordMemory (segment, _base, index);
} else if (call.Method.Class.TypeFullName.EndsWith (".DWordMemory")) {
return new DWordMemory (segment, _base, index);
} else if (call.Method.Class.TypeFullName.EndsWith (".QWordMemory")) {
return new QWordMemory (segment, _base, index);
} else if (call.Method.Class.TypeFullName.EndsWith (".TWordMemory")) {
return new TWordMemory (segment, _base, index);
} else {
throw new EngineException ("'" + call.Method.Class.TypeFullName + "' is not supported.");
}
} else if (call.Use.Length == 4) {
if (call.Method.Arguments [1].TypeFullName.IndexOf ("16") != -1) {
SegType segment = Seg.GetByID (Operand.GetNonRegister (call.Use [0], typeof (FieldOperand)));
R16Type _base = R16.GetByID (Operand.GetNonRegister (call.Use [1], typeof (FieldOperand)));
R16Type index = R16.GetByID (Operand.GetNonRegister (call.Use [2], typeof (FieldOperand)));
Int16 displacement = System.Convert.ToInt16 ((Operand.GetNonRegister (call.Use [3], typeof (IntConstant)) as IntConstant).Value);
if (call.Method.Class.TypeFullName.EndsWith (".Memory")) {
return new Memory (segment, _base, index, displacement);
} else if (call.Method.Class.TypeFullName.EndsWith (".ByteMemory")) {
return new ByteMemory (segment, _base, index, displacement);
} else if (call.Method.Class.TypeFullName.EndsWith (".WordMemory")) {
//.........这里部分代码省略.........
开发者ID:sharpos,项目名称:SharpOS,代码行数:101,代码来源:IR.cs
示例12: Throw
/// <summary>
/// Implements the 'throw' IL instruction, which throws an exception. The bulk of the
/// work performed by this instruction is delegated to the kernel's runtime.
/// </summary>
private void Throw (IR.Instructions.Throw instruction)
{
if (instruction.Use != null && instruction.Use.Length == 1) {
IR.Operands.Register value = instruction.Use [0] as IR.Operands.Register;
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
} else
// This is for when rethrowing an exception
this.assembly.MOV (R32.EAX, this.GetExceptionHandlingExceptionObjectSlot);
this.assembly.PUSH (R32.EAX);
this.assembly.CALL (this.assembly.Engine.Throw.AssemblyLabel);
this.assembly.ADD (R32.ESP, 4);
}
开发者ID:sharpos,项目名称:SharpOS,代码行数:22,代码来源:IR.cs
示例13: Break
/// <summary>
/// Implements the 'break' IL instruction.
/// </summary>
private void Break (IR.Instructions.Break instruction)
{
// Does nothing, perhaps emit a label?
}
开发者ID:sharpos,项目名称:SharpOS,代码行数:7,代码来源:IR.cs
示例14: GetOppositeConditionCode
/// <summary>
/// Gets the opposite condition code.
/// </summary>
/// <param name="conditionCode">The condition code.</param>
/// <returns></returns>
protected IR.ConditionCode GetOppositeConditionCode(IR.ConditionCode conditionCode)
{
switch (conditionCode) {
case IR.ConditionCode.Equal: return IR.ConditionCode.NotEqual;
case IR.ConditionCode.NotEqual: return IR.ConditionCode.Equal;
case IR.ConditionCode.GreaterOrEqual: return IR.ConditionCode.LessThan;
case IR.ConditionCode.GreaterThan: return IR.ConditionCode.LessOrEqual;
case IR.ConditionCode.LessOrEqual: return IR.ConditionCode.UnsignedLessOrEqual;
case IR.ConditionCode.LessThan: return IR.ConditionCode.GreaterOrEqual;
case IR.ConditionCode.UnsignedGreaterOrEqual: return IR.ConditionCode.UnsignedLessThan;
case IR.ConditionCode.UnsignedGreaterThan: return IR.ConditionCode.UnsignedLessOrEqual;
case IR.ConditionCode.UnsignedLessOrEqual: return IR.ConditionCode.UnsignedGreaterThan;
case IR.ConditionCode.UnsignedLessThan: return IR.ConditionCode.UnsignedGreaterOrEqual;
case IR.ConditionCode.Signed: return IR.ConditionCode.NotSigned;
case IR.ConditionCode.NotSigned: return IR.ConditionCode.Signed;
default: throw new NotSupportedException();
}
}
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:23,代码来源:BaseStage.cs
示例15: CreateUnaryOperationIC
public static void CreateUnaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, bool i0TypeCheck)
{
ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex);
var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf);
ilGen.Ldarg_CallFrame();
ilGen.Ldfld(CodeGen.Types.CallFrame.Values);
ilGen.Stloc(values);
var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
//if (i0TypeCheck)
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(CodeGen.Types.DValue.GetValueType);
ilGen.Stloc(t0);
}
var guardFail = ilGen.DefineLabel();
var done = ilGen.DefineLabel();
var operation = CodeGen.Types.Operations.Unary.Get(nodeType);
if (i0Type == mdr.ValueTypes.DValueRef) //Just a better guess!
i0Type = operation.ReturnType(i0Type); //we will need to repeat the lookup again
ilGen.Ldloc(t0);
ilGen.Ldc_I4((int)i0Type);
ilGen.Bne_Un(guardFail);
var mi = operation.Get(i0Type);
var returnType = operation.ReturnType(i0Type);
if (returnType == mdr.ValueTypes.DValueRef)
{
Debug.Assert(mi.GetParameters().Length == 2 && mi.GetParameters()[1].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a second parameter of type 'ref DValue'", mi);
LoadValue(ilGen, values, resultIndex, i0Type);
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
ilGen.Call(mi);
}
else
{
LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
LoadValue(ilGen, values, resultIndex, i0Type);
ilGen.Call(mi);
ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType));
}
ilGen.Br(done);
ilGen.MarkLabel(guardFail);
ilGen.Ldarg_CallFrame();
ilGen.Ldarg_1();
ilGen.Ldc_I4((int)nodeType);
ilGen.Ldc_I4(resultIndex);
ilGen.Ldloc(t0);
ilGen.Ldc_I4(i0TypeCheck);
ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateUnaryOperationIC);
ilGen.Ret();
ilGen.MarkLabel(done);
}
开发者ID:reshadi2,项目名称:mcjs,代码行数:60,代码来源:ICMethods.cs
示例16: Load
/// <summary>
/// Common implementation for IL instructions which load a value onto the IL evaluation stack.
/// </summary>
private void Load (IR.Operands.Register assignee, InternalType sourceType, Memory memory)
{
switch (sourceType) {
case InternalType.I1:
this.assembly.MOVSX (R32.EAX, new ByteMemory (memory));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.U1:
this.assembly.MOVZX (R32.EAX, new ByteMemory (memory));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.I2:
this.assembly.MOVSX (R32.EAX, new WordMemory (memory));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.U2:
this.assembly.MOVZX (R32.EAX, new WordMemory (memory));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.I4:
case InternalType.U4:
case InternalType.I:
case InternalType.U:
case InternalType.O:
case InternalType.M:
case InternalType.SZArray:
case InternalType.Array:
this.assembly.MOV (R32.EAX, new DWordMemory (memory));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
break;
case InternalType.I8:
case InternalType.U8:
DWordMemory source = new DWordMemory (memory);
source.DisplacementDelta = 4;
Memory destination = this.GetAddress (assignee);
destination.DisplacementDelta = 4;
this.assembly.MOV (R32.EAX, new DWordMemory (memory));
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
this.assembly.MOV (R32.EAX, new DWordMemory (source));
this.assembly.MOV (new DWordMemory (destination), R32.EAX);
break;
case InternalType.ValueType:
uint size = (uint) assignee.Type.Size;
if (size == 4) {
this.assembly.MOV (R32.EAX, new DWordMemory (memory));
if (assignee.IsRegisterSet)
this.assembly.MOV (Assembly.GetRegister (assignee.Register), R32.EAX);
else
this.assembly.MOV (new DWordMemory (this.GetAddress (assignee)), R32.EAX);
} else {
this.assembly.PUSH (R32.ECX);
this.assembly.PUSH (R32.ESI);
this.assembly.PUSH (R32.EDI);
this.assembly.LEA (R32.ESI, new DWordMemory (memory));
//.........这里部分代码省略.........
开发者ID:sharpos,项目名称:SharpOS,代码行数:101,代码来源:IR.cs
示例17: RunAndUpdateBinaryOperationIC
public static int RunAndUpdateBinaryOperationIC(ref mdr.CallFrame callFrame, int index, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, mdr.ValueTypes i1Type, bool i0TypeCheck, bool i1TypeCheck)
{
var ilGen = JSRuntime.Instance.AsmGenerator.GetILGenerator();
var funcMetadata = callFrame.Function.Metadata;
var methodName = funcMetadata.FullName + "__" + index.ToString();
ilGen.BeginICMethod(methodName);
CreateBinaryOperationIC(ilGen, nodeType, resultIndex, i0Type, i1Type, i0TypeCheck, i1TypeCheck);
ilGen.Ldc_I4(index + 1);
ilGen.Ret();
ilGen.WriteComment("Reinstalling this at index {0}", index);
var m = ilGen.EndICMethod((JSFunctionMetadata)funcMetadata);
funcMetadata.InlineCache[index] = m;
return m(ref callFrame, index);
}
开发者ID:reshadi2,项目名称:mcjs,代码行数:15,代码来源:ICMethods.cs
示例18: Save
/// <summary>
/// Common implementations which pop a value from the IL evaluation stack and save it in another means
/// of storage (such as stloc, stind, starg).
/// </summary>
private void Save (Class _class, InternalType destinationType, Memory memory, IR.Operands.Register value)
{
switch (destinationType) {
case InternalType.I1:
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new ByteMemory (memory), R8.AL);
break;
case InternalType.U1:
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new ByteMemory (memory), R8.AL);
break;
case InternalType.I2:
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new WordMemory (memory), R16.AX);
break;
case InternalType.U2:
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new WordMemory (memory), R16.AX);
break;
case InternalType.I4:
case InternalType.U4:
case InternalType.I:
case InternalType.U:
case InternalType.O:
case InternalType.SZArray:
case InternalType.Array:
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new DWordMemory (memory), R32.EAX);
break;
case InternalType.I8:
case InternalType.U8:
Memory source = this.GetAddress (value);
source.DisplacementDelta = 4;
DWordMemory destination = new DWordMemory (memory);
destination.DisplacementDelta = 4;
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new DWordMemory (memory), R32.EAX);
this.assembly.MOV (R32.EAX, new DWordMemory (source));
this.assembly.MOV (new DWordMemory (destination), R32.EAX);
break;
case InternalType.ValueType:
uint size = (uint) this.method.Engine.GetTypeSize (_class.TypeFullName, 4);
if (size == 4) {
if (value.IsRegisterSet)
this.assembly.MOV (R32.EAX, Assembly.GetRegister (value.Register));
else
this.assembly.MOV (R32.EAX, new DWordMemory (this.GetAddress (value)));
this.assembly.MOV (new DWordMemory (memory), R32.EAX);
} else {
this.assembly.PUSH (R32.ECX);
this.assembly.PUSH (R32.ESI);
this.assembly.PUSH (R32.EDI);
if (value.IsRegisterSet)
//.........这里部分代码省略.........
开发者ID:sharpos,项目名称:SharpOS,代码行数:101,代码来源:IR.cs
示例19: Optimize
public void Optimize(IR.MethodEntry method, OptimizationLevel level)
{
foreach (var op in method.FlatInstructionList)
op.IsIndexChecked = true;
}
开发者ID:kenkendk,项目名称:ac3il,代码行数:5,代码来源:IndexBoundsRemoval.cs
示例20: GetConditionString
/// <summary>
/// Gets the condition string.
/// </summary>
/// <param name="conditioncode">The conditioncode.</param>
/// <returns></returns>
protected string GetConditionString(IR.ConditionCode conditioncode)
{
switch (conditioncode) {
case IR.ConditionCode.Equal: return @"equal";
case IR.ConditionCode.GreaterOrEqual: return @"greater or equal";
case IR.ConditionCode.GreaterThan: return @"greater";
case IR.ConditionCode.LessOrEqual: return @"less or equal";
case IR.ConditionCode.LessThan: return @"less";
case IR.ConditionCode.NotEqual: return @"not equal";
case IR.ConditionCode.UnsignedGreaterOrEqual: return @"greater or equal (U)";
case IR.ConditionCode.UnsignedGreaterThan: return @"greater (U)";
case IR.ConditionCode.UnsignedLessOrEqual: return @"less or equal (U)";
case IR.ConditionCode.UnsignedLessThan: return @"less (U)";
case IR.ConditionCode.NotSigned: return @"unsigned";
case IR.ConditionCode.Signed: return @"signed";
default: throw new NotSupportedException();
}
}
开发者ID:shanebrown99,项目名称:MOSA-Project,代码行数:23,代码来源:BaseInstruction.cs
注:本文中的IR类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论