Exemplo n.º 1
0
        public static LLCommentInstruction Create(LLFunction pFunction, string pComment)
        {
            LLCommentInstruction instruction = new LLCommentInstruction(pFunction);

            instruction.mComment = pComment;
            return(instruction);
        }
Exemplo n.º 2
0
        public static LLAllocateInstruction Create(LLFunction pFunction, LLLocation pDestination)
        {
            LLAllocateInstruction instruction = new LLAllocateInstruction(pFunction);

            instruction.mDestination = pDestination;
            return(instruction);
        }
Exemplo n.º 3
0
        public static LLGotoInstruction Create(LLFunction pFunction, LLLabel pTargetLabel)
        {
            LLGotoInstruction instruction = new LLGotoInstruction(pFunction);

            instruction.mTargetLabel = pTargetLabel;
            return(instruction);
        }
 public static LLBitcastInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pSource)
 {
     LLBitcastInstruction instruction = new LLBitcastInstruction(pFunction);
     instruction.mDestination = pDestination;
     instruction.mSource = pSource;
     return instruction;
 }
Exemplo n.º 5
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (mReturnDestination != null)
            {
                sb.AppendFormat("{0} = ", mReturnDestination);
            }
            sb.AppendFormat("call {0} {1}(", mReturnDestination == null ? LLModule.VoidType : mReturnDestination.Type, mFunctionSource);
            for (int index = 0; index < mParameterSources.Count; ++index)
            {
                LLLocation parameterSource = mParameterSources[index];
                if (index > 0)
                {
                    sb.Append(", ");
                }
                sb.AppendFormat("{0} {1}", parameterSource.Type, parameterSource);
            }
            sb.Append(")");
            if (mFunctionSource is LLFunctionLocation)
            {
                LLFunction function = ((LLFunctionLocation)mFunctionSource).Function;
                if (function.Description != null)
                {
                    sb.AppendFormat("    ; {0}", function.Description);
                }
            }
            return(sb.ToString());
        }
 public static LLIntegerToPointerInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pSource)
 {
     LLIntegerToPointerInstruction instruction = new LLIntegerToPointerInstruction(pFunction);
     instruction.mDestination = pDestination;
     instruction.mSource = pSource;
     return instruction;
 }
Exemplo n.º 7
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.º 8
0
        public static LLLabelInstruction Create(LLFunction pFunction, LLLabel pLabel)
        {
            LLLabelInstruction instruction = new LLLabelInstruction(pFunction);

            instruction.mLabel = pLabel;
            return(instruction);
        }
Exemplo n.º 9
0
        public static LLReturnInstruction Create(LLFunction pFunction, LLLocation pSource)
        {
            LLReturnInstruction instruction = new LLReturnInstruction(pFunction);

            instruction.mSource = pSource;
            return(instruction);
        }
Exemplo n.º 10
0
        internal override void Store(LLFunction pFunction, LLLocation pSource)
        {
            LLLocation locationLocal  = LLLocalLocation.Create(pFunction.Locals[Temporary.Name]);
            LLLocation locationSource = pFunction.CurrentBlock.EmitConversion(pSource, locationLocal.Type.PointerDepthMinusOne);

            pFunction.CurrentBlock.EmitStore(locationLocal, locationSource);
        }
Exemplo n.º 11
0
        private static void BuildDelegateInstance()
        {
            List <LLParameter> parametersFunction = new List <LLParameter>();

            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), "this"));
            sDelegateInstance = LLModule.GetOrCreateFunction("DelegateInstance", true, true, false, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), parametersFunction);
        }
Exemplo n.º 12
0
        internal void BuildFunction()
        {
            // DONE: Convert HLMethods to LLFunctions
            List <LLParameter> parameters = new List <LLParameter>();

            foreach (HLParameter parameter in Parameters)
            {
                LLType typeParameter = parameter.Type.LLType;
                // DONE: Adjust first parameter for string constructors to additional pointer depth plus one
                if (parameter == Parameters.First() && Container == HLDomain.SystemString && !IsStatic && IsConstructor)
                {
                    typeParameter = typeParameter.PointerDepthPlusOne;
                }
                parameters.Add(LLParameter.Create(typeParameter, parameter.Name));
            }
            bool entryFunction = HLDomain.EntryMethod == this;

            mLLFunction            = LLModule.GetOrCreateFunction(entryFunction ? "main" : (Container.ToString() + "." + ToString()), entryFunction, IsExternal, IsAbstract || IsRuntimeImplemented, ReturnType.LLType, parameters);
            LLFunction.Description = Signature;
            foreach (HLParameter parameter in Parameters.Where(p => p.RequiresAddressing))
            {
                parameter.AddressableLocal = LLFunction.CreateLocal(parameter.Type.LLType, "local_" + parameter.Name);
            }
            foreach (HLLocal local in Locals)
            {
                LLFunction.CreateLocal(local.Type.LLType, local.Name);
            }
            foreach (HLTemporary temporary in Temporaries)
            {
                LLFunction.CreateLocal(temporary.Type.LLType, temporary.Name);
            }
        }
Exemplo n.º 13
0
        internal override void Store(LLFunction pFunction, LLLocation pSource)
        {
            LLLocation locationElementPointer = HLArrayElementAddressLocation.LoadArrayElementPointer(pFunction, Instance, Index, ElementType);
            LLLocation locationSource         = pFunction.CurrentBlock.EmitConversion(pSource, locationElementPointer.Type.PointerDepthMinusOne);

            pFunction.CurrentBlock.EmitStore(locationElementPointer, locationSource);
        }
Exemplo n.º 14
0
        internal override void Store(LLFunction pFunction, LLLocation pSource)
        {
            LLLocation locationFieldPointer = HLFieldAddressLocation.LoadInstanceFieldPointer(pFunction, Instance, Field);
            LLLocation locationSource       = pFunction.CurrentBlock.EmitConversion(pSource, locationFieldPointer.Type.PointerDepthMinusOne);

            pFunction.CurrentBlock.EmitStore(locationFieldPointer, locationSource);
        }
Exemplo n.º 15
0
        internal override LLLocation Load(LLFunction pFunction)
        {
            LLLocation locationAddress = mAddress.Load(pFunction);

            locationAddress = pFunction.CurrentBlock.EmitConversion(locationAddress, Type.LLType);
            return(locationAddress.Load(pFunction.CurrentBlock));
        }
Exemplo n.º 16
0
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationCondition = mConditionSource.Load(pFunction);

            locationCondition = pFunction.CurrentBlock.EmitConversion(locationCondition, LLModule.BooleanType);
            pFunction.CurrentBlock.EmitBranch(locationCondition, pFunction.Labels.GetByIdentifier(mTrueLabel.Identifier), pFunction.Labels.GetByIdentifier(mFalseLabel.Identifier));
        }
 public static LLGetElementPointerInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pPointerSource, params LLLocation[] pIndexSources)
 {
     LLGetElementPointerInstruction instruction = new LLGetElementPointerInstruction(pFunction);
     instruction.mDestination = pDestination;
     instruction.mPointerSource = pPointerSource;
     instruction.mIndexSources = new List<LLLocation>(pIndexSources);
     return instruction;
 }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
 public static LLCallInstruction Create(LLFunction pFunction, LLLocation pReturnDestination, LLLocation pFunctionSource, List<LLLocation> pParameterSources)
 {
     LLCallInstruction instruction = new LLCallInstruction(pFunction);
     instruction.mReturnDestination = pReturnDestination;
     instruction.mFunctionSource = pFunctionSource;
     instruction.mParameterSources = new List<LLLocation>(pParameterSources);
     return instruction;
 }
 public static LLSignedRightShiftInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pLeftSource, LLLocation pRightSource)
 {
     LLSignedRightShiftInstruction instruction = new LLSignedRightShiftInstruction(pFunction);
     instruction.mDestination = pDestination;
     instruction.mLeftSource = pLeftSource;
     instruction.mRightSource = pRightSource;
     return instruction;
 }
Exemplo n.º 21
0
 internal override LLLocation Load(LLFunction pFunction)
 {
     if (!Parameter.RequiresAddressing)
     {
         throw new NotSupportedException();
     }
     return(LLLocalLocation.Create(Parameter.AddressableLocal));
 }
Exemplo n.º 22
0
        private static void BuildVTableFunctionLookup()
        {
            List <LLParameter> parametersFunction = new List <LLParameter>();

            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), "this"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreateSignedType(32), "index"));
            sVTableFunctionLookup = LLModule.GetOrCreateFunction("VTableFunctionLookup", true, true, false, LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), parametersFunction);
        }
Exemplo n.º 23
0
        internal override LLLocation Load(LLFunction pFunction)
        {
            LLLocation locationLocal     = LLLocalLocation.Create(pFunction.Locals[Temporary.Name]);
            LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(locationLocal.Type.PointerDepthMinusOne));

            pFunction.CurrentBlock.EmitLoad(locationTemporary, locationLocal);
            return(locationTemporary);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
 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));
 }
Exemplo n.º 26
0
        public static LLTruncateInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pSource)
        {
            LLTruncateInstruction instruction = new LLTruncateInstruction(pFunction);

            instruction.mDestination = pDestination;
            instruction.mSource      = pSource;
            return(instruction);
        }
Exemplo n.º 27
0
 public static LLBranchInstruction Create(LLFunction pFunction, LLLocation pConditionSource, LLLabel pTrueTargetLabel, LLLabel pFalseTargetLabel)
 {
     LLBranchInstruction instruction = new LLBranchInstruction(pFunction);
     instruction.mConditionSource = pConditionSource;
     instruction.mTrueTargetLabel = pTrueTargetLabel;
     instruction.mFalseTargetLabel = pFalseTargetLabel;
     return instruction;
 }
Exemplo n.º 28
0
        private static void BuildGCRoot()
        {
            List <LLParameter> parametersFunction = new List <LLParameter>();

            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 2), "ptrloc"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 1), "metadata"));
            sGCRoot = LLModule.GetOrCreateFunction("llvm.gcroot", true, true, false, LLModule.VoidType, parametersFunction);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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);
        }
Exemplo n.º 31
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);
        }
Exemplo n.º 32
0
        public static LLOrInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pLeftSource, LLLocation pRightSource)
        {
            LLOrInstruction instruction = new LLOrInstruction(pFunction);

            instruction.mDestination = pDestination;
            instruction.mLeftSource  = pLeftSource;
            instruction.mRightSource = pRightSource;
            return(instruction);
        }
Exemplo n.º 33
0
        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);
        }
        public static LLGetElementPointerInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pPointerSource, params LLLocation[] pIndexSources)
        {
            LLGetElementPointerInstruction instruction = new LLGetElementPointerInstruction(pFunction);

            instruction.mDestination   = pDestination;
            instruction.mPointerSource = pPointerSource;
            instruction.mIndexSources  = new List <LLLocation>(pIndexSources);
            return(instruction);
        }
Exemplo n.º 35
0
        private static void BuildGCAllocate()
        {
            List <LLParameter> parametersFunction = new List <LLParameter>();

            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreatePointerType(LLModule.GetOrCreateUnsignedType(8), 2), "this"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreateUnsignedType(32), "size"));
            parametersFunction.Add(LLParameter.Create(LLModule.GetOrCreateSignedType(32), "handle"));
            sGCAllocate = LLModule.GetOrCreateFunction("GCAllocate", true, true, false, LLModule.VoidType, parametersFunction);
        }
Exemplo n.º 36
0
        public static LLCallInstruction Create(LLFunction pFunction, LLLocation pReturnDestination, LLLocation pFunctionSource, List <LLLocation> pParameterSources)
        {
            LLCallInstruction instruction = new LLCallInstruction(pFunction);

            instruction.mReturnDestination = pReturnDestination;
            instruction.mFunctionSource    = pFunctionSource;
            instruction.mParameterSources  = new List <LLLocation>(pParameterSources);
            return(instruction);
        }
 public static LLCompareIntegersInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pLeftSource, LLLocation pRightSource, LLCompareIntegersCondition pCondition)
 {
     LLCompareIntegersInstruction instruction = new LLCompareIntegersInstruction(pFunction);
     instruction.mDestination = pDestination;
     instruction.mLeftSource = pLeftSource;
     instruction.mRightSource = pRightSource;
     instruction.mCondition = pCondition;
     return instruction;
 }
 public static LLCompareExchangeInstruction Create(LLFunction pFunction, LLLocation pDestination, LLLocation pPointerSource, LLLocation pComparedSource, LLLocation pNewSource, LLCompareExchangeOrdering pOrdering)
 {
     LLCompareExchangeInstruction instruction = new LLCompareExchangeInstruction(pFunction);
     instruction.mDestination = pDestination;
     instruction.mPointerSource = pPointerSource;
     instruction.mComparedSource = pComparedSource;
     instruction.mNewSource = pNewSource;
     instruction.mOrdering = pOrdering;
     return instruction;
 }
Exemplo n.º 39
0
 public static LLGotoInstruction Create(LLFunction pFunction, LLLabel pTargetLabel)
 {
     LLGotoInstruction instruction = new LLGotoInstruction(pFunction);
     instruction.mTargetLabel = pTargetLabel;
     return instruction;
 }
Exemplo n.º 40
0
 private LLGotoInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 41
0
 public static LLReturnInstruction Create(LLFunction pFunction, LLLocation pSource)
 {
     LLReturnInstruction instruction = new LLReturnInstruction(pFunction);
     instruction.mSource = pSource;
     return instruction;
 }
Exemplo n.º 42
0
 public static LLLabelInstruction Create(LLFunction pFunction, LLLabel pLabel)
 {
     LLLabelInstruction instruction = new LLLabelInstruction(pFunction);
     instruction.mLabel = pLabel;
     return instruction;
 }
Exemplo n.º 43
0
 private LLMultiplyInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 44
0
 public static LLFunctionLocation Create(LLFunction pFunction)
 {
     LLFunctionLocation location = new LLFunctionLocation(LLModule.GetOrCreateFunctionType(pFunction.ReturnType, pFunction.Parameters.ToTypeList()).PointerDepthPlusOne);
     location.mFunction = pFunction;
     return location;
 }
 private LLCompareIntegersInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
 private LLCompareExchangeInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 47
0
 private LLStoreInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 48
0
 private LLXorInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 49
0
 private LLCommentInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 50
0
 private LLReturnInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 51
0
 private LLBranchInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
 private LLSignedRightShiftInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
 private LLIntegerToPointerInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
 private LLGetElementPointerInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 55
0
 private LLSubtractInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
 private LLIntegerToFloatInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 57
0
 public static LLCommentInstruction Create(LLFunction pFunction, string pComment)
 {
     LLCommentInstruction instruction = new LLCommentInstruction(pFunction);
     instruction.mComment = pComment;
     return instruction;
 }
Exemplo n.º 58
0
 private LLLabelInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 59
0
 private LLAddInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }
Exemplo n.º 60
0
 private LLExtendInstruction(LLFunction pFunction)
     : base(pFunction)
 {
 }