Beispiel #1
0
 private HLLocation ProcessTargetExpression(ITargetExpression pExpression)
 {
     if (pExpression.Definition is ILocalDefinition)
     {
         return(HLLocalLocation.Create(HLDomain.GetLocal(pExpression.Definition as ILocalDefinition)));
     }
     else if (pExpression.Definition is IParameterDefinition)
     {
         HLParameter parameter = HLDomain.GetParameter(pExpression.Definition as IParameterDefinition);
         parameter.RequiresAddressing = true;
         return(HLParameterLocation.Create(parameter));
     }
     else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference)
     {
         IFieldDefinition definition         = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField;
         HLType           typeFieldContainer = HLDomain.GetOrCreateType(definition.Container);
         HLField          field = HLDomain.GetField(definition);
         if (field.IsStatic)
         {
             return(HLStaticFieldLocation.Create(field));
         }
         HLLocation instance = ProcessExpression(pExpression.Instance);
         return(HLFieldLocation.Create(instance, field));
     }
     else if (pExpression.Definition is IAddressDereference)
     {
         IAddressDereference definition      = pExpression.Definition as IAddressDereference;
         HLLocation          locationAddress = ProcessExpression(definition.Address);
         return(HLIndirectAddressLocation.Create(locationAddress, HLDomain.GetOrCreateType(pExpression.Type)));
     }
     throw new NotSupportedException();
 }
 public override void Visit(IAddressDereference addressDereference)
 {
     if (Process(addressDereference))
     {
         visitor.Visit(addressDereference);
     }
     base.Visit(addressDereference);
 }
Beispiel #3
0
        public override void TraverseChildren(IAddressDereference addressDereference)
        {
            base.TraverseChildren(addressDereference);
            IPointerTypeReference /*?*/ pointerTypeReference = addressDereference.Address.Type as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                if (!(pointerTypeReference.TargetType is Dummy))
                {
                    if (addressDereference.Type is Dummy)
                    {
                        ((AddressDereference)addressDereference).Type = pointerTypeReference.TargetType;
                    }
                    else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, pointerTypeReference.TargetType))
                    {
                        var targetPointerType = Immutable.PointerType.GetPointerType(addressDereference.Type, this.host.InternFactory);
                        ((AddressDereference)addressDereference).Address = new Conversion()
                        {
                            ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
                        };
                    }
                    return;
                }
            }
            IManagedPointerTypeReference /*?*/ managedPointerTypeReference = addressDereference.Address.Type as IManagedPointerTypeReference;

            if (managedPointerTypeReference != null)
            {
                if (!(managedPointerTypeReference.TargetType is Dummy))
                {
                    if (addressDereference.Type is Dummy)
                    {
                        ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
                    }
                    else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, managedPointerTypeReference.TargetType))
                    {
                        if (managedPointerTypeReference.TargetType.TypeCode == PrimitiveTypeCode.Boolean && addressDereference.Type.TypeCode == PrimitiveTypeCode.Int8)
                        {
                            ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
                        }
                        else
                        {
                            var targetPointerType = Immutable.ManagedPointerType.GetManagedPointerType(addressDereference.Type, this.host.InternFactory);
                            ((AddressDereference)addressDereference).Address = new Conversion()
                            {
                                ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
                            };
                        }
                    }
                    return;
                }
            }
        }
Beispiel #4
0
 public void Visit(IAddressDereference addressDereference)
 {
     throw new NotImplementedException();
 }
Beispiel #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="addressDereference"></param>
 public AddressDereference(IAddressDereference addressDereference)
     : base(addressDereference)
 {
     this.address = addressDereference.Address;
       if (addressDereference.IsUnaligned)
     this.alignment = addressDereference.Alignment;
       else
     this.alignment = 0;
       this.isVolatile = addressDereference.IsVolatile;
 }
Beispiel #6
0
 public void Visit(IAddressDereference addressDereference)
 {
     this.traverser.Traverse(addressDereference);
 }
Beispiel #7
0
 /// <summary>
 /// Performs some computation with the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public virtual void Visit(IAddressDereference addressDereference)
 {
     this.Visit((IExpression)addressDereference);
 }
        public override void TraverseChildren(IAddressDereference addressDereference)
{ MethodEnter(addressDereference);
            base.TraverseChildren(addressDereference);
     MethodExit();   }
Beispiel #9
0
 /// <summary>
 /// Traverses the address dereference expression.
 /// </summary>
 public void Traverse(IAddressDereference addressDereference)
 {
     Contract.Requires(addressDereference != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(addressDereference);
       if (this.StopTraversal) return;
       this.TraverseChildren(addressDereference);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(addressDereference);
 }
Beispiel #10
0
 /// <summary>
 /// Returns a shallow copy of the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public AddressDereference Copy(IAddressDereference addressDereference)
 {
     return new AddressDereference(addressDereference);
 }
 public override void Visit(IAddressDereference addressDereference)
 {
     if(Process(addressDereference)){visitor.Visit(addressDereference);}
     base.Visit(addressDereference);
 }
Beispiel #12
0
 private void VisitAssignmentTo(IAddressDereference addressDereference)
 {
     if (addressDereference.IsUnaligned)
     this.generator.Emit(OperationCode.Unaligned_, addressDereference.Alignment);
       if (addressDereference.IsVolatile)
     this.generator.Emit(OperationCode.Volatile_);
       OperationCode opcode;
       switch (addressDereference.Type.TypeCode) {
     case PrimitiveTypeCode.Boolean: opcode = OperationCode.Stind_I1; break;
     case PrimitiveTypeCode.Char: opcode = OperationCode.Stind_I2; break;
     case PrimitiveTypeCode.Float32: opcode = OperationCode.Stind_R4; break;
     case PrimitiveTypeCode.Float64: opcode = OperationCode.Stind_R8; break;
     case PrimitiveTypeCode.Int16: opcode = OperationCode.Stind_I2; break;
     case PrimitiveTypeCode.Int32: opcode = OperationCode.Stind_I4; break;
     case PrimitiveTypeCode.Int64: opcode = OperationCode.Stind_I8; break;
     case PrimitiveTypeCode.Int8: opcode = OperationCode.Stind_I1; break;
     case PrimitiveTypeCode.IntPtr: opcode = OperationCode.Stind_I; break;
     case PrimitiveTypeCode.Pointer: opcode = OperationCode.Stind_I; break;
     case PrimitiveTypeCode.UInt16: opcode = OperationCode.Stind_I2; break;
     case PrimitiveTypeCode.UInt32: opcode = OperationCode.Stind_I4; break;
     case PrimitiveTypeCode.UInt64: opcode = OperationCode.Stind_I8; break;
     case PrimitiveTypeCode.UInt8: opcode = OperationCode.Stind_I1; break;
     case PrimitiveTypeCode.UIntPtr: opcode = OperationCode.Stind_I; break;
     default:
       if (addressDereference.Type.IsValueType || addressDereference.Type is IGenericParameterReference) {
     this.generator.Emit(OperationCode.Stobj, addressDereference.Type);
     this.StackSize-=2;
     return;
       }
       opcode = OperationCode.Stind_Ref; break;
       }
       this.generator.Emit(opcode);
       this.StackSize-=2;
 }
Beispiel #13
0
 /// <summary>
 /// Generates IL for the specified address dereference.
 /// </summary>
 /// <param name="addressDereference">The address dereference.</param>
 public override void TraverseChildren(IAddressDereference addressDereference)
 {
     this.Traverse(addressDereference.Address);
       if (addressDereference.IsUnaligned)
     this.generator.Emit(OperationCode.Unaligned_, addressDereference.Alignment);
       if (addressDereference.IsVolatile)
     this.generator.Emit(OperationCode.Volatile_);
       OperationCode opcode;
       switch (addressDereference.Type.TypeCode) {
     case PrimitiveTypeCode.Boolean: opcode = OperationCode.Ldind_U1; break;
     case PrimitiveTypeCode.Char: opcode = OperationCode.Ldind_U2; break;
     case PrimitiveTypeCode.Float32: opcode = OperationCode.Ldind_R4; break;
     case PrimitiveTypeCode.Float64: opcode = OperationCode.Ldind_R8; break;
     case PrimitiveTypeCode.Int16: opcode = OperationCode.Ldind_I2; break;
     case PrimitiveTypeCode.Int32: opcode = OperationCode.Ldind_I4; break;
     case PrimitiveTypeCode.Int64: opcode = OperationCode.Ldind_I8; break;
     case PrimitiveTypeCode.Int8: opcode = OperationCode.Ldind_I1; break;
     case PrimitiveTypeCode.IntPtr: opcode = OperationCode.Ldind_I; break;
     case PrimitiveTypeCode.Pointer: opcode = OperationCode.Ldind_I; break;
     case PrimitiveTypeCode.UInt16: opcode = OperationCode.Ldind_U2; break;
     case PrimitiveTypeCode.UInt32: opcode = OperationCode.Ldind_U4; break;
     case PrimitiveTypeCode.UInt64: opcode = OperationCode.Ldind_I8; break;
     case PrimitiveTypeCode.UInt8: opcode = OperationCode.Ldind_U1; break;
     case PrimitiveTypeCode.UIntPtr: opcode = OperationCode.Ldind_I; break;
     default:
       var ptr = addressDereference.Type as IPointerTypeReference;
       if (ptr != null) {
     opcode = OperationCode.Ldind_I; break;
       } else {
     var mgdPtr = addressDereference.Type as IManagedPointerTypeReference;
     if (mgdPtr != null) {
       opcode = OperationCode.Ldind_I; break;
     }
       }
       //If addressDereference.Type is a reference type, then Ldobj is equivalent to Lind_Ref, but the instruction is larger, so try to avoid it.
       if (addressDereference.Type.IsValueType || addressDereference.Type is IGenericParameterReference) {
     this.generator.Emit(OperationCode.Ldobj, addressDereference.Type);
     return;
       }
       opcode = OperationCode.Ldind_Ref; break;
       }
       this.generator.Emit(opcode);
 }
Beispiel #14
0
 public override void TraverseChildren(IAddressDereference addressDereference) {
   if (addressDereference.Address.Type is IPointerTypeReference || addressDereference.Address.Type.TypeCode == PrimitiveTypeCode.IntPtr ||
     addressDereference.Address is IDupValue || addressDereference.Address is IPopValue)
     this.sourceEmitterOutput.Write("*");
   else {
     var addrOf = addressDereference.Address as IAddressOf;
     if (addrOf != null) {
       this.Traverse(addrOf.Expression);
       return;
     }
   }
   this.Traverse(addressDereference.Address);
 }
Beispiel #15
0
 private void VisitAssignmentTo(IAddressDereference addressDereference) {
   if (addressDereference.IsUnaligned)
     this.generator.Emit(OperationCode.Unaligned_, addressDereference.Alignment);
   if (addressDereference.IsVolatile)
     this.generator.Emit(OperationCode.Volatile_);
   this.StoreIndirect(addressDereference.Type);
 }
Beispiel #16
0
 /// <summary>
 /// Generates IL for the specified address dereference.
 /// </summary>
 /// <param name="addressDereference">The address dereference.</param>
 public override void TraverseChildren(IAddressDereference addressDereference) {
   this.Traverse(addressDereference.Address);
   if (addressDereference.IsUnaligned)
     this.generator.Emit(OperationCode.Unaligned_, addressDereference.Alignment);
   if (addressDereference.IsVolatile)
     this.generator.Emit(OperationCode.Volatile_);
   this.LoadIndirect(addressDereference.Type);
 }
 public virtual void onASTElement(IAddressDereference addressDereference) { }
 public override void TraverseChildren(IAddressDereference addressDereference)
 {
   IBoundExpression be = addressDereference.Address as IBoundExpression;
   if (be != null)
   {
     IParameterDefinition pd = be.Definition as IParameterDefinition;
     if (pd != null)
     {
       this.LoadParameter(pd);
       return;
     }
   }
   this.Traverse(addressDereference.Address);
   return;
 }
Beispiel #19
0
 private HLLocation ProcessAddressDereferenceExpression(IAddressDereference pExpression)
 {
     HLLocation locationAddress = ProcessExpression(pExpression.Address);
     return HLIndirectAddressLocation.Create(locationAddress, HLDomain.GetOrCreateType(pExpression.Type));
 }
Beispiel #20
0
        private HLLocation ProcessAddressDereferenceExpression(IAddressDereference pExpression)
        {
            HLLocation locationAddress = ProcessExpression(pExpression.Address);

            return(HLIndirectAddressLocation.Create(locationAddress, HLDomain.GetOrCreateType(pExpression.Type)));
        }
Beispiel #21
0
 public void Visit(IAddressDereference addressDereference)
 {
     this.result = this.copier.Copy(addressDereference);
 }
Beispiel #22
0
 public override void Visit(IAddressDereference addressDereference)
 {
     allElements.Add(new InvokInfo(Traverser, "IAddressDereference", addressDereference));
 }
Beispiel #23
0
 public virtual void onASTElement(IAddressDereference addressDereference)
 {
 }
 /// <summary>
 /// Rewrites the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public virtual IExpression Rewrite(IAddressDereference addressDereference)
 {
     return addressDereference;
 }
Beispiel #25
0
 /// <summary>
 /// Performs some computation with the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public virtual void Visit(IAddressDereference addressDereference)
 {
 }
 public override void TraverseChildren(IAddressDereference addressDereference) {
   base.TraverseChildren(addressDereference);
   IPointerTypeReference/*?*/ pointerTypeReference = addressDereference.Address.Type as IPointerTypeReference;
   if (pointerTypeReference != null) {
     if (!(pointerTypeReference.TargetType is Dummy)) {
       if (addressDereference.Type is Dummy)
         ((AddressDereference)addressDereference).Type = pointerTypeReference.TargetType;
       else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, pointerTypeReference.TargetType)) {
         var targetPointerType = Immutable.PointerType.GetPointerType(addressDereference.Type, this.host.InternFactory);
         ((AddressDereference)addressDereference).Address = new Conversion() {
           ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
         };
       }
       return;
     }
   }
   IManagedPointerTypeReference/*?*/ managedPointerTypeReference = addressDereference.Address.Type as IManagedPointerTypeReference;
   if (managedPointerTypeReference != null) {
     if (!(managedPointerTypeReference.TargetType is Dummy)) {
       if (addressDereference.Type is Dummy)
         ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
       else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, managedPointerTypeReference.TargetType)) {
         if (managedPointerTypeReference.TargetType.TypeCode == PrimitiveTypeCode.Boolean && addressDereference.Type.TypeCode == PrimitiveTypeCode.Int8)
           ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
         else {
           var targetPointerType = Immutable.ManagedPointerType.GetManagedPointerType(addressDereference.Type, this.host.InternFactory);
           ((AddressDereference)addressDereference).Address = new Conversion() {
             ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
           };
         }
       }
       return;
     }
   }
 }
Beispiel #27
0
 /// <summary>
 /// Traverses the children of the address dereference expression.
 /// </summary>
 public virtual void TraverseChildren(IAddressDereference addressDereference)
 {
     Contract.Requires(addressDereference != null);
       this.TraverseChildren((IExpression)addressDereference);
       if (this.StopTraversal) return;
       this.Traverse(addressDereference.Address);
 }
Beispiel #28
0
    /// <summary>
    /// Returns a deep copy of the given address dereference expression.
    /// </summary>
    /// <param name="addressDereference"></param>
    public AddressDereference Copy(IAddressDereference addressDereference) {
      Contract.Requires(addressDereference != null);
      Contract.Ensures(Contract.Result<AddressDereference>() != null);

      var mutableCopy = this.shallowCopier.Copy(addressDereference);
      mutableCopy.Address = this.Copy(mutableCopy.Address);
      return mutableCopy;
    }
Beispiel #29
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public virtual void Visit(IAddressDereference addressDereference)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(addressDereference);
       this.Visit(addressDereference.Address);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count.
       this.path.Pop();
 }
Beispiel #30
0
    /// <summary>
    /// Returns a shallow copy of the given address dereference expression.
    /// </summary>
    /// <param name="addressDereference"></param>
    public AddressDereference Copy(IAddressDereference addressDereference) {
      Contract.Requires(addressDereference != null);
      Contract.Ensures(Contract.Result<AddressDereference>() != null);

      return new AddressDereference(addressDereference);
    }
Beispiel #31
0
 public void Visit(IAddressDereference addressDereference)
 {
     Contract.Requires(addressDereference != null);
       throw new NotImplementedException();
 }
 /// <summary>
 /// Performs some computation with the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public virtual void Visit(IAddressDereference addressDereference)
 {
 }
 public override void Visit(IAddressDereference addressDereference) {
   IBoundExpression be = addressDereference.Address as IBoundExpression;
   if (be != null) {
     IParameterDefinition pd = be.Definition as IParameterDefinition;
     if (pd != null) {
       var pv = this.sink.FindParameterVariable(pd);
       TranslatedExpressions.Push(Bpl.Expr.Ident(pv));
       return;
     }
   }
   this.Visit(addressDereference.Address);
   throw new NotImplementedException();
 }
Beispiel #34
0
 /// <summary>
 /// Visits the specified address dereference.
 /// </summary>
 /// <param name="addressDereference">The address dereference.</param>
 public override void Visit(IAddressDereference addressDereference)
 {
     AddressDereference mutableAddressDereference  = new AddressDereference(addressDereference);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableAddressDereference);
 }
 public override void TraverseChildren(IAddressDereference addressDereference) {
   if (addressDereference.Address.Type is IPointerTypeReference || addressDereference.Address.Type.TypeCode == PrimitiveTypeCode.IntPtr ||
     addressDereference.Address.Type.TypeCode == PrimitiveTypeCode.UIntPtr ||
     addressDereference.Address is IDupValue || addressDereference.Address is IPopValue) {
     this.sourceEmitterOutput.Write("*");
     var conv = addressDereference.Address as IConversion;
     if (conv != null && (conv.TypeAfterConversion.TypeCode == PrimitiveTypeCode.IntPtr || conv.TypeAfterConversion.TypeCode == PrimitiveTypeCode.UIntPtr)) {
       string type = TypeHelper.GetTypeName(addressDereference.Type, NameFormattingOptions.ContractNullable|NameFormattingOptions.UseTypeKeywords);
       this.sourceEmitterOutput.Write("("+type+"*)");
       this.Traverse(conv.ValueToConvert);
       return;
     }
   } else {
     var addrOf = addressDereference.Address as IAddressOf;
     if (addrOf != null) {
       this.Traverse(addrOf.Expression);
       return;
     }
   }
   this.Traverse(addressDereference.Address);
 }
Beispiel #36
0
 /// <summary>
 /// Returns a deep copy of the given address dereference expression.
 /// </summary>
 /// <param name="addressDereference"></param>
 public AddressDereference Copy(IAddressDereference addressDereference)
 {
     var mutableCopy = this.shallowCopier.Copy(addressDereference);
       mutableCopy.Address = this.Copy(mutableCopy.Address);
       return mutableCopy;
 }
Beispiel #37
0
 public override void TraverseChildren(IAddressDereference addressDereference)
 {
     MethodEnter(addressDereference);
     base.TraverseChildren(addressDereference);
     MethodExit();
 }
Beispiel #38
0
 public void Visit(IAddressDereference addressDereference)
 {
     this.result = this.rewriter.Rewrite(addressDereference);
 }