internal override LLLocation Load(LLFunction pFunction)
 {
     LLLocation location = LLLocalLocation.Create(pFunction.Locals[Local.Name]);
     if (mLocal.IsReference)
         location = location.Load(pFunction.CurrentBlock);
     return location;
 }
 internal override void Store(LLFunction pFunction, LLLocation pSource)
 {
     HLStaticFieldAddressLocation.CheckStaticConstructorCalled(pFunction, StaticField.Container);
     LLLocation locationFieldPointer = LLGlobalLocation.Create(LLModule.GetGlobal(StaticField.Container.ToString() + "." + StaticField.ToString()));
     LLLocation locationSource = pFunction.CurrentBlock.EmitConversion(pSource, locationFieldPointer.Type.PointerDepthMinusOne);
     pFunction.CurrentBlock.EmitStore(locationFieldPointer, locationSource);
 }
 internal override void Store(LLFunction pFunction, LLLocation pSource)
 {
     LLLocation locationAddress = mAddress.Load(pFunction);
     locationAddress = pFunction.CurrentBlock.EmitConversion(locationAddress, Type.LLType);
     LLLocation locationSource = pFunction.CurrentBlock.EmitConversion(pSource, locationAddress.Type.PointerDepthMinusOne);
     pFunction.CurrentBlock.EmitStore(locationAddress, locationSource);
 }
예제 #4
0
 internal override LLLocation Load(LLFunction pFunction)
 {
     LLLocation locationFieldPointer = HLFieldAddressLocation.LoadInstanceFieldPointer(pFunction, Instance, Field);
     LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationFieldPointer.Type.PointerDepthMinusOne));
     pFunction.CurrentBlock.EmitLoad(locationTemporary, locationFieldPointer);
     return locationTemporary;
 }
예제 #5
0
 internal override LLLocation Load(LLFunction pFunction)
 {
     LLLocation locationLocal = LLLocalLocation.Create(pFunction.Locals[Local.Name]);
     LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationLocal.Type.PointerDepthMinusOne));
     pFunction.CurrentBlock.EmitLoad(locationTemporary, locationLocal);
     return locationTemporary;
 }
예제 #6
0
 internal override void Store(LLFunction pFunction, LLLocation pSource)
 {
     if (!Parameter.RequiresAddressing) throw new NotSupportedException();
     LLLocation locationLocal = LLLocalLocation.Create(Parameter.AddressableLocal);
     LLLocation locationSource = pFunction.CurrentBlock.EmitConversion(pSource, locationLocal.Type.PointerDepthMinusOne);
     pFunction.CurrentBlock.EmitStore(locationLocal, locationSource);
 }
        internal static LLLocation LoadArrayElementPointer(LLFunction pFunction, HLLocation pInstance, HLLocation pIndex, HLType pElementType)
        {
            LLLocation locationIndex = pIndex.Load(pFunction);
            LLLocation locationElementOffset = locationIndex;
            long? literalElementOffset = null;
            if (locationIndex is LLLiteralLocation)
            {
                literalElementOffset = Convert.ToInt64(((LLLiteralLocation)locationIndex).Literal.Value) * pElementType.VariableSize;
            }
            else if (pElementType.VariableSize > 1)
            {
                locationElementOffset = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationIndex.Type));
                pFunction.CurrentBlock.EmitMultiply(locationElementOffset, locationIndex, LLLiteralLocation.Create(LLLiteral.Create(locationElementOffset.Type, pElementType.VariableSize.ToString())));
            }

            LLLocation locationArrayPointer = pInstance.Load(pFunction);
            locationArrayPointer = pFunction.CurrentBlock.EmitConversion(locationArrayPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));

            LLLocation locationElementPointer = null;
            if (literalElementOffset.HasValue)
            {
                locationElementOffset = LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(64), (literalElementOffset.Value + HLDomain.SystemArray.CalculatedSize).ToString()));
                locationElementPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationElementPointer, locationArrayPointer, locationElementOffset);
            }
            else
            {
                LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationTemporary, locationArrayPointer, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), (HLDomain.SystemArray.CalculatedSize).ToString())));
                locationElementPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationElementPointer, locationTemporary, locationElementOffset);
            }
            return pFunction.CurrentBlock.EmitConversion(locationElementPointer, pElementType.LLType.PointerDepthPlusOne);
        }
        internal static void CheckStaticConstructorCalled(LLFunction pFunction, HLType pType)
        {
            if (pType.StaticConstructor == null) return;
            if (pType.StaticConstructor.LLFunction == pFunction) return;
            LLLocation locationConstructorCalled = LLGlobalLocation.Create(LLModule.GetGlobal(pType.ToString()));
            LLLocation locationConstructorCalledOriginal = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationConstructorCalled.Type.PointerDepthMinusOne));
            pFunction.CurrentBlock.EmitCompareExchange(locationConstructorCalledOriginal, locationConstructorCalled, LLLiteralLocation.Create(LLLiteral.Create(locationConstructorCalledOriginal.Type, "0")), LLLiteralLocation.Create(LLLiteral.Create(locationConstructorCalledOriginal.Type, "1")), LLCompareExchangeOrdering.acq_rel);

            LLLocation locationConstructorCall = LLTemporaryLocation.Create(pFunction.CreateTemporary(LLModule.BooleanType));
            pFunction.CurrentBlock.EmitCompareIntegers(locationConstructorCall, locationConstructorCalledOriginal, LLLiteralLocation.Create(LLLiteral.Create(locationConstructorCalledOriginal.Type, "0")), LLCompareIntegersCondition.eq);

            LLLabel labelTrue = pFunction.CreateLabel(pFunction.Labels.Count);
            LLLabel labelFalse = pFunction.CreateLabel(pFunction.Labels.Count);
            LLLabel labelNext = pFunction.CreateLabel(pFunction.Labels.Count);
            pFunction.CurrentBlock.EmitBranch(locationConstructorCall, labelTrue, labelFalse);

            LLInstructionBlock blockTrue = pFunction.CreateBlock(labelTrue);
            List<LLLocation> parameters = new List<LLLocation>();
            parameters.Add(LLLiteralLocation.Create(LLLiteral.Create(pType.StaticConstructor.LLFunction.Parameters[0].Type, "zeroinitializer")));
            blockTrue.EmitCall(null, LLFunctionLocation.Create(pType.StaticConstructor.LLFunction), parameters);
            blockTrue.EmitGoto(labelNext);

            LLInstructionBlock blockFalse = pFunction.CreateBlock(labelFalse);
            blockFalse.EmitGoto(labelNext);

            pFunction.CurrentBlock = pFunction.CreateBlock(labelNext);
        }
예제 #9
0
        public static LLFunction GetFunction(string pIdentifier)
        {
            LLFunction function = null;

            sFunctions.TryGetValue(pIdentifier, out function);
            return(function);
        }
 internal override LLLocation Load(LLFunction pFunction)
 {
     LLLocation locationElementPointer = HLArrayElementAddressLocation.LoadArrayElementPointer(pFunction, Instance, Index, ElementType);
     LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationElementPointer.Type.PointerDepthMinusOne));
     pFunction.CurrentBlock.EmitLoad(locationTemporary, locationElementPointer);
     return locationTemporary;
 }
 internal override LLLocation Load(LLFunction pFunction)
 {
     //LLLocation locationFieldPointer = LoadInstanceFieldPointer(pFunction, mInstance, mField);
     //LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationFieldPointer.Type.PointerDepthMinusOne));
     //pFunction.CurrentBlock.EmitLoad(locationTemporary, locationFieldPointer);
     //return locationTemporary;
     return LoadInstanceFieldPointer(pFunction, Instance, Field);
 }
 internal override LLLocation Load(LLFunction pFunction)
 {
     HLStaticFieldAddressLocation.CheckStaticConstructorCalled(pFunction, StaticField.Container);
     LLLocation locationFieldPointer = LLGlobalLocation.Create(LLModule.GetGlobal(StaticField.Container.ToString() + "." + StaticField.ToString()));
     LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationFieldPointer.Type.PointerDepthMinusOne));
     pFunction.CurrentBlock.EmitLoad(locationTemporary, locationFieldPointer);
     return locationTemporary;
 }
예제 #13
0
 public static LLInstructionBlock Create(LLFunction pFunction, LLLabel pStartLabel)
 {
     LLInstructionBlock block = new LLInstructionBlock();
     block.mFunction = pFunction;
     block.mStartLabel = pStartLabel;
     block.EmitLabel(pStartLabel);
     return block;
 }
예제 #14
0
 internal override void Transform(LLFunction pFunction)
 {
     LLLocation locationCondition = mConditionSource.Load(pFunction);
     List<LLSwitchCase> cases = new List<LLSwitchCase>();
     foreach (Tuple<HLLiteralLocation, HLLabel> tupleCase in mCases)
         cases.Add(LLSwitchCase.Create(LLLiteral.Create(tupleCase.Item1.Type.LLType, tupleCase.Item1.LiteralAsString), pFunction.Labels.GetByIdentifier(tupleCase.Item2.Identifier)));
     pFunction.CurrentBlock.EmitSwitch(locationCondition, pFunction.Labels.GetByIdentifier(mDefaultLabel.Identifier), cases);
 }
예제 #15
0
        public static LLInstructionBlock Create(LLFunction pFunction, LLLabel pStartLabel)
        {
            LLInstructionBlock block = new LLInstructionBlock();

            block.mFunction   = pFunction;
            block.mStartLabel = pStartLabel;
            block.EmitLabel(pStartLabel);
            return(block);
        }
        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);
        }
 internal override LLLocation Load(LLFunction pFunction)
 {
     LLLocation locationArrayPointer = Instance.Load(pFunction);
     locationArrayPointer = pFunction.CurrentBlock.EmitConversion(locationArrayPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));
     LLLocation locationArraySizePointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
     pFunction.CurrentBlock.EmitGetElementPointer(locationArraySizePointer, locationArrayPointer, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemArray.Fields["mLength"].Offset.ToString())));
     locationArraySizePointer = pFunction.CurrentBlock.EmitConversion(locationArraySizePointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateSignedType(32), 1));
     LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(LLModule.GetOrCreateSignedType(32)));
     pFunction.CurrentBlock.EmitLoad(locationTemporary, locationArraySizePointer);
     return pFunction.CurrentBlock.EmitConversion(locationTemporary, Type.LLType);
 }
예제 #18
0
        public static LLFunction GetOrCreateFunction(string pName, bool pExplicitName, bool pExternal, bool pAbstract, LLType pReturnType, List <LLParameter> pParameters)
        {
            LLFunction function   = null;
            string     identifier = GetFunctionIdentifier(pName, pReturnType, pParameters);

            if (!sFunctions.TryGetValue(identifier, out function))
            {
                function = CreateFunction(pName, pExplicitName, pExternal, pAbstract, pReturnType, pParameters);
            }
            return(function);
        }
예제 #19
0
 internal override LLLocation Load(LLFunction pFunction)
 {
     LLLocation locationTemporary = null;
     if (!Parameter.RequiresAddressing) locationTemporary = LLParameterLocation.Create(pFunction.Parameters[Parameter.Name]);
     else
     {
         LLLocation locationLocal = LLLocalLocation.Create(Parameter.AddressableLocal);
         locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationLocal.Type.PointerDepthMinusOne));
         pFunction.CurrentBlock.EmitLoad(locationTemporary, locationLocal);
     }
     return locationTemporary;
 }
 internal static LLLocation LoadInstanceFieldPointer(LLFunction pFunction, HLLocation pInstance, HLField pField)
 {
     LLLocation locationInstance = pInstance.Load(pFunction);
     locationInstance = pFunction.CurrentBlock.EmitConversion(locationInstance, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));
     LLLocation locationFieldPointer = locationInstance;
     if (pField.Offset > 0)
     {
         locationFieldPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationFieldPointer.Type));
         pFunction.CurrentBlock.EmitGetElementPointer(locationFieldPointer, locationInstance, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateUnsignedType(32), pField.Offset.ToString())));
     }
     return pFunction.CurrentBlock.EmitConversion(locationFieldPointer, pField.Type.LLType.PointerDepthPlusOne);
 }
예제 #21
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);
        }
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationLeftOperand = mLeftOperandSource.Load(pFunction);
            LLLocation locationRightOperand = mRightOperandSource.Load(pFunction);

            LLType typeOperands = LLModule.BinaryResult(locationLeftOperand.Type, locationRightOperand.Type);
            locationLeftOperand = pFunction.CurrentBlock.EmitConversion(locationLeftOperand, typeOperands);
            locationRightOperand = pFunction.CurrentBlock.EmitConversion(locationRightOperand, typeOperands);

            LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(typeOperands));
            pFunction.CurrentBlock.EmitMultiply(locationTemporary, locationLeftOperand, locationRightOperand);

            mDestination.Store(pFunction, locationTemporary);
        }
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationSource = mSource.Load(pFunction);
            if (mSource.Type.Definition.IsValueType && mDestination.Type == HLDomain.SystemObject)
            {
                // Boxing
                List<LLLocation> parameters = new List<LLLocation>();
                LLLocation locationObjectReference = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.SystemObject.LLType.PointerDepthPlusOne));
                pFunction.CurrentBlock.EmitAllocate(locationObjectReference);
                pFunction.CurrentBlock.EmitStore(locationObjectReference, LLLiteralLocation.Create(LLLiteral.Create(locationObjectReference.Type.PointerDepthMinusOne, "zeroinitializer")));

                parameters.Add(locationObjectReference);
                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, (HLDomain.SystemObject.CalculatedSize + mSource.Type.CalculatedSize).ToString()));
                LLLocation locationHandle = LLLiteralLocation.Create(LLLiteral.Create(HLDomain.GCAllocate.Parameters[2].Type, mSource.Type.RuntimeTypeHandle.ToString()));

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

                LLLocation locationObject = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.SystemObject.LLType));
                pFunction.CurrentBlock.EmitLoad(locationObject, locationObjectReference);

                LLLocation locationObjectValue = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationObject.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationObjectValue, locationObject, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemObject.CalculatedSize.ToString())));
                locationObjectValue = pFunction.CurrentBlock.EmitConversion(locationObjectValue, mSource.Type.LLType.PointerDepthPlusOne);

                pFunction.CurrentBlock.EmitStore(locationObjectValue, locationSource);
                locationSource = locationObject;
            }
            else if (mSource.Type == HLDomain.SystemObject && mDestination.Type.Definition.IsValueType)
            {
                // Unboxing

                // TODO: Branch on destination type handle not matching object handle, and throw exception
                LLLocation locationObjectValue = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationSource.Type));
                pFunction.CurrentBlock.EmitGetElementPointer(locationObjectValue, locationSource, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemObject.CalculatedSize.ToString())));
                locationObjectValue = pFunction.CurrentBlock.EmitConversion(locationObjectValue, mDestination.Type.LLType.PointerDepthPlusOne);

                LLLocation locationValue = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationObjectValue.Type.PointerDepthMinusOne));
                pFunction.CurrentBlock.EmitLoad(locationValue, locationObjectValue);
                locationSource = locationValue;
            }
            mDestination.Store(pFunction, locationSource);
        }
예제 #24
0
        private static LLFunction CreateFunction(string pName, bool pExplicitName, bool pExternal, bool pAbstract, LLType pReturnType, List <LLParameter> pParameters)
        {
            LLFunction function = new LLFunction();

            function.Name                   = pName;
            function.ExplicitName           = pExplicitName;
            function.External               = pExternal;
            function.Abstract               = pAbstract;
            function.Identifier             = LLModule.GetFunctionIdentifier(pName, pReturnType, pParameters);
            function.IdentifierHash         = "F_" + BitConverter.ToString(SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(function.Identifier))).Replace("-", "").ToUpper().Substring(0, 16);
            function.ReturnType             = pReturnType;
            function.Parameters             = new LLParameterList(pParameters);
            sFunctions[function.Identifier] = function;
            return(function);
        }
예제 #25
0
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationLeftOperand = mLeftOperandSource.Load(pFunction);
            LLLocation locationRightOperand = mRightOperandSource.Load(pFunction);

            LLType typeOperands = LLModule.BinaryResult(locationLeftOperand.Type, locationRightOperand.Type);
            locationLeftOperand = pFunction.CurrentBlock.EmitConversion(locationLeftOperand, typeOperands);
            locationRightOperand = pFunction.CurrentBlock.EmitConversion(locationRightOperand, typeOperands);

            LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(LLModule.BooleanType));

            if (typeOperands.Primitive == LLPrimitive.Float)
            {
                LLCompareFloatsCondition condition = LLCompareFloatsCondition.oeq;
                switch (mCompareType)
                {
                    case HLCompareType.Equal: condition = LLCompareFloatsCondition.oeq; break;
                    case HLCompareType.NotEqual: condition = LLCompareFloatsCondition.one; break;
                    case HLCompareType.GreaterThan: condition = LLCompareFloatsCondition.ogt; break;
                    case HLCompareType.GreaterThanOrEqual: condition = LLCompareFloatsCondition.oge; break;
                    case HLCompareType.LessThan: condition = LLCompareFloatsCondition.olt; break;
                    case HLCompareType.LessThanOrEqual: condition = LLCompareFloatsCondition.ole; break;
                    default: throw new NotSupportedException();
                }
                pFunction.CurrentBlock.EmitCompareFloats(locationTemporary, locationLeftOperand, locationRightOperand, condition);
            }
            else
            {
                LLCompareIntegersCondition condition = LLCompareIntegersCondition.eq;
                switch (mCompareType)
                {
                    case HLCompareType.Equal: condition = LLCompareIntegersCondition.eq; break;
                    case HLCompareType.NotEqual: condition = LLCompareIntegersCondition.ne; break;
                    case HLCompareType.GreaterThan: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.ugt : LLCompareIntegersCondition.sgt; break;
                    case HLCompareType.GreaterThanOrEqual: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.uge : LLCompareIntegersCondition.sge; break;
                    case HLCompareType.LessThan: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.ult : LLCompareIntegersCondition.slt; break;
                    case HLCompareType.LessThanOrEqual: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.ule : LLCompareIntegersCondition.sle; break;
                    default: throw new NotSupportedException();
                }
                pFunction.CurrentBlock.EmitCompareIntegers(locationTemporary, locationLeftOperand, locationRightOperand, condition);
            }

            mDestination.Store(pFunction, locationTemporary);
        }
        internal override LLLocation Load(LLFunction pFunction)
        {
            List<LLLocation> parameters = new List<LLLocation>();

            LLLocation locationStringReference = LLTemporaryLocation.Create(pFunction.CreateTemporary(HLDomain.SystemStringCtorWithCharPointer.Parameters[0].Type.LLType.PointerDepthPlusOne));
            pFunction.CurrentBlock.EmitAllocate(locationStringReference);
            pFunction.CurrentBlock.EmitStore(locationStringReference, LLLiteralLocation.Create(LLLiteral.Create(locationStringReference.Type.PointerDepthMinusOne, "zeroinitializer")));

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

            parameters.Clear();
            parameters.Add(locationStringReference);

            char[] data = Literal.ToCharArray();
            Array.Resize(ref data, data.Length + 1);

            LLType typeChar = LLModule.GetOrCreateSignedType(16);
            LLType typeLiteralData = LLModule.GetOrCreateArrayType(typeChar, data.Length);
            LLLocation locationLiteralData = LLTemporaryLocation.Create(pFunction.CreateTemporary(typeLiteralData.PointerDepthPlusOne));
            pFunction.CurrentBlock.EmitAllocate(locationLiteralData);
            StringBuilder sb = new StringBuilder();
            sb.Append("[ ");
            for (int index = 0; index < data.Length; ++index)
            {
                if (index > 0) sb.Append(", ");
                sb.AppendFormat("{0} {1}", typeChar, (int)data[index]);
            }
            sb.Append(" ]");
            pFunction.CurrentBlock.EmitStore(locationLiteralData, LLLiteralLocation.Create(LLLiteral.Create(typeLiteralData, sb.ToString())));
            parameters.Add(locationLiteralData);

            for (int index = 1; index < parameters.Count; ++index)
                parameters[index] = pFunction.CurrentBlock.EmitConversion(parameters[index], HLDomain.SystemStringCtorWithCharPointer.Parameters[index].Type.LLType);

            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.SystemStringCtorWithCharPointer.LLFunction), parameters);

            LLLocation locationString = LLTemporaryLocation.Create(pFunction.CreateTemporary(Type.LLType));
            pFunction.CurrentBlock.EmitLoad(locationString, locationStringReference);
            return locationString;
        }
        internal override void Transform(LLFunction pFunction)
        {
            List<LLLocation> parameters = new List<LLLocation>();
            LLLocation locationObjectReference = mDestinationSource.Load(pFunction);
            pFunction.CurrentBlock.EmitStore(locationObjectReference, LLLiteralLocation.Create(LLLiteral.Create(locationObjectReference.Type.PointerDepthMinusOne, "zeroinitializer")));

            parameters.Add(locationObjectReference);
            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, mNewObjectType.CalculatedSize.ToString()));

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

            parameters.Clear();
            parameters.Add(locationObjectReference);
            parameters.Add(locationTotalSize);
            parameters.Add(locationHandle);
            pFunction.CurrentBlock.EmitCall(null, LLFunctionLocation.Create(HLDomain.GCAllocate), parameters);
        }
        internal override void Transform(LLFunction pFunction)
        {
            List<LLLocation> parameters = new List<LLLocation>();
            LLLocation locationArrayReference = mDestinationSource.Load(pFunction);
            pFunction.CurrentBlock.EmitStore(locationArrayReference, LLLiteralLocation.Create(LLLiteral.Create(locationArrayReference.Type.PointerDepthMinusOne, "zeroinitializer")));

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

            LLLocation locationSize = mSizeSource.Load(pFunction);
            LLLocation locationElementsSize = locationSize;
            if (mElementType.VariableSize > 1)
            {
                locationElementsSize = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationSize.Type));
                pFunction.CurrentBlock.EmitMultiply(locationElementsSize, locationSize, LLLiteralLocation.Create(LLLiteral.Create(locationSize.Type, mElementType.VariableSize.ToString())));
            }
            LLLocation locationTotalSize = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationSize.Type));
            pFunction.CurrentBlock.EmitAdd(locationTotalSize, locationElementsSize, LLLiteralLocation.Create(LLLiteral.Create(locationSize.Type, (HLDomain.SystemArray.CalculatedSize).ToString())));
            locationTotalSize = pFunction.CurrentBlock.EmitConversion(locationTotalSize, HLDomain.GCAllocate.Parameters[1].Type);

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

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

            LLLocation locationArrayPointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayReference.Type.PointerDepthMinusOne));
            pFunction.CurrentBlock.EmitLoad(locationArrayPointer, locationArrayReference);
            locationArrayPointer = pFunction.CurrentBlock.EmitConversion(locationArrayPointer, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1));

            LLLocation locationArraySizePointer = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationArrayPointer.Type));
            pFunction.CurrentBlock.EmitGetElementPointer(locationArraySizePointer, locationArrayPointer, LLLiteralLocation.Create(LLLiteral.Create(LLModule.GetOrCreateSignedType(32), HLDomain.SystemObject.CalculatedSize.ToString())));
            locationArraySizePointer = pFunction.CurrentBlock.EmitConversion(locationArraySizePointer, locationSize.Type.PointerDepthPlusOne);
            pFunction.CurrentBlock.EmitStore(locationArraySizePointer, locationSize);
        }
 internal override LLLocation Load(LLFunction pFunction)
 {
     return LLLiteralLocation.Create(LLLiteral.Create(Type.LLType, Literal.ToString()));
 }
예제 #30
0
 protected LLInstruction(LLFunction pFunction)
 {
     mFunction = pFunction;
 }
예제 #31
0
 private static LLFunction CreateFunction(string pName, bool pExplicitName, bool pExternal, bool pAbstract, LLType pReturnType, List<LLParameter> pParameters)
 {
     LLFunction function = new LLFunction();
     function.Name = pName;
     function.ExplicitName = pExplicitName;
     function.External = pExternal;
     function.Abstract = pAbstract;
     function.Identifier = LLModule.GetFunctionIdentifier(pName, pReturnType, pParameters);
     function.IdentifierHash = "F_" + BitConverter.ToString(SHA256.Create().ComputeHash(Encoding.ASCII.GetBytes(function.Identifier))).Replace("-", "").ToUpper().Substring(0, 16);
     function.ReturnType = pReturnType;
     function.Parameters = new LLParameterList(pParameters);
     sFunctions[function.Identifier] = function;
     return function;
 }
예제 #32
0
 internal override void Store(LLFunction pFunction, LLLocation pSource)
 {
     LLLocation locationLocal = LLLocalLocation.Create(pFunction.Locals[Local.Name]);
     LLLocation locationSource = pFunction.CurrentBlock.EmitConversion(pSource, locationLocal.Type.PointerDepthMinusOne);
     pFunction.CurrentBlock.EmitStore(locationLocal, locationSource);
 }
예제 #33
0
 internal virtual LLLocation Load(LLFunction pFunction)
 {
     throw new NotSupportedException();
 }
예제 #34
0
 internal override void Transform(LLFunction pFunction)
 {
     pFunction.CurrentBlock.EmitGoto(pFunction.Labels.GetByIdentifier(mTargetLabel.Identifier));
 }
예제 #35
0
 internal virtual void Store(LLFunction pFunction, LLLocation pSource)
 {
     throw new NotSupportedException();
 }