示例#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();
 }
示例#2
0
 private HLLocation ProcessBoundExpression(IBoundExpression pExpression)
 {
     if (pExpression.Definition is ILocalDefinition)
     {
         ILocalDefinition definition = pExpression.Definition as ILocalDefinition;
         HLLocation       location   = HLLocalLocation.Create(HLDomain.GetLocal(definition));
         if (pExpression.Type.ResolvedType.TypeCode == PrimitiveTypeCode.Reference)
         {
             location = location.AddressOf();
         }
         return(location);
     }
     else if (pExpression.Definition is IParameterDefinition)
     {
         return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition)));
     }
     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));
     }
     throw new NotSupportedException();
 }
示例#3
0
        private static HLType CreateType(ITypeDefinition pDefinition)
        {
            HLType type = new HLType();

            type.Definition        = pDefinition;
            type.Name              = pDefinition.ToString(); // TODO: Don't really like this, should use TypeHelper perhaps?
            type.Signature         = HLDomain.GetTypeSignature(pDefinition);
            sTypes[type.Signature] = type;

            ITypeReference referenceBase = pDefinition.BaseClasses.FirstOrDefault();

            if (referenceBase != null)
            {
                type.BaseType = GetOrCreateType(referenceBase);
                type.BaseType.MemberFields.ForEach(f => type.Fields.Add(f));
            }

            foreach (IFieldDefinition fieldDefinition in pDefinition.Fields.OrderBy(d => d.SequenceNumber))
            {
                CreateField(type, fieldDefinition);
            }

            IMethodDefinition definitionStaticConstructor = pDefinition.Methods.FirstOrDefault(d => d.IsStaticConstructor);

            if (definitionStaticConstructor != null)
            {
                type.StaticConstructor = GetOrCreateMethod(definitionStaticConstructor);
            }
            return(type);
        }
示例#4
0
        public static HLType GetOrCreateType(ITypeDefinition pDefinition)
        {
            HLType type = null;

            if (!sTypes.TryGetValue(GetTypeSignature(pDefinition), out type))
            {
                type = CreateType(pDefinition);
            }
            return(type);
        }
示例#5
0
        public HLTemporary CreateTemporary(HLType pType)
        {
            HLTemporary temporary = new HLTemporary();

            temporary.Name = "temp_" + Temporaries.Count;
            //temporary.Container = this;
            temporary.Type = pType;
            Temporaries.Add(temporary);
            return(temporary);
        }
示例#6
0
        public static HLMethod GetOrCreateMethod(IMethodDefinition pDefinition)
        {
            HLMethod method = null;

            if (!sMethods.TryGetValue(GetMethodSignature(pDefinition), out method))
            {
                HLType container = GetOrCreateType(pDefinition.Container);
                method = CreateMethod(container, pDefinition);
            }
            return(method);
        }
示例#7
0
        private HLLocation ProcessArrayIndexerExpression(IArrayIndexer pExpression)
        {
            if (pExpression.Indices.Count() != 1)
            {
                throw new NotSupportedException();
            }

            HLLocation locationInstance = ProcessExpression(pExpression.IndexedObject);
            HLLocation locationIndex    = ProcessExpression(pExpression.Indices.First());
            HLType     typeElement      = HLDomain.GetOrCreateType(pExpression.Type);

            return(HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement));
        }
示例#8
0
 private static void EnlistRuntimeTypes()
 {
     sSystemRuntimeMethodData   = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeMethodData"));
     sSystemRuntimeMethodHandle = GetOrCreateType(PlatformType.SystemRuntimeMethodHandle);
     sSystemRuntimeType         = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeType"));
     sSystemRuntimeTypeData     = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeTypeData"));
     sSystemRuntimeTypeHandle   = GetOrCreateType(PlatformType.SystemRuntimeTypeHandle);
     sSystemString = GetOrCreateType(PlatformType.SystemString);
     if (sSystemRuntimeMethodData.Definition.TypeCode == PrimitiveTypeCode.Invalid)
     {
         throw new NotImplementedException();
     }
     if (sSystemRuntimeTypeData.Definition.TypeCode == PrimitiveTypeCode.Invalid)
     {
         throw new NotImplementedException();
     }
 }
示例#9
0
        private static HLMethod CreateMethod(HLType pContainer, IMethodDefinition pDefinition)
        {
            HLMethod method = new HLMethod();

            method.Definition          = pDefinition;
            method.Name                = pDefinition.Name.Value;
            method.Signature           = GetMethodSignature(pDefinition);
            sMethods[method.Signature] = method;

            method.Container = pContainer;
            pContainer.Methods.Add(method);

            method.IsStatic             = pDefinition.IsStatic;
            method.IsExternal           = pDefinition.IsExternal;
            method.IsRuntimeImplemented = pDefinition.IsRuntimeImplemented;
            method.IsAbstract           = pDefinition.IsAbstract;
            method.IsVirtual            = pDefinition.IsVirtual;
            method.IsConstructor        = pDefinition.IsConstructor;
            method.ReturnType           = GetOrCreateType(pDefinition.Type);
            if (pDefinition != Module.EntryPoint.ResolvedMethod && !pDefinition.HasExplicitThisParameter)
            {
                HLType typeImplicitThis = method.Container;
                if (typeImplicitThis.Definition.IsValueType)
                {
                    typeImplicitThis = GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pDefinition.Container, Host.InternFactory, pDefinition.Container));
                }
                method.Parameters.Add(new HLParameter()
                {
                    Name = "this", Type = typeImplicitThis
                });
            }
            foreach (IParameterDefinition definition in pDefinition.Parameters.OrderBy(d => d.Index))
            {
                method.Parameters.Add(CreateParameter(definition));
            }
            foreach (ILocalDefinition definition in pDefinition.Body.LocalVariables.Where(d => d.Name.Value != string.Empty))
            {
                method.Locals.Add(CreateLocal(definition));
            }
            // TODO: Finish loading from Definition

            sPendingMethods.Enqueue(method);
            return(method);
        }
示例#10
0
 private HLLocation ProcessAddressableExpression(IAddressableExpression pExpression)
 {
     if (pExpression.Definition is ILocalDefinition)
     {
         return(HLLocalLocation.Create(HLDomain.GetLocal(pExpression.Definition as ILocalDefinition)));
     }
     else if (pExpression.Definition is IParameterDefinition)
     {
         return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition)));
     }
     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 IArrayIndexer)
     {
         IArrayIndexer definition = (IArrayIndexer)pExpression.Definition;
         if (definition.Indices.Count() != 1)
         {
             throw new NotSupportedException();
         }
         HLLocation locationInstance = ProcessExpression(pExpression.Instance);
         HLLocation locationIndex    = ProcessExpression(definition.Indices.First());
         HLType     typeElement      = HLDomain.GetOrCreateType(pExpression.Type);
         return(HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement));
     }
     else if (pExpression.Definition is IDefaultValue)
     {
         HLType     typeDefaultValue     = HLDomain.GetOrCreateType(((IDefaultValue)pExpression.Definition).DefaultValueType);
         HLLocation locationDefaultValue = HLTemporaryLocation.Create(CreateTemporary(typeDefaultValue));
         mCurrentBlock.EmitAssignment(locationDefaultValue, HLDefaultLocation.Create(typeDefaultValue));
         return(locationDefaultValue);
     }
     throw new NotSupportedException();
 }
示例#11
0
        private static HLField CreateField(HLType pContainer, IFieldDefinition pDefinition)
        {
            HLField field = new HLField();

            //field.Definition = pDefinition;
            field.Name               = pDefinition.Name.Value;
            field.Signature          = HLDomain.GetFieldSignature(pDefinition);
            sFields[field.Signature] = field;

            field.Container = pContainer;
            pContainer.Fields.Add(field);

            field.IsStatic = pDefinition.IsStatic;
            field.IsCompileTimeConstant = pDefinition.IsCompileTimeConstant;
            if (field.IsCompileTimeConstant)
            {
                field.CompileTimeConstant = pDefinition.Constant.Value;
            }
            field.Type = GetOrCreateType(pDefinition.Type);
            return(field);
        }
示例#12
0
        private HLLocation ProcessCreateArrayExpression(ICreateArray pExpression)
        {
            if (pExpression.Rank != 1 || pExpression.Sizes.Count() != 1 || pExpression.LowerBounds.Count() > 0)
            {
                throw new NotSupportedException();
            }

            HLType     typeElement      = HLDomain.GetOrCreateType(pExpression.ElementType);
            HLLocation locationInstance = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type)));
            HLLocation locationSize     = ProcessExpression(pExpression.Sizes.First());

            mCurrentBlock.EmitNewArray(locationInstance.AddressOf(), locationSize, locationInstance.Type, typeElement);

            IExpression[] initializers = pExpression.Initializers.ToArray();
            for (int indexInitializer = 0; indexInitializer < initializers.Length; ++indexInitializer)
            {
                HLLocation locationInitializer  = ProcessExpression(initializers[indexInitializer]);
                HLLocation locationArrayElement = HLArrayElementLocation.Create(locationInstance, HLInt32LiteralLocation.Create(indexInitializer), typeElement);
                mCurrentBlock.EmitAssignment(locationArrayElement, locationInitializer);
            }

            return(locationInstance);
        }
示例#13
0
        private HLLocation ProcessMethodCallExpression(IMethodCall pExpression)
        {
            List <HLLocation> locationsParameters = new List <HLLocation>();

            if (pExpression.ThisArgument.Type.TypeCode != PrimitiveTypeCode.Invalid)
            {
                locationsParameters.Add(ProcessExpression(pExpression.ThisArgument));
            }
            else if (pExpression.MethodToCall.IsStatic)
            {
                HLType typeContainer = null;
                if (pExpression.MethodToCall.ContainingType.ResolvedType.IsValueType)
                {
                    typeContainer = HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pExpression.MethodToCall.ContainingType, HLDomain.Host.InternFactory, pExpression.MethodToCall.ContainingType));
                }
                else
                {
                    typeContainer = HLDomain.GetOrCreateType(pExpression.MethodToCall.ContainingType);
                }
                locationsParameters.Add(HLNullLocation.Create(typeContainer));
            }
            foreach (IExpression argument in pExpression.Arguments)
            {
                locationsParameters.Add(ProcessExpression(argument));
            }

            HLLocation locationReturn = null;
            HLMethod   methodCalled   = HLDomain.GetOrCreateMethod(pExpression.MethodToCall);

            if (methodCalled.ReturnType.Definition.TypeCode != PrimitiveTypeCode.Void)
            {
                locationReturn = HLTemporaryLocation.Create(CreateTemporary(methodCalled.ReturnType));
            }
            mCurrentBlock.EmitCall(methodCalled, pExpression.IsVirtualCall, locationReturn, locationsParameters);
            return(locationReturn);
        }
示例#14
0
 public void EmitNewObject(HLType pNewObjectType, HLLocation pDestinationSource)
 {
     Emit(HLNewObjectInstruction.Create(mMethod, pNewObjectType, pDestinationSource));
 }
示例#15
0
 public void EmitNewDelegate(HLType pNewDelegateType, HLLocation pDestinationSource, HLLocation pInstanceSource, HLMethod pMethodCalled, bool pVirtual)
 {
     Emit(HLNewDelegateInstruction.Create(mMethod, pNewDelegateType, pDestinationSource, pInstanceSource, pMethodCalled, pVirtual));
 }
示例#16
0
 public void EmitNewArray(HLLocation pDestinationSource, HLLocation pSizeSource, HLType pArrayType, HLType pElementType)
 {
     Emit(HLNewArrayInstruction.Create(mMethod, pDestinationSource, pSizeSource, pArrayType, pElementType));
 }
示例#17
0
 protected HLLocation(HLType pType)
 {
     mType = pType;
 }
示例#18
0
        private static HLField CreateField(HLType pContainer, IFieldDefinition pDefinition)
        {
            HLField field = new HLField();
            //field.Definition = pDefinition;
            field.Name = pDefinition.Name.Value;
            field.Signature = HLDomain.GetFieldSignature(pDefinition);
            sFields[field.Signature] = field;

            field.Container = pContainer;
            pContainer.Fields.Add(field);

            field.IsStatic = pDefinition.IsStatic;
            field.IsCompileTimeConstant = pDefinition.IsCompileTimeConstant;
            if (field.IsCompileTimeConstant) field.CompileTimeConstant = pDefinition.Constant.Value;
            field.Type = GetOrCreateType(pDefinition.Type);
            return field;
        }
 public void EmitNewDelegate(HLType pNewDelegateType, HLLocation pDestinationSource, HLLocation pInstanceSource, HLMethod pMethodCalled, bool pVirtual)
 {
     Emit(HLNewDelegateInstruction.Create(mMethod, pNewDelegateType, pDestinationSource, pInstanceSource, pMethodCalled, pVirtual));
 }
 public void EmitNewArray(HLLocation pDestinationSource, HLLocation pSizeSource, HLType pArrayType, HLType pElementType)
 {
     Emit(HLNewArrayInstruction.Create(mMethod, pDestinationSource, pSizeSource, pArrayType, pElementType));
 }
示例#21
0
 protected HLLiteralLocation(HLType pType)
     : base(pType)
 {
 }
示例#22
0
        private static HLType CreateType(ITypeDefinition pDefinition)
        {
            HLType type = new HLType();
            type.Definition = pDefinition;
            type.Name = pDefinition.ToString(); // TODO: Don't really like this, should use TypeHelper perhaps?
            type.Signature = HLDomain.GetTypeSignature(pDefinition);
            sTypes[type.Signature] = type;

            ITypeReference referenceBase = pDefinition.BaseClasses.FirstOrDefault();
            if (referenceBase != null)
            {
                type.BaseType = GetOrCreateType(referenceBase);
                type.BaseType.MemberFields.ForEach(f => type.Fields.Add(f));
            }

            foreach (IFieldDefinition fieldDefinition in pDefinition.Fields.OrderBy(d => d.SequenceNumber))
                CreateField(type, fieldDefinition);

            IMethodDefinition definitionStaticConstructor = pDefinition.Methods.FirstOrDefault(d => d.IsStaticConstructor);
            if (definitionStaticConstructor != null) type.StaticConstructor = GetOrCreateMethod(definitionStaticConstructor);
            return type;
        }
示例#23
0
        private static HLMethod CreateMethod(HLType pContainer, IMethodDefinition pDefinition)
        {
            HLMethod method = new HLMethod();
            method.Definition = pDefinition;
            method.Name = pDefinition.Name.Value;
            method.Signature = GetMethodSignature(pDefinition);
            sMethods[method.Signature] = method;

            method.Container = pContainer;
            pContainer.Methods.Add(method);

            method.IsStatic = pDefinition.IsStatic;
            method.IsExternal = pDefinition.IsExternal;
            method.IsRuntimeImplemented = pDefinition.IsRuntimeImplemented;
            method.IsAbstract = pDefinition.IsAbstract;
            method.IsVirtual = pDefinition.IsVirtual;
            method.IsConstructor = pDefinition.IsConstructor;
            method.ReturnType = GetOrCreateType(pDefinition.Type);
            if (pDefinition != Module.EntryPoint.ResolvedMethod && !pDefinition.HasExplicitThisParameter)
            {
                HLType typeImplicitThis = method.Container;
                if (typeImplicitThis.Definition.IsValueType)
                    typeImplicitThis = GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pDefinition.Container, Host.InternFactory, pDefinition.Container));
                method.Parameters.Add(new HLParameter() { Name = "this", Type = typeImplicitThis });
            }
            foreach (IParameterDefinition definition in pDefinition.Parameters.OrderBy(d => d.Index))
                method.Parameters.Add(CreateParameter(definition));
            foreach (ILocalDefinition definition in pDefinition.Body.LocalVariables.Where(d => d.Name.Value != string.Empty))
                method.Locals.Add(CreateLocal(definition));
            // TODO: Finish loading from Definition

            sPendingMethods.Enqueue(method);
            return method;
        }
 public void EmitNewObject(HLType pNewObjectType, HLLocation pDestinationSource)
 {
     Emit(HLNewObjectInstruction.Create(mMethod, pNewObjectType, pDestinationSource));
 }
示例#25
0
 private static void EnlistRuntimeTypes()
 {
     sSystemRuntimeMethodData = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeMethodData"));
     sSystemRuntimeMethodHandle = GetOrCreateType(PlatformType.SystemRuntimeMethodHandle);
     sSystemRuntimeType = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeType"));
     sSystemRuntimeTypeData = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeTypeData"));
     sSystemRuntimeTypeHandle = GetOrCreateType(PlatformType.SystemRuntimeTypeHandle);
     sSystemString = GetOrCreateType(PlatformType.SystemString);
     if (sSystemRuntimeMethodData.Definition.TypeCode == PrimitiveTypeCode.Invalid) throw new NotImplementedException();
     if (sSystemRuntimeTypeData.Definition.TypeCode == PrimitiveTypeCode.Invalid) throw new NotImplementedException();
 }
示例#26
0
 protected HLLocation(HLType pType)
 {
     mType = pType;
 }
示例#27
0
 protected HLLiteralLocation(HLType pType) : base(pType)
 {
 }
示例#28
0
 public HLTemporary CreateTemporary(HLType pType)
 {
     HLTemporary temporary = new HLTemporary();
     temporary.Name = "temp_" + Temporaries.Count;
     //temporary.Container = this;
     temporary.Type = pType;
     Temporaries.Add(temporary);
     return temporary;
 }