Exemple #1
0
 /// <summary>
 /// Allocates an object that is the metadata (IL) level represetation of the body of a method or of a property/event accessor.
 /// </summary>
 /// <param name="generator">An object that provides a way to construct the information needed by a method body. Construction should
 /// be completed by the time the generator is passed to this constructor. The generator is not referenced by the resulting method body.</param>
 /// <param name="localsAreZeroed">True if the locals are initialized by zeroeing the stack upon method entry.</param>
 /// <param name="maxStack">The maximum number of elements on the evaluation stack during the execution of the method.</param>
 /// <param name="methodDefinition">The definition of the method whose body this is.
 /// If this is the body of an event or property accessor, this will hold the corresponding adder/remover/setter or getter method.</param>
 /// <param name="localVariables"></param>
 /// <param name="privateHelperTypes">Any types that are implicitly defined in order to implement the body semantics.
 /// In case of AST to instructions conversion this lists the types produced.
 /// In case of instructions to AST decompilation this should ideally be list of all types
 /// which are local to method.</param>
 public ILGeneratorMethodBody(ILGenerator generator, bool localsAreZeroed, ushort maxStack, IMethodDefinition methodDefinition, 
   IEnumerable<ILocalDefinition> localVariables, IEnumerable<ITypeDefinition> privateHelperTypes) {
   this.localsAreZeroed = localsAreZeroed;
   this.operationExceptionInformation = generator.GetOperationExceptionInformation();
   this.operations = generator.GetOperations();
   this.privateHelperTypes = privateHelperTypes;
   this.generatorScopes = generator.GetLocalScopes();
   this.localVariables = localVariables;
   this.maxStack = maxStack;
   this.methodDefinition = methodDefinition;
 }
 /// <summary>
 /// Allocates an object that is the metadata (IL) level represetation of the body of a method or of a property/event accessor.
 /// </summary>
 /// <param name="generator">An object that provides a way to construct the information needed by a method body. Construction should
 /// be completed by the time the generator is passed to this constructor. The generator is not referenced by the resulting method body.</param>
 /// <param name="localsAreZeroed">True if the locals are initialized by zeroeing the stack upon method entry.</param>
 /// <param name="maxStack">The maximum number of elements on the evaluation stack during the execution of the method.</param>
 /// <param name="methodDefinition">The definition of the method whose body this is.
 /// If this is the body of an event or property accessor, this will hold the corresponding adder/remover/setter or getter method.</param>
 /// <param name="localVariables"></param>
 /// <param name="privateHelperTypes">Any types that are implicitly defined in order to implement the body semantics.
 /// In case of AST to instructions conversion this lists the types produced.
 /// In case of instructions to AST decompilation this should ideally be list of all types
 /// which are local to method.</param>
 public ILGeneratorMethodBody(ILGenerator generator, bool localsAreZeroed, ushort maxStack, IMethodDefinition methodDefinition,
                              IEnumerable <ILocalDefinition> localVariables, IEnumerable <ITypeDefinition> privateHelperTypes)
 {
     this.localsAreZeroed = localsAreZeroed;
     this.operationExceptionInformation = generator.GetOperationExceptionInformation();
     this.operations         = generator.GetOperations();
     this.privateHelperTypes = privateHelperTypes;
     this.generatorScopes    = generator.GetLocalScopes();
     this.localVariables     = localVariables;
     this.maxStack           = maxStack;
     this.methodDefinition   = methodDefinition;
 }
Exemple #3
0
 /// <summary>
 /// Allocates an object that is the metadata (IL) level represetation of the body of a method or of a property/event accessor.
 /// </summary>
 /// <param name="generator">An object that provides a way to construct the information needed by a method body. Construction should
 /// be completed by the time the generator is passed to this constructor. The generator is not referenced by the resulting method body.</param>
 /// <param name="localsAreZeroed">True if the locals are initialized by zeroeing the stack upon method entry.</param>
 /// <param name="maxStack">The maximum number of elements on the evaluation stack during the execution of the method.</param>
 public ILGeneratorMethodBody(ILGenerator generator, bool localsAreZeroed, ushort maxStack) {
   this.localsAreZeroed = localsAreZeroed;
   this.operationExceptionInformation = generator.GetOperationExceptionInformation();
   this.operations = generator.GetOperations();
   this.privateHelperTypes = IteratorHelper.GetEmptyEnumerable<ITypeDefinition>();
   this.generatorScopes = generator.GetLocalScopes();
   List<ILocalDefinition> locals = new List<ILocalDefinition>();
   foreach (var localScope in this.generatorScopes)
     locals.AddRange(localScope.Locals);
   this.localVariables = locals.AsReadOnly();
   this.maxStack = maxStack;
 }
Exemple #4
0
        /// <summary>
        /// Allocates an object that is the metadata (IL) level represetation of the body of a method or of a property/event accessor.
        /// </summary>
        /// <param name="generator">An object that provides a way to construct the information needed by a method body. Construction should
        /// be completed by the time the generator is passed to this constructor. The generator is not referenced by the resulting method body.</param>
        /// <param name="localsAreZeroed">True if the locals are initialized by zeroeing the stack upon method entry.</param>
        /// <param name="maxStack">The maximum number of elements on the evaluation stack during the execution of the method.</param>
        public ILGeneratorMethodBody(ILGenerator generator, bool localsAreZeroed, ushort maxStack)
        {
            this.localsAreZeroed = localsAreZeroed;
            this.operationExceptionInformation = generator.GetOperationExceptionInformation();
            this.operations         = generator.GetOperations();
            this.privateHelperTypes = IteratorHelper.GetEmptyEnumerable <ITypeDefinition>();
            this.generatorScopes    = generator.GetLocalScopes();
            List <ILocalDefinition> locals = new List <ILocalDefinition>();

            foreach (var localScope in this.generatorScopes)
            {
                locals.AddRange(localScope.Locals);
            }
            this.localVariables = locals.AsReadOnly();
            this.maxStack       = maxStack;
        }
        private void ProcessOperations(MethodBody methodBody)
        {
            List<IOperation> operations = methodBody.Operations;
            int count = methodBody.Operations.Count;

            ILGenerator generator = new ILGenerator(this.host, methodBody.MethodDefinition);

            var methodName = MemberHelper.GetMemberSignature(methodBody.MethodDefinition, NameFormattingOptions.SmartTypeName);

            #endregion Pass 2: Emit each operation, along with labels

            #region Retrieve the operations (and the exception information) from the generator
            generator.AdjustBranchSizesToBestFit();
            methodBody.OperationExceptionInformation = new List<IOperationExceptionInformation>(generator.GetOperationExceptionInformation());
            methodBody.Operations = new List<IOperation>(generator.GetOperations());
            #endregion Retrieve the operations (and the exception information) from the generator
            methodBody.MaxStack++;
        }
Exemple #6
0
    /// <summary>
    /// Allocates an object that is the metadata (IL) level represetation of the body of a method or of a property/event accessor.
    /// </summary>
    /// <param name="generator">An object that provides a way to construct the information needed by a method body. Construction should
    /// be completed by the time the generator is passed to this constructor. The generator is not referenced by the resulting method body.</param>
    /// <param name="localsAreZeroed">True if the locals are initialized by zeroeing the stack upon method entry.</param>
    /// <param name="maxStack">The maximum number of elements on the evaluation stack during the execution of the method.</param>
    /// <param name="methodDefinition">The definition of the method whose body this is.
    /// If this is the body of an event or property accessor, this will hold the corresponding adder/remover/setter or getter method.</param>
    /// <param name="localVariables"></param>
    /// <param name="privateHelperTypes">Any types that are implicitly defined in order to implement the body semantics.
    /// In case of AST to instructions conversion this lists the types produced.
    /// In case of instructions to AST decompilation this should ideally be list of all types
    /// which are local to method.</param>
    public ILGeneratorMethodBody(ILGenerator generator, bool localsAreZeroed, ushort maxStack, IMethodDefinition methodDefinition,
      IEnumerable<ILocalDefinition> localVariables, IEnumerable<ITypeDefinition> privateHelperTypes) {
      Contract.Requires(generator != null);
      Contract.Requires(methodDefinition != null);
      Contract.Requires(localVariables != null);
      Contract.Requires(privateHelperTypes != null);

      this.localsAreZeroed = localsAreZeroed;
      this.operationExceptionInformation = generator.GetOperationExceptionInformation();
      this.operations = generator.GetOperations();
      this.privateHelperTypes = privateHelperTypes;
      this.generatorIteratorScopes = generator.GetIteratorScopes();
      this.generatorLocalScopes = generator.GetLocalScopes();
      this.localVariables = localVariables;
      this.maxStack = maxStack;
      this.methodDefinition = methodDefinition;
      this.size = generator.CurrentOffset;
      this.synchronizationInformation = generator.GetSynchronizationInformation();
    }
Exemple #7
0
        /// <summary>
        /// Allocates an object that is the metadata (IL) level represetation of the body of a method or of a property/event accessor.
        /// </summary>
        /// <param name="generator">An object that provides a way to construct the information needed by a method body. Construction should
        /// be completed by the time the generator is passed to this constructor. The generator is not referenced by the resulting method body.</param>
        /// <param name="localsAreZeroed">True if the locals are initialized by zeroeing the stack upon method entry.</param>
        /// <param name="maxStack">The maximum number of elements on the evaluation stack during the execution of the method.</param>
        /// <param name="methodDefinition">The definition of the method whose body this is.
        /// If this is the body of an event or property accessor, this will hold the corresponding adder/remover/setter or getter method.</param>
        /// <param name="localVariables"></param>
        /// <param name="privateHelperTypes">Any types that are implicitly defined in order to implement the body semantics.
        /// In case of AST to instructions conversion this lists the types produced.
        /// In case of instructions to AST decompilation this should ideally be list of all types
        /// which are local to method.</param>
        public ILGeneratorMethodBody(ILGenerator generator, bool localsAreZeroed, ushort maxStack, IMethodDefinition methodDefinition,
                                     IEnumerable <ILocalDefinition> localVariables, IEnumerable <ITypeDefinition> privateHelperTypes)
        {
            Contract.Requires(generator != null);
            Contract.Requires(methodDefinition != null);
            Contract.Requires(localVariables != null);
            Contract.Requires(privateHelperTypes != null);

            this.localsAreZeroed = localsAreZeroed;
            this.operationExceptionInformation = generator.GetOperationExceptionInformation();
            this.operations              = generator.GetOperations();
            this.privateHelperTypes      = privateHelperTypes;
            this.generatorIteratorScopes = generator.GetIteratorScopes();
            this.generatorLocalScopes    = generator.GetLocalScopes();
            this.localVariables          = localVariables;
            this.maxStack                   = maxStack;
            this.methodDefinition           = methodDefinition;
            this.size                       = generator.CurrentOffset;
            this.synchronizationInformation = generator.GetSynchronizationInformation();
        }