コード例 #1
0
        private void SetupPredecessorEdges()
        {
            Contract.Ensures(this.predecessorEdges != null);

            var predecessorEdges = this.predecessorEdges = new List <BasicBlock>(this.cfg.SuccessorEdges.Count);
            MultiHashtable <BasicBlock> blocksThatTarget = new MultiHashtable <BasicBlock>();

            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                foreach (var successor in this.cfg.SuccessorsFor(block))
                {
                    blocksThatTarget.Add(successor.Offset, block);
                }
            }
            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                block.firstPredecessorEdge = predecessorEdges.Count;
                foreach (var predecessor in blocksThatTarget.GetValuesFor(block.Offset))
                {
                    predecessorEdges.Add(predecessor);
                }
                block.predeccessorCount = predecessorEdges.Count - block.firstPredecessorEdge;
            }
        }
コード例 #2
0
        private void SetupDominanceFrontier()
        {
            Contract.Ensures(this.dominanceFrontier != null);
            MultiHashtable <BasicBlock> frontierFor = new MultiHashtable <BasicBlock>();

            if (!this.immediateDominatorsAreInitialized)
            {
                this.SetupImmediateDominators();
            }
            var predecessorEdges = this.predecessorEdges;

            Contract.Assume(predecessorEdges != null);

            var dominanceFrontier = this.dominanceFrontier = new List <BasicBlock>(this.cfg.AllBlocks.Count * 2);

            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                var n = block.predeccessorCount;
                if (n < 2)
                {
                    continue;
                }
                for (int i = 0; i < n; i++)
                {
                    Contract.Assume(block.firstPredecessorEdge + i >= 0);
                    Contract.Assume(block.firstPredecessorEdge + i < predecessorEdges.Count);
                    var pred = predecessorEdges[block.firstPredecessorEdge + i];
                    Contract.Assume(pred != null);
                    var a = pred;
                    while (true)
                    {
                        if (a == block.immediateDominator)
                        {
                            break;                    //Any node that dominates node a will also dominate node block and hence block will not be in its dominance frontier.
                        }
                        frontierFor.Add(a.Offset, block);
                        if (a == a.immediateDominator)
                        {
                            break;                //Since there are multiple roots, block can be its own immediate dominator while still having predecessors.
                        }
                        a = (BasicBlock)a.immediateDominator;
                        Contract.Assume(a != null);
                    }
                }
            }
            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                block.firstDominanceFrontierNode = dominanceFrontier.Count;
                foreach (var frontierNode in frontierFor.GetValuesFor(block.Offset))
                {
                    dominanceFrontier.Add(frontierNode);
                }
                block.dominanceFrontierCount = dominanceFrontier.Count - block.firstDominanceFrontierNode;
            }
            dominanceFrontier.TrimExcess();
        }
コード例 #3
0
ファイル: Errors.cs プロジェクト: sanjayprabhu/Afterthought
 internal MetadataErrorContainer(
     PeReader metadataReader,
     IBinaryDocument binaryDocument
     )
 {
     this.MetadataReader = metadataReader;
     this.BinaryDocument = binaryDocument;
     this.ErrorList      = new MultiHashtable <MetadataReaderErrorMessage>();
 }
コード例 #4
0
        private void SetupDominanceFrontier()
        {
            Contract.Ensures(this.dominanceFrontier != null);
            MultiHashtable <BasicBlock> frontierFor = new MultiHashtable <BasicBlock>();

            if (!this.immediateDominatorsAreInitialized)
            {
                this.SetupImmediateDominators();
            }
            var predecessorEdges = this.predecessorEdges;

            Contract.Assume(predecessorEdges != null);

            var dominanceFrontier = this.dominanceFrontier = new List <BasicBlock>(this.cfg.AllBlocks.Count * 2);

            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                var n = block.predeccessorCount;
                if (n < 2)
                {
                    continue;
                }
                for (int i = 0; i < n; i++)
                {
                    Contract.Assume(block.firstPredecessorEdge + i >= 0);
                    Contract.Assume(block.firstPredecessorEdge + i < predecessorEdges.Count);
                    var pred = predecessorEdges[block.firstPredecessorEdge + i];
                    Contract.Assume(pred != null);
                    var a = pred;
                    while (a != block.immediateDominator)
                    {
                        frontierFor.Add(a.Offset, block);
                        a = (BasicBlock)a.immediateDominator;
                        Contract.Assume(a != null);
                    }
                }
            }
            foreach (var block in this.cfg.AllBlocks)
            {
                Contract.Assume(block != null);
                block.firstDominanceFrontierNode = dominanceFrontier.Count;
                foreach (var frontierNode in frontierFor.GetValuesFor(block.Offset))
                {
                    dominanceFrontier.Add(frontierNode);
                }
                block.dominanceFrontierCount = dominanceFrontier.Count - block.firstDominanceFrontierNode;
            }
            dominanceFrontier.TrimExcess();
        }
コード例 #5
0
ファイル: Core.cs プロジェクト: Refresh06/visualmutator
    uint GetMethodReferenceInternedId(IMethodReference methodReference) {
      Contract.Requires(methodReference != null);

      var genInstanceRef = methodReference as IGenericMethodInstanceReference;
      if (genInstanceRef != null) return this.GetGenericMethodInstanceReferenceInternedKey(genInstanceRef);
      uint containingTypeReferenceInternedId = this.GetTypeReferenceInternId(methodReference.ContainingType);
      uint requiredParameterTypesInternedId = this.GetParameterTypeListInternId(methodReference.Parameters.GetEnumerator());
      uint returnValueCustomModifiersInternedId = 0;
      uint genericParameterCount = methodReference.GenericParameterCount;
      if (methodReference.ReturnValueIsModified)
        returnValueCustomModifiersInternedId = this.GetCustomModifierListInternId(methodReference.ReturnValueCustomModifiers.GetEnumerator());
      uint returnTypeReferenceInternedId = this.GetTypeReferenceInternId(methodReference.Type);
      MultiHashtable<SignatureStore>/*?*/ methods = this.MethodReferenceHashtable.Find(containingTypeReferenceInternedId);
      if (methods == null) {
        methods = new MultiHashtable<SignatureStore>();
        this.MethodReferenceHashtable.Add(containingTypeReferenceInternedId, methods);
      }
      foreach (SignatureStore signatureStore in methods.GetValuesFor((uint)methodReference.Name.UniqueKey)) {
        if (
          signatureStore.CallingConvention == methodReference.CallingConvention
          && signatureStore.RequiredParameterListInternedId == requiredParameterTypesInternedId
          && signatureStore.ReturnValueCustomModifiersListInteredId == returnValueCustomModifiersInternedId
          && signatureStore.ReturnValueIsByRef == methodReference.ReturnValueIsByRef
          && signatureStore.ReturnTypeReferenceInternedId == returnTypeReferenceInternedId
          && signatureStore.GenericParameterCount == genericParameterCount
        ) {
          return signatureStore.InternedId;
        }
      }
      SignatureStore signatureStore1 = new SignatureStore(methodReference.CallingConvention, requiredParameterTypesInternedId,
        0, methodReference.ReturnValueIsByRef, returnValueCustomModifiersInternedId, returnTypeReferenceInternedId, genericParameterCount,
        this.CurrentMethodReferenceInternValue++);
      methods.Add((uint)methodReference.Name.UniqueKey, signatureStore1);
      return signatureStore1.InternedId;
    }
コード例 #6
0
ファイル: Core.cs プロジェクト: Refresh06/visualmutator
 /// <summary>
 /// 
 /// </summary>
 public InternFactory() {
   this.CurrentAssemblyInternValue = 0x00001000;
   this.CurrentMethodReference = Dummy.MethodReference;
   this.CurrentModuleInternValue = 0x00000001;
   this.CurrentNamespaceInternValue = 0x00000001;
   this.CurrentTypeInternValue = 0x00000100;
   this.CurrentTypeListInternValue = 0x00000001;
   this.CurrentCustomModifierInternValue = 0x00000001;
   this.CurrentCustomModifierListInternValue = 0x00000001;
   this.CurrentMethodReferenceInternValue = 0x00000001;
   this.CurrentFieldReferenceInternValue = 0x00000001;
   this.CurrentParameterTypeInternValue = 0x00000001;
   this.CurrentParameterTypeListInternValue = 0x00000001;
   this.CurrentSignatureInternValue = 0x00000001;
   this.AssemblyHashtable = new MultiHashtable<AssemblyStore>();
   this.ModuleHashtable = new MultiHashtable<ModuleStore>();
   this.NestedNamespaceHashtable = new DoubleHashtable();
   this.NamespaceTypeHashtable = new MultiHashtable<NamespaceTypeStore>();
   this.NestedTypeHashtable = new MultiHashtable<NestedTypeStore>();
   this.VectorTypeHashTable = new Hashtable();
   this.PointerTypeHashTable = new Hashtable();
   this.ManagedPointerTypeHashTable = new Hashtable();
   this.MatrixTypeHashtable = new MultiHashtable<MatrixTypeStore>();
   this.TypeListHashtable = new DoubleHashtable();
   this.GenericTypeInstanceHashtable = new DoubleHashtable();
   this.GenericMethodInstanceHashtable = new DoubleHashtable();
   this.GenericTypeParameterHashtable = new DoubleHashtable();
   this.GenericMethodTypeParameterHashTable = new DoubleHashtable();
   this.CustomModifierHashTable = new DoubleHashtable();
   this.CustomModifierListHashTable = new DoubleHashtable();
   this.ParameterTypeHashtable = new MultiHashtable<ParameterTypeStore>();
   this.ParameterTypeListHashtable = new DoubleHashtable();
   this.SignatureHashtable = new MultiHashtable<SignatureStore>();
   this.FunctionTypeHashTable = new Hashtable();
   this.ModifiedTypeHashtable = new DoubleHashtable();
   this.MethodReferenceHashtable = new Hashtable<MultiHashtable<SignatureStore>>();
   this.FieldReferenceHashtable = new Hashtable<DoubleHashtable>();
 }
コード例 #7
0
ファイル: Core.cs プロジェクト: xornand/cci
    uint GetMethodReferenceInternedId(IMethodReference potentiallySpecializedMethodReference) {
      Contract.Requires(potentiallySpecializedMethodReference != null);

      var genInstanceRef = potentiallySpecializedMethodReference as IGenericMethodInstanceReference;
      if (genInstanceRef != null) return this.GetGenericMethodInstanceReferenceInternedKey(genInstanceRef);
      uint containingTypeReferenceInternedId = this.GetTypeReferenceInternId(potentiallySpecializedMethodReference.ContainingType);

      // After constructing the containingTypeReferenceInternedId, perform the rest of the InternId
      // calculation using the unspecialized version of the method reference. This allows
      // the intern keys for methods which have overlapping type parameters to be distinguished
      // if the method parameters are different on the open type. 
      // For instance 
      // interface I<T> {
      //    void Print(T t)
      //    void Print(int t)
      // }
      //
      // We do not want the intern key for I<int>.Print(T) to match that of I<int>.Print(int)
      //  (This is hard to see with ToString, as Cci reports both of these methods to be "I<int>.Print(int)")
      IMethodReference methodReference;
      if (potentiallySpecializedMethodReference is ISpecializedMethodReference)
      {
          methodReference = ((ISpecializedMethodReference)potentiallySpecializedMethodReference).UnspecializedVersion;
      }
      else
      {
          methodReference = potentiallySpecializedMethodReference;
      }
      uint requiredParameterTypesInternedId = this.GetParameterTypeListInternId(methodReference.Parameters.GetEnumerator(), methodReference.ParameterCount);
      uint returnValueCustomModifiersInternedId = 0;
      uint genericParameterCount = methodReference.GenericParameterCount;
      if (methodReference.ReturnValueIsModified)
        returnValueCustomModifiersInternedId = this.GetCustomModifierListInternId(methodReference.ReturnValueCustomModifiers.GetEnumerator());
      uint returnTypeReferenceInternedId = this.GetTypeReferenceInternId(methodReference.Type);
      MultiHashtable<SignatureStore>/*?*/ methods = this.MethodReferenceHashtable.Find(containingTypeReferenceInternedId);
      if (methods == null) {
        methods = new MultiHashtable<SignatureStore>();
        this.MethodReferenceHashtable.Add(containingTypeReferenceInternedId, methods);
      }
      foreach (SignatureStore signatureStore in methods.GetValuesFor((uint)methodReference.Name.UniqueKey)) {
        if (
          signatureStore.CallingConvention == methodReference.CallingConvention
          && signatureStore.RequiredParameterListInternedId == requiredParameterTypesInternedId
          && signatureStore.ReturnValueCustomModifiersListInteredId == returnValueCustomModifiersInternedId
          && signatureStore.ReturnValueIsByRef == methodReference.ReturnValueIsByRef
          && signatureStore.ReturnTypeReferenceInternedId == returnTypeReferenceInternedId
          && signatureStore.GenericParameterCount == genericParameterCount
        ) {
          return signatureStore.InternedId;
        }
      }
      SignatureStore signatureStore1 = new SignatureStore(methodReference.CallingConvention, requiredParameterTypesInternedId,
        0, methodReference.ReturnValueIsByRef, returnValueCustomModifiersInternedId, returnTypeReferenceInternedId, genericParameterCount,
        this.CurrentMethodReferenceInternValue++);
      methods.Add((uint)methodReference.Name.UniqueKey, signatureStore1);
      return signatureStore1.InternedId;
    }
コード例 #8
0
ファイル: Core.cs プロジェクト: xornand/cci
    uint GetNestedTypeReferenceInternId(ITypeReference containingTypeReference, IName typeName, uint genericParameterCount) {
      Contract.Requires(containingTypeReference != null);
      Contract.Requires(typeName != null);

      uint containingTypeReferenceInternedId = this.GetTypeReferenceInternId(containingTypeReference);
      // If there are a large number of specializations of a type nested within a generic type,
      // enumerating through all specializations to find a particular one can take a long time. Therefore,
      // first discriminate based on the containing type.
      MultiHashtable<NestedTypeStore> nestedTypes = this.NestedTypeHashtable.Find(containingTypeReferenceInternedId);
      if (nestedTypes == null) {
        nestedTypes = new MultiHashtable<NestedTypeStore>(2);
        this.NestedTypeHashtable.Add(containingTypeReferenceInternedId, nestedTypes);
      }
      else {
        foreach (NestedTypeStore nstTypeStore in nestedTypes.GetValuesFor((uint)typeName.UniqueKey)) {
          if (nstTypeStore.GenericParameterCount == genericParameterCount) {
            return nstTypeStore.InternedId;
          }
        }
      }

      NestedTypeStore nstTypeStore1 = new NestedTypeStore(genericParameterCount, this.CurrentTypeInternValue++);
      nestedTypes.Add((uint)typeName.UniqueKey, nstTypeStore1);
      return nstTypeStore1.InternedId;
    }
コード例 #9
0
ファイル: Errors.cs プロジェクト: harib/Afterthought
     internal MetadataErrorContainer(
   PeReader metadataReader,
   IBinaryDocument binaryDocument
 )
     {
         this.MetadataReader = metadataReader;
           this.BinaryDocument = binaryDocument;
           this.ErrorList = new MultiHashtable<MetadataReaderErrorMessage>();
     }