Exemplo n.º 1
0
        public static LLFunctionLocation Create(LLFunction pFunction)
        {
            LLFunctionLocation location = new LLFunctionLocation(LLModule.GetOrCreateFunctionType(pFunction.ReturnType, pFunction.Parameters.ToTypeList()).PointerDepthPlusOne);

            location.mFunction = pFunction;
            return(location);
        }
Exemplo n.º 2
0
        internal override void Transform(LLFunction pFunction)
        {
            List <LLLocation> parameters = new List <LLLocation>();
            LLLocation        locationDelegateReference = mDestinationSource.Load(pFunction);

            pFunction.CurrentBlock.EmitStore(locationDelegateReference, LLLiteralLocation.Create(LLLiteral.Create(locationDelegateReference.Type.PointerDepthMinusOne, "zeroinitializer")));

            parameters.Add(locationDelegateReference);
            parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCRoot.Parameters[1].Type, "null")));
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCRoot), parameters);

            LLLocation locationTotalSize = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[1].Type, mNewDelegateType.CalculatedSize.ToString()));

            LLLocation locationHandle = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[2].Type, mNewDelegateType.RuntimeTypeHandle.ToString()));

            parameters.Clear();
            parameters.Add(locationDelegateReference);
            parameters.Add(locationTotalSize);
            parameters.Add(locationHandle);
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCAllocate), parameters);

            LLLocation locationDelegate = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationDelegateReference.Type.PointerDepthMinusOne));

            pFunction.CurrentBlock.EmitLoad(locationDelegate, locationDelegateReference);

            LLLocation locationTargetObj = null;

            if (mInstanceSource != null)
            {
                LLLocation locationTargetObjPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationDelegate.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationTargetObjPointer, locationDelegate, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), mNewDelegateType.Fields["mTargetObj"].Offset.ToString())));
                locationTargetObjPointer = pFunction.CurrentBlock.EmitConversion(locationTargetObjPointer, mInstanceSource.Type.LLType.PointerDepthPlusOne);
                locationTargetObj        = mInstanceSource.Load(pFunction);
                pFunction.CurrentBlock.EmitStore(locationTargetObjPointer, locationTargetObj);
            }

            LLLocation locationTargetMethodPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationDelegate.Type));

            pFunction.CurrentBlock.EmitGetElementPointer(locationTargetMethodPointer, locationDelegate, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), mNewDelegateType.Fields["mTargetMethod"].Offset.ToString())));
            locationTargetMethodPointer = pFunction.CurrentBlock.EmitConversion(locationTargetMethodPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateSignedType(32), 1));
            LLLocation locationTargetMethod = null;

            if (!mVirtual)
            {
                locationTargetMethod = LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), mMethodCalled.RuntimeMethodHandle.ToString()));
            }
            else
            {
                LLType typeFunction = LLModule.GetOrCreateFunctionType(mMethodCalled.ReturnType == null ? null : mMethodCalled.ReturnType.LLType, mMethodCalled.Parameters.ConvertAll(p => p.Type.LLType));
                int    virtualIndex = mMethodCalled.Container.VirtualLookup[mMethodCalled];

                parameters.Clear();
                parameters.Add(locationTargetObj);
                parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), virtualIndex.ToString())));
                for (int index = 0; index < parameters.Count; ++index)
                {
                    parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], HLDomain.VTableHandleLookup.Parameters[index].Type);
                }
                locationTargetMethod = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.VTableHandleLookup.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationTargetMethod, LLFunctionLocation.Create(HLDomain.VTableHandleLookup), parameters);
                locationTargetMethod = pFunction.CurrentBlock.EmitConversion(locationTargetMethod, LLModule.GetOrCreateSignedType(32));
            }
            pFunction.CurrentBlock.EmitStore(locationTargetMethodPointer, locationTargetMethod);
        }
Exemplo n.º 3
0
        internal override void Transform(LLFunction pFunction)
        {
            List <LLLocation> parameters              = new List <LLLocation>();
            LLLocation        locationReturn          = null;
            LLLocation        locationFunction        = null;
            LLLocation        locationAlternativeThis = null;

            if (!mVirtual)
            {
                locationFunction = LLFunctionLocation.Create(mCalledMethod.LLFunction);
            }
            else if (mCalledMethod.Container.Definition.IsDelegate && mCalledMethod.Name == "Invoke")
            {
                parameters.Add(mParameterSources[0].Load(pFunction));

                locationFunction = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.DelegateLookup.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationFunction, LLFunctionLocation.Create(HLDomain.DelegateLookup), parameters);

                LLType typeFunction = LLModule.GetOrCreateFunctionType(mCalledMethod.ReturnType == null ? null : mCalledMethod.ReturnType.LLType, mParameterSources.ConvertAll(l => l.Type.LLType));
                locationFunction = pFunction.CurrentBlock.EmitConversion(locationFunction, LLModule.GetOrCreatePointerType(typeFunction, 1));

                locationAlternativeThis = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.DelegateInstance.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationAlternativeThis, LLFunctionLocation.Create(HLDomain.DelegateInstance), parameters);
            }
            else
            {
                LLType typeFunction = LLModule.GetOrCreateFunctionType(mCalledMethod.ReturnType == null ? null : mCalledMethod.ReturnType.LLType, mParameterSources.ConvertAll(l => l.Type.LLType));
                int    virtualIndex = mCalledMethod.Container.VirtualLookup[mCalledMethod];
                parameters.Add(mParameterSources[0].Load(pFunction));
                parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), virtualIndex.ToString())));
                for (int index = 0; index < parameters.Count; ++index)
                {
                    parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], HLDomain.VTableFunctionLookup.Parameters[index].Type);
                }
                locationReturn = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.VTableFunctionLookup.ReturnType));
                pFunction.CurrentBlock.EmitCall(locationReturn, LLFunctionLocation.Create(HLDomain.VTableFunctionLookup), parameters);
                locationFunction = pFunction.CurrentBlock.EmitConversion(locationReturn, typeFunction.PointerDepthPlusOne);
            }

            parameters.Clear();
            if (locationAlternativeThis == null)
            {
                mParameterSources.ForEach(l => parameters.Add(l.Load(pFunction)));
            }
            else
            {
                parameters.Add(locationAlternativeThis);
                for (int index = 1; index < mParameterSources.Count; ++index)
                {
                    parameters.Add(mParameterSources[index].Load(pFunction));
                }
            }

            for (int index = 0; index < parameters.Count; ++index)
            {
                parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], mCalledMethod.LLFunction.Parameters[index].Type);
            }

            locationReturn = null;
            if (mReturnDestination != null)
            {
                locationReturn = LLTemporaryLocation.Create(pFunction.CreateTemporary(mReturnDestination.Type.LLType));
            }

            pFunction.CurrentBlock.EmitCall(locationReturn, locationFunction, parameters);
            if (mReturnDestination != null)
            {
                mReturnDestination.Store(pFunction, locationReturn);
            }
        }