Пример #1
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);
        }
Пример #2
0
        private static HLLocal CreateLocal(ILocalDefinition pDefinition)
        {
            HLLocal local = new HLLocal();

            //local.Definition = pDefinition;
            local.Name               = pDefinition.Name.Value;
            local.Signature          = HLDomain.GetLocalSignature(pDefinition);
            sLocals[local.Signature] = local;

            //local.Container = GetOrCreateMethod(pDefinition.MethodDefinition);
            ITypeReference type = pDefinition.Type;

            if (pDefinition.IsReference)
            {
                type = MutableModelHelper.GetManagedPointerTypeReference(type, Host.InternFactory, type);
            }
            local.IsReference = pDefinition.IsReference;
            local.Type        = GetOrCreateType(type);
            return(local);
        }
Пример #3
0
        private static HLParameter CreateParameter(IParameterDefinition pDefinition)
        {
            HLParameter parameter = new HLParameter();

            //parameter.Definition = pDefinition;
            parameter.Name      = pDefinition.Name.Value;
            parameter.Signature = HLDomain.GetParameterSignature(pDefinition);
            sParameters[parameter.Signature] = parameter;

            //if (pDefinition.ContainingSignature is IMethodDefinition) parameter.MethodContainer = GetOrCreateMethod(pDefinition.ContainingSignature as IMethodDefinition);
            //else throw new NotSupportedException();
            ITypeReference type = pDefinition.Type;

            if (pDefinition.IsByReference)
            {
                type = MutableModelHelper.GetManagedPointerTypeReference(type, Host.InternFactory, type);
            }
            parameter.IsReference = pDefinition.IsByReference;
            parameter.Type        = GetOrCreateType(type);
            return(parameter);
        }
Пример #4
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);
        }
Пример #5
0
        public static HLFieldAddressLocation Create(HLLocation pInstance, HLField pField)
        {
            HLFieldAddressLocation location = new HLFieldAddressLocation(HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pField.Type.Definition, HLDomain.Host.InternFactory, pField.Type.Definition)));

            location.mInstance = pInstance;
            location.mField    = pField;
            return(location);
        }
Пример #6
0
        public static HLParameterAddressLocation Create(HLParameter pParameter)
        {
            HLParameterAddressLocation location = new HLParameterAddressLocation(HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pParameter.Type.Definition, HLDomain.Host.InternFactory, pParameter.Type.Definition)));

            location.mParameter = pParameter;

            pParameter.RequiresAddressing = true;
            return(location);
        }
Пример #7
0
        public static HLIndirectAddressLocation Create(HLLocation pAddress, HLType pType)
        {
            HLIndirectAddressLocation location = new HLIndirectAddressLocation(HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pType.Definition, HLDomain.Host.InternFactory, pType.Definition)));

            location.mAddress = pAddress;
            return(location);
        }
        public static HLArrayElementAddressLocation Create(HLLocation pInstance, HLLocation pIndex, HLType pElementType)
        {
            HLArrayElementAddressLocation location = new HLArrayElementAddressLocation(HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pElementType.Definition, HLDomain.Host.InternFactory, pElementType.Definition)));

            location.mInstance    = pInstance;
            location.mIndex       = pIndex;
            location.mElementType = pElementType;
            return(location);
        }
Пример #9
0
        public static HLTemporaryAddressLocation Create(HLTemporary pTemporary)
        {
            HLTemporaryAddressLocation location = new HLTemporaryAddressLocation(HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pTemporary.Type.Definition, HLDomain.Host.InternFactory, pTemporary.Type.Definition)));

            location.mTemporary = pTemporary;
            return(location);
        }
Пример #10
0
        public static HLLocalAddressLocation Create(HLLocal pLocal)
        {
            HLLocalAddressLocation location = new HLLocalAddressLocation(HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pLocal.Type.Definition, HLDomain.Host.InternFactory, pLocal.Type.Definition)));

            location.mLocal = pLocal;
            return(location);
        }