本文整理汇总了C#中IMethodCompiler类的典型用法代码示例。如果您正苦于以下问题:C# IMethodCompiler类的具体用法?C# IMethodCompiler怎么用?C# IMethodCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMethodCompiler类属于命名空间,在下文中一共展示了IMethodCompiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
var stackTypeForOperand1 = ctx.Operand1.StackType;
var stackTypeForOperand2 = ctx.Operand2.StackType;
if (ctx.Operand1.Type is ValueTypeSigType)
{
var op1Type = compiler.Method.Module.GetType ((ctx.Operand1.Type as ValueTypeSigType).Token);
if (op1Type.BaseType.FullName == "System.Enum")
stackTypeForOperand1 = this.FromSigType (op1Type.Fields[0].SignatureType.Type);
}
if (ctx.Operand2.Type is ValueTypeSigType)
{
var op2Type = compiler.Method.Module.GetType ((ctx.Operand2.Type as ValueTypeSigType).Token);
if (op2Type.BaseType.FullName == "System.Enum")
stackTypeForOperand2 = this.FromSigType (op2Type.Fields[0].SignatureType.Type);
}
var result = _opTable[(int)stackTypeForOperand1][(int)stackTypeForOperand2];
if (result == StackTypeCode.Unknown)
throw new InvalidOperationException (@"Invalid stack result of instruction: " + result.ToString () + " (" + ctx.Operand1.ToString () + ")");
ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
}
示例2: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
StackTypeCode result = StackTypeCode.Unknown;
switch (opcode)
{
case OpCode.Add_ovf_un:
result = _addovfunTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
break;
case OpCode.Sub_ovf_un:
result = _subovfunTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
break;
default:
result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
break;
}
if (StackTypeCode.Unknown == result)
throw new InvalidOperationException(@"Invalid operand types passed to " + opcode);
ctx.Result = compiler.CreateVirtualRegister(Operand.SigTypeFromStackType(result));
}
示例3: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
// Simple result is the same type as the unary argument
ctx.Result = compiler.CreateTemporary(ctx.Operand1.Type);
}
示例4: Validate
/// <summary>
/// Validates the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
ctx.Result = ctx.Operand1;
ctx.Result2 = ctx.Operand1;
}
示例5: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx"></param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
// Validate the typecode & determine the resulting stack type
SigType resultType;
switch (_opcode) {
case OpCode.Conv_u: goto case OpCode.Conv_i;
case OpCode.Conv_i:
resultType = compiler.Architecture.NativeType;
break;
case OpCode.Conv_i1:
resultType = new SigType(CilElementType.I1);
break;
case OpCode.Conv_i2:
resultType = new SigType(CilElementType.I2);
break;
case OpCode.Conv_i4:
resultType = new SigType(CilElementType.I4);
break;
case OpCode.Conv_i8:
resultType = new SigType(CilElementType.I8);
break;
case OpCode.Conv_r4:
resultType = new SigType(CilElementType.R4);
break;
case OpCode.Conv_r8:
resultType = new SigType(CilElementType.R8);
break;
case OpCode.Conv_u1:
resultType = new SigType(CilElementType.U1);
break;
case OpCode.Conv_u2:
resultType = new SigType(CilElementType.U2);
break;
case OpCode.Conv_u4:
resultType = new SigType(CilElementType.U4);
break;
case OpCode.Conv_u8:
resultType = new SigType(CilElementType.U8);
break;
default:
throw new NotSupportedException(@"Overflow checking conversions not supported.");
}
ctx.Result = compiler.CreateTemporary(resultType);
}
示例6: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
Mosa.Runtime.Metadata.Signatures.ArraySigType a = ctx.Operand1.Type as Mosa.Runtime.Metadata.Signatures.ArraySigType;
if (null == a || 1 != a.Rank)
throw new InvalidProgramException(@"Operand to ldlen is not a vector.");
ctx.Result = compiler.CreateTemporary(new SigType(CilElementType.I));
}
示例7: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
SZArraySigType arrayType = ctx.Operand1.Type as SZArraySigType;
if (arrayType == null)
throw new InvalidProgramException(@"Operand to ldlen is not a vector.");
ctx.Result = compiler.CreateTemporary(BuiltInSigType.IntPtr);
}
示例8: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
StackTypeCode result = _opTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
if (result == StackTypeCode.Unknown)
throw new InvalidOperationException(@"Invalid stack result of instruction.");
ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
}
示例9: Run
public static void Run(IMethodCompiler methodCompiler, IPipelineStage stage)
{
Run(
methodCompiler.InternalTrace,
stage,
methodCompiler.Method,
methodCompiler.InstructionSet,
methodCompiler.BasicBlocks
);
}
示例10: Setup
/// <summary>
/// Setups the specified compiler.
/// </summary>
/// <param name="compiler">The compiler.</param>
public void Setup(IMethodCompiler compiler)
{
if (compiler == null)
throw new ArgumentNullException ("compiler");
MethodCompiler = compiler;
InstructionSet = compiler.InstructionSet;
BasicBlocks = compiler.BasicBlocks;
Architecture = compiler.Architecture;
}
示例11:
/// <summary>
/// Setup stage specific processing on the compiler context.
/// </summary>
/// <param name="methodCompiler">The compiler context to perform processing in.</param>
void IMethodCompilerStage.Setup(IMethodCompiler methodCompiler)
{
base.Setup(methodCompiler);
IStackLayoutProvider stackLayoutProvider = methodCompiler.Pipeline.FindFirst<IStackLayoutProvider>();
stackSize = (stackLayoutProvider == null) ? 0 : stackLayoutProvider.LocalsSize;
Debug.Assert((stackSize % 4) == 0, @"Stack size of method can't be divided by 4!!");
}
示例12: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
StackTypeCode result = _operandTable[(int)ctx.Operand1.StackType][(int)ctx.Operand2.StackType];
Debug.Assert(StackTypeCode.Unknown != result, @"Can't shift with the given stack operands.");
if (StackTypeCode.Unknown == result)
throw new InvalidOperationException(@"Invalid stack state for pairing (" + ctx.Operand1.StackType + ", " + ctx.Operand2.StackType + ")");
ctx.Result = compiler.CreateTemporary(Operand.SigTypeFromStackType(result));
}
示例13: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx"></param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
// Validate the operand
StackTypeCode result = _opTable[(int)ctx.Operand1.StackType];
if (StackTypeCode.Unknown == result)
throw new InvalidOperationException(@"Invalid operand to Not instruction.");
ctx.Result = compiler.CreateTemporary(ctx.Operand1.Type);
}
示例14: Validate
/// <summary>
/// Validates the instruction operands and creates a matching variable for the result.
/// </summary>
/// <param name="ctx"></param>
/// <param name="compiler">The compiler.</param>
public override void Validate(Context ctx, IMethodCompiler compiler)
{
base.Validate(ctx, compiler);
// Validate the operand
StackTypeCode result = _typeCodes[(int)ctx.Operand1.StackType];
if (StackTypeCode.Unknown == result)
throw new InvalidOperationException(@"Invalid operand to Neg instruction [" + result + "]");
ctx.Result = compiler.CreateVirtualRegister(ctx.Operand1.Type);
}
示例15: ComputeTypeSize
private static int ComputeTypeSize(TokenTypes token, IMethodCompiler compiler)
{
IMetadataProvider metadata = compiler.Assembly.Metadata;
Metadata.Tables.TypeDefRow typeDefinition;
Metadata.Tables.TypeDefRow followingTypeDefinition;
metadata.Read(token, out typeDefinition);
metadata.Read(token + 1, out followingTypeDefinition);
int result = 0;
TokenTypes fieldList = typeDefinition.FieldList;
while (fieldList != followingTypeDefinition.FieldList)
result += FieldSize(fieldList++, compiler);
return result;
}