Microsoft.Cci.CodeModelToILConverter.ConvertToIL C# (CSharp) Method

ConvertToIL() public method

Traverses the given block of statements in the context of the given method to produce a list of IL operations, exception information blocks (the locations of handlers, filters and finallies) and any private helper types (for example closure classes) that represent the semantics of the given block of statements. The results of the traversal can be retrieved via the GetOperations, GetOperationExceptionInformation and GetPrivateHelperTypes methods.
public ConvertToIL ( IBlockStatement body ) : void
body IBlockStatement A block of statements that are to be converted to IL.
return void
    public virtual void ConvertToIL(IBlockStatement body) {
      ITypeReference returnType = this.method.Type;
      new LabelAndTryBlockAssociater(this.mostNestedTryCatchFor).Traverse(body);
      Contract.Assume(this.StackSize == 0);
      this.Traverse(body);
      var ending = this.StackSize;
      if (this.StackSize != 0) {
        //
        // Put a breakpoint here to find (potential) bugs in the decompiler and/or this traverser's
        // tracking of the stack size. However, it cannot be enforced because when structured code
        // is not completely decompiled, the resulting explicit stack instructions cannot be tracked
        // accurately by this traverser. (Unstructured source code can also lead to this situation.)
        //
        // For instance, the following will result in both pushes being counted, but the stack size
        // should increase only by one.
        //
        // if (c) goto L1;
        // push e;
        // goto L2;
        // L1:
        // push f;
        // L2:
        // an expression containing a pop value
      }
      this.generator.MarkLabel(this.endOfMethod);
      if (this.returnLocal != null) {
        this.LoadLocal(this.returnLocal);
        this.generator.Emit(OperationCode.Ret);
      } else if (returnType.TypeCode == PrimitiveTypeCode.Void && !this.lastStatementWasUnconditionalTransfer)
        this.generator.Emit(OperationCode.Ret);
      this.generator.AdjustBranchSizesToBestFit(eliminateBranchesToNext: true);
    }
  }