OpCodesClassification.cs :  » Aspect-Oriented-Frameworks » Runtime-Assembly-Instrumentation-Library » rail » MSIL » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Aspect Oriented Frameworks » Runtime Assembly Instrumentation Library 
Runtime Assembly Instrumentation Library » rail » MSIL » OpCodesClassification.cs
/*
  The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); 
  you may not use this file except in compliance with the License. You may obtain a copy of the License at 
  http://www.mozilla.org/MPL/ 
  Software distributed under the License is distributed on an "AS IS" basis, 
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language 
  governing rights and limitations under the License. 

  The Original Code is RAIL(Runtime Assembly Instrumentation Library) Alpha Version.
  The Initial Developer of the Original Code is University of Coimbra,
  Computer Science Department, Dependable Systems Group. Copyright (C) University of Coimbra. 
  All Rights Reserved.  
*/
using System;
using System.Reflection.Emit;
using Iesi.Collections;

namespace Rail.MSIL{
  /// <summary>
  /// 
  /// </summary>
  /// <remarks>
  /// The opcodes that have their operands encoded on its name
  /// don't take any argument and therefore are classified as 
  /// OperandType.InlineNone. This is the case of ldarg_0, ldarg_1, ldloc_0 
  /// and so on. But for the purposes of the rail API, these instructions
  /// should be associated with an object of type 
  /// <code>RParameter</code> or <code>LocalVariable</code>, which provide more
  /// information than simply the index of the variable. So, these opcodes should
  /// always be associated with an argument. This means that they should not be
  /// used with the <code>ILNone</code> class, which does not allow for any 
  /// argument. This also means that for the purposes of the Rail API, these Opcodes
  /// should be classified as taking an argument instead of the classification 
  /// made by the .Net Framework. This class provides a suitable classification of 
  /// opcodes for the Rail API.
  /// </remarks>
  public sealed class OpCodesClassifier 
  {
    /// <summary>
    /// Array of OpCodes with no arguments
    /// </summary>
    public static readonly OpCode[] NO_ARGS = new OpCode[] {
                                   OpCodes.Add, OpCodes.Add_Ovf, OpCodes.Add_Ovf_Un, OpCodes.And, 
                                   OpCodes.Arglist, OpCodes.Break, OpCodes.Ceq, OpCodes.Cgt, OpCodes.Cgt_Un, 
                                   OpCodes.Ckfinite, OpCodes.Clt, OpCodes.Clt_Un, OpCodes.Conv_I, OpCodes.Conv_I1, 
                                   OpCodes.Conv_I2, OpCodes.Conv_I4, OpCodes.Conv_I8, OpCodes.Conv_Ovf_I, 
                                   OpCodes.Conv_Ovf_I_Un, OpCodes.Conv_Ovf_I1, OpCodes.Conv_Ovf_I1_Un, 
                                   OpCodes.Conv_Ovf_I2, OpCodes.Conv_Ovf_I2_Un, 
                                   OpCodes.Conv_Ovf_I4, OpCodes.Conv_Ovf_I4_Un, OpCodes.Conv_Ovf_I8, 
                                   OpCodes.Conv_Ovf_I8_Un, OpCodes.Conv_Ovf_U, OpCodes.Conv_Ovf_U_Un, 
                                   OpCodes.Conv_Ovf_U1, OpCodes.Conv_Ovf_U1_Un, OpCodes.Conv_Ovf_U2, 
                                   OpCodes.Conv_Ovf_U2_Un, OpCodes.Conv_Ovf_U4, OpCodes.Conv_Ovf_U4_Un, 
                                   OpCodes.Conv_Ovf_U8, OpCodes.Conv_Ovf_U8_Un, OpCodes.Conv_R_Un, 
                                   OpCodes.Conv_R4, OpCodes.Conv_R8, OpCodes.Conv_U, OpCodes.Conv_U1, 
                                   OpCodes.Conv_U2, OpCodes.Conv_U4, OpCodes.Conv_U8, OpCodes.Cpblk, 
                                   OpCodes.Div, OpCodes.Div_Un, 
                                   OpCodes.Dup, OpCodes.Endfilter, OpCodes.Endfinally, OpCodes.Initblk, 
                                   OpCodes.Ldc_I4_0, OpCodes.Ldc_I4_1, OpCodes.Ldc_I4_2, OpCodes.Ldc_I4_3, 
                                   OpCodes.Ldc_I4_4, OpCodes.Ldc_I4_5, OpCodes.Ldc_I4_6, OpCodes.Ldc_I4_7, 
                                   OpCodes.Ldc_I4_8, OpCodes.Ldc_I4_M1, OpCodes.Ldelem_I, OpCodes.Ldelem_I1, 
                                   OpCodes.Ldelem_I2, OpCodes.Ldelem_I4, OpCodes.Ldelem_I8, OpCodes.Ldelem_R4, 
                                   OpCodes.Ldelem_R8, OpCodes.Ldelem_Ref,OpCodes.Ldelem_U1, OpCodes.Ldelem_U2, 
                                   OpCodes.Ldelem_U4, OpCodes.Ldind_I, OpCodes.Ldind_I1, OpCodes.Ldind_I2, 
                                   OpCodes.Ldind_I4, OpCodes.Ldind_I8, OpCodes.Ldind_R4, OpCodes.Ldind_R8, 
                                   OpCodes.Ldind_Ref, OpCodes.Ldind_U1, OpCodes.Ldind_U2, OpCodes.Ldind_U4, 
                                   OpCodes.Ldlen, OpCodes.Ldnull, OpCodes.Localloc, OpCodes.Mul, OpCodes.Mul_Ovf, 
                                   OpCodes.Mul_Ovf_Un, OpCodes.Neg, OpCodes.Nop, OpCodes.Not, OpCodes.Or, 
                                   OpCodes.Pop, OpCodes.Refanytype, OpCodes.Rem, OpCodes.Rem_Un, OpCodes.Ret, 
                                   OpCodes.Rethrow, OpCodes.Shl, OpCodes.Shr, OpCodes.Shr_Un, OpCodes.Stelem_I, 
                                   OpCodes.Stelem_I1, OpCodes.Stelem_I2, OpCodes.Stelem_I4, OpCodes.Stelem_I8, 
                                   OpCodes.Stelem_R4, OpCodes.Stelem_R8, OpCodes.Stelem_Ref, OpCodes.Stind_I, 
                                   OpCodes.Stind_I1, OpCodes.Stind_I2, OpCodes.Stind_I4, OpCodes.Stind_I8, 
                                   OpCodes.Stind_R4, OpCodes.Stind_R8, OpCodes.Stind_Ref, OpCodes.Sub, 
                                   OpCodes.Sub_Ovf, OpCodes.Sub_Ovf_Un, OpCodes.Tailcall, OpCodes.Throw, 
                                   OpCodes.Volatile, OpCodes.Xor};
    /// <summary>
    /// The HashedSet for the NO_ARGS array
    /// </summary>
    public static readonly HashedSet NO_ARGS_SET = new HashedSet(NO_ARGS);

    /// <summary>
    /// Array of OpCodes of braches
    /// </summary>
    public static readonly OpCode[] BRANCH = new OpCode[] {
                                  OpCodes.Beq, OpCodes.Beq_S, OpCodes.Bge, OpCodes.Bge_S, OpCodes.Bge_Un, 
                                  OpCodes.Bge_Un_S, OpCodes.Bgt, OpCodes.Bgt_S, OpCodes.Bgt_Un, 
                                  OpCodes.Bgt_Un_S, OpCodes.Ble, OpCodes.Ble_S, OpCodes.Ble_Un, OpCodes.Ble_Un_S, 
                                  OpCodes.Blt, OpCodes.Blt_S, OpCodes.Blt_Un, OpCodes.Blt_Un_S, 
                                  OpCodes.Bne_Un, OpCodes.Bne_Un_S, OpCodes.Br, OpCodes.Br_S, OpCodes.Brfalse, 
                                  OpCodes.Brfalse_S, OpCodes.Brtrue, OpCodes.Brtrue_S, OpCodes.Leave, OpCodes.Leave_S
                                };
    /// <summary>
    /// The Set for the BRANCH array
    /// </summary>
    public static readonly Set BRANCH_SET = new HashedSet(BRANCH);

    /// <summary>
    /// Array of OpCodes that work with LocalVariable
    /// </summary>
    public static readonly OpCode[] LOCALS = new OpCode[] {
                                  OpCodes.Ldloc, OpCodes.Ldloc_S, OpCodes.Ldloca, OpCodes.Ldloca_S,
                                  OpCodes.Ldloc_0, OpCodes.Ldloc_1, OpCodes.Ldloc_2, OpCodes.Ldloc_3,
                                  OpCodes.Stloc_S, OpCodes.Stloc,
                                  OpCodes.Stloc_0, OpCodes.Stloc_1, OpCodes.Stloc_2, OpCodes.Stloc_3};
    /// <summary>
    /// The Set for the array of LOCALS
    /// </summary>
    public static readonly Set LOCALS_SET = new HashedSet(LOCALS);

    /// <summary>
    /// The array of OpCodes that work with arguments
    /// </summary>
    public static readonly OpCode[] ARGS = {
                           OpCodes.Ldarg, OpCodes.Ldarg_S, OpCodes.Ldarga, OpCodes.Ldarga_S,
                           OpCodes.Starg, OpCodes.Starg_S,
                           OpCodes.Ldarg_0, OpCodes.Ldarg_1, OpCodes.Ldarg_2, OpCodes.Ldarg_3};
    /// <summary>
    /// The Set for the ARGS array
    /// </summary>
    public static readonly Set ARGS_SET = new HashedSet(ARGS);

    /// <summary>
    /// To verify if the opcode is in NO_ARGS array
    /// </summary>
    /// <param name="op">The OpCode to check</param>
    /// <returns>True if the OpCode is in NO_ARGS array</returns>
    public static bool IsNoArg(OpCode op) 
    {
      return NO_ARGS_SET.Contains(op);
    }

    /// <summary>
    /// To verify if the opcode is in BRANCH array
    /// </summary>
    /// <param name="op">The OpCode to check</param>
    /// <returns>True if the OpCode is in BRANCH array</returns>
    public static bool IsBranch(OpCode op) 
    {
      return BRANCH_SET.Contains(op);
    }

    /// <summary>
    /// To verify if the opcode is in LOCALS array
    /// </summary>
    /// <param name="op">The OpCode to check</param>
    /// <returns>True if the OpCode is in LOCALS array</returns>
    public static bool IsLocalVariable(OpCode op) 
    {
      return LOCALS_SET.Contains(op);
    }

    /// <summary>
    /// To verify if the opcode is in ARGS array
    /// </summary>
    /// <param name="op">The OpCode to check</param>
    /// <returns>True if the OpCode is in ARGS array</returns>
    public static bool IsArgs(OpCode op) 
    {
      return ARGS_SET.Contains(op);
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.