示例#1
0
 public static LLParameter Create(LLType pType, string pIdentifier)
 {
     LLParameter parameter = new LLParameter();
     parameter.mType = pType;
     parameter.mIdentifier = pIdentifier;
     return parameter;
 }
示例#2
0
 public static LLTemporary Create(LLType pType, int pIdentifier)
 {
     LLTemporary temporary = new LLTemporary();
     temporary.mType = pType;
     temporary.mIdentifier = pIdentifier;
     return temporary;
 }
示例#3
0
 public static LLLocal Create(LLType pType, string pIdentifier)
 {
     LLLocal local = new LLLocal();
     local.mType = pType;
     local.mIdentifier = pIdentifier;
     return local;
 }
示例#4
0
 public static LLLiteral Create(LLType pType, string pValue)
 {
     LLLiteral literal = new LLLiteral();
     literal.mType = pType;
     literal.mValue = pValue;
     return literal;
 }
示例#5
0
 public static LLGlobal Create(LLType pType, string pIdentifier)
 {
     LLGlobal global = new LLGlobal();
     global.mType = pType;
     global.mIdentifier = pIdentifier;
     return global;
 }
示例#6
0
        public static LLType BinaryResult(LLType pLeftType, LLType pRightType)
        {
            if (pLeftType.Primitive == LLPrimitive.Void || pRightType.Primitive == LLPrimitive.Void) throw new NotSupportedException();
            if (pLeftType.Primitive == LLPrimitive.Function || pRightType.Primitive == LLPrimitive.Function) throw new NotSupportedException();
            if (pLeftType.Primitive == LLPrimitive.Vector || pRightType.Primitive == LLPrimitive.Vector) throw new NotSupportedException();
            if (pLeftType.Primitive == LLPrimitive.Array || pRightType.Primitive == LLPrimitive.Array) throw new NotSupportedException();
            if (pLeftType.Primitive == LLPrimitive.Structure || pRightType.Primitive == LLPrimitive.Structure) throw new NotSupportedException();

            if (pLeftType.Primitive == LLPrimitive.Pointer && pRightType.Primitive == LLPrimitive.Pointer) return GetOrCreateSignedType(PointerSizeInBits);

            if (pLeftType == pRightType) return pLeftType;
            // u1, i8, u8, i16, u16, i32, u32, i64, u64, ptr, f32, f64
            if (pLeftType.Primitive == LLPrimitive.Float && pRightType.Primitive == LLPrimitive.Float) return pLeftType.SizeInBits >= pRightType.SizeInBits ? pLeftType : pRightType;
            if (pLeftType.Primitive == LLPrimitive.Float) return pLeftType;
            if (pRightType.Primitive == LLPrimitive.Float) return pRightType;
            // u1, i8, u8, i16, u16, i32, u32, i64, u64, ptr
            if (pLeftType.Primitive == LLPrimitive.Pointer && pRightType.SizeInBits <= PointerSizeInBits) return GetOrCreateSignedType(PointerSizeInBits);
            if (pLeftType.Primitive == LLPrimitive.Pointer && pRightType.SizeInBits > PointerSizeInBits) return GetOrCreateSignedType(pRightType.SizeInBits);
            if (pRightType.Primitive == LLPrimitive.Pointer && pLeftType.SizeInBits <= PointerSizeInBits) return GetOrCreateSignedType(PointerSizeInBits);
            if (pRightType.Primitive == LLPrimitive.Pointer && pLeftType.SizeInBits > PointerSizeInBits) return GetOrCreateSignedType(pLeftType.SizeInBits);
            // u1, i8, u8, i16, u16, i32, u32, i64, u64
            if (pLeftType.SizeInBits > pRightType.SizeInBits) return pLeftType;
            if (pRightType.SizeInBits > pLeftType.SizeInBits) return pRightType;
            // i, u
            if (pLeftType.Primitive == LLPrimitive.Unsigned) return pLeftType;
            if (pRightType.Primitive == LLPrimitive.Unsigned) return pRightType;
            // i... should not get here, means both are Signed of the same size, should be same type handled earlier
            throw new NotSupportedException();
        }
示例#7
0
        public static LLType GetOrCreateVectorType(LLType pElementType, int pElementCount)
        {
            LLType type      = null;
            string signature = GetVectorSignature(pElementType, pElementCount);

            if (!sTypes.TryGetValue(signature, out type))
            {
                type = CreateVectorType(pElementType, pElementCount);
            }
            return(type);
        }
示例#8
0
        private static LLType CreateVectorType(LLType pElementType, int pElementCount)
        {
            LLType type = new LLType();

            type.Primitive         = LLPrimitive.Vector;
            type.SizeInBits        = pElementCount * pElementType.SizeInBits;
            type.ElementCount      = pElementCount;
            type.ElementType       = pElementType;
            sTypes[type.Signature] = type;
            return(type);
        }
示例#9
0
        public static LLType GetOrCreateFunctionType(LLType pReturnType, List <LLType> pParameterTypes)
        {
            LLType type      = null;
            string signature = GetFunctionSignature(pReturnType, pParameterTypes);

            if (!sTypes.TryGetValue(signature, out type))
            {
                type = CreateFunctionType(pReturnType, pParameterTypes);
            }
            return(type);
        }
示例#10
0
        private static LLType CreateFunctionType(LLType pReturnType, List <LLType> pParameterTypes)
        {
            LLType type = new LLType();

            type.Primitive          = LLPrimitive.Function;
            type.SizeInBits         = 0;
            type.FunctionReturn     = pReturnType;
            type.FunctionParameters = new List <LLType>(pParameterTypes);
            sTypes[type.Signature]  = type;
            return(type);
        }
示例#11
0
        public static LLType GetOrCreatePointerType(LLType pPointerBase, int pPointerDepth)
        {
            LLType type      = null;
            string signature = GetPointerSignature(pPointerBase, pPointerDepth);

            if (!sTypes.TryGetValue(signature, out type))
            {
                type = CreatePointerType(pPointerBase, pPointerDepth);
            }
            return(type);
        }
示例#12
0
        private static LLType CreatePointerType(LLType pPointerBase, int pPointerDepth)
        {
            LLType type = new LLType();

            type.Primitive         = LLPrimitive.Pointer;
            type.SizeInBits        = LLModule.PointerSizeInBits;
            type.PointerBase       = pPointerBase;
            type.PointerDepth      = pPointerDepth;
            sTypes[type.Signature] = type;
            return(type);
        }
示例#13
0
        public static string GetFunctionSignature(LLType pReturnType, List <LLType> pParameterTypes)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("(function:{0}", pReturnType.Signature);
            foreach (LLType type in pParameterTypes)
            {
                sb.AppendFormat(":{0}", type.Signature);
            }
            sb.Append(")");
            return(sb.ToString());
        }
示例#14
0
        private static LLType CreateStructureType(string pName, bool pPacked, List <LLType> pFieldTypes)
        {
            LLType type = new LLType();

            type.Primitive         = LLPrimitive.Structure;
            type.SizeInBits        = pFieldTypes.Sum(t => t.SizeInBits);
            type.StructureName     = pName;
            type.StructurePacked   = pPacked;
            type.StructureFields   = new List <LLType>(pFieldTypes);
            sTypes[type.Signature] = type;
            return(type);
        }
示例#15
0
        public static LLType GetOrCreateUnsignedType(int pSizeInBits)
        {
            if (pSizeInBits == 1)
            {
                return(BooleanType);
            }
            LLType type      = null;
            string signature = GetUnsignedSignature(pSizeInBits);

            if (!sTypes.TryGetValue(signature, out type))
            {
                type = CreatePrimitiveType(LLPrimitive.Unsigned, pSizeInBits);
            }
            return(type);
        }
示例#16
0
 public static LLType GetOrCreateFunctionType(LLType pReturnType, List<LLType> pParameterTypes)
 {
     LLType type = null;
     string signature = GetFunctionSignature(pReturnType, pParameterTypes);
     if (!sTypes.TryGetValue(signature, out type)) type = CreateFunctionType(pReturnType, pParameterTypes);
     return type;
 }
示例#17
0
 public static LLType GetOrCreatePointerType(LLType pPointerBase, int pPointerDepth)
 {
     LLType type = null;
     string signature = GetPointerSignature(pPointerBase, pPointerDepth);
     if (!sTypes.TryGetValue(signature, out type)) type = CreatePointerType(pPointerBase, pPointerDepth);
     return type;
 }
示例#18
0
 public static string GetFunctionSignature(LLType pReturnType, List<LLType> pParameterTypes)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("(function:{0}", pReturnType.Signature);
     foreach (LLType type in pParameterTypes)
         sb.AppendFormat(":{0}", type.Signature);
     sb.Append(")");
     return sb.ToString();
 }
示例#19
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;
 }
示例#20
0
 private static LLType CreateFunctionType(LLType pReturnType, List<LLType> pParameterTypes)
 {
     LLType type = new LLType();
     type.Primitive = LLPrimitive.Function;
     type.SizeInBits = 0;
     type.FunctionReturn = pReturnType;
     type.FunctionParameters = new List<LLType>(pParameterTypes);
     sTypes[type.Signature] = type;
     return type;
 }
示例#21
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);
        }
示例#22
0
 public static string GetVectorSignature(LLType pElementType, int pElementCount)
 {
     return(string.Format("(vector:{0}:{1})", pElementType.Signature, pElementCount));
 }
示例#23
0
 public static string GetVectorSignature(LLType pElementType, int pElementCount)
 {
     return string.Format("(vector:{0}:{1})", pElementType.Signature, pElementCount);
 }
示例#24
0
 private static LLType CreateVectorType(LLType pElementType, int pElementCount)
 {
     LLType type = new LLType();
     type.Primitive = LLPrimitive.Vector;
     type.SizeInBits = pElementCount * pElementType.SizeInBits;
     type.ElementCount = pElementCount;
     type.ElementType = pElementType;
     sTypes[type.Signature] = type;
     return type;
 }
示例#25
0
 public static LLGlobal CreateGlobal(LLType pType, string pIdentifier)
 {
     LLGlobal global = LLGlobal.Create(pType, pIdentifier);
     sGlobals.Add(global.Identifier, global);
     return global;
 }
示例#26
0
 private static LLType CreatePrimitiveType(LLPrimitive pPrimitive, int pSizeInBits)
 {
     LLType type = new LLType();
     type.Primitive = pPrimitive;
     type.SizeInBits = pSizeInBits;
     sTypes[type.Signature] = type;
     return type;
 }
示例#27
0
        public static LLType BinaryResult(LLType pLeftType, LLType pRightType)
        {
            if (pLeftType.Primitive == LLPrimitive.Void || pRightType.Primitive == LLPrimitive.Void)
            {
                throw new NotSupportedException();
            }
            if (pLeftType.Primitive == LLPrimitive.Function || pRightType.Primitive == LLPrimitive.Function)
            {
                throw new NotSupportedException();
            }
            if (pLeftType.Primitive == LLPrimitive.Vector || pRightType.Primitive == LLPrimitive.Vector)
            {
                throw new NotSupportedException();
            }
            if (pLeftType.Primitive == LLPrimitive.Array || pRightType.Primitive == LLPrimitive.Array)
            {
                throw new NotSupportedException();
            }
            if (pLeftType.Primitive == LLPrimitive.Structure || pRightType.Primitive == LLPrimitive.Structure)
            {
                throw new NotSupportedException();
            }

            if (pLeftType.Primitive == LLPrimitive.Pointer && pRightType.Primitive == LLPrimitive.Pointer)
            {
                return(GetOrCreateSignedType(PointerSizeInBits));
            }

            if (pLeftType == pRightType)
            {
                return(pLeftType);
            }
            // u1, i8, u8, i16, u16, i32, u32, i64, u64, ptr, f32, f64
            if (pLeftType.Primitive == LLPrimitive.Float && pRightType.Primitive == LLPrimitive.Float)
            {
                return(pLeftType.SizeInBits >= pRightType.SizeInBits ? pLeftType : pRightType);
            }
            if (pLeftType.Primitive == LLPrimitive.Float)
            {
                return(pLeftType);
            }
            if (pRightType.Primitive == LLPrimitive.Float)
            {
                return(pRightType);
            }
            // u1, i8, u8, i16, u16, i32, u32, i64, u64, ptr
            if (pLeftType.Primitive == LLPrimitive.Pointer && pRightType.SizeInBits <= PointerSizeInBits)
            {
                return(GetOrCreateSignedType(PointerSizeInBits));
            }
            if (pLeftType.Primitive == LLPrimitive.Pointer && pRightType.SizeInBits > PointerSizeInBits)
            {
                return(GetOrCreateSignedType(pRightType.SizeInBits));
            }
            if (pRightType.Primitive == LLPrimitive.Pointer && pLeftType.SizeInBits <= PointerSizeInBits)
            {
                return(GetOrCreateSignedType(PointerSizeInBits));
            }
            if (pRightType.Primitive == LLPrimitive.Pointer && pLeftType.SizeInBits > PointerSizeInBits)
            {
                return(GetOrCreateSignedType(pLeftType.SizeInBits));
            }
            // u1, i8, u8, i16, u16, i32, u32, i64, u64
            if (pLeftType.SizeInBits > pRightType.SizeInBits)
            {
                return(pLeftType);
            }
            if (pRightType.SizeInBits > pLeftType.SizeInBits)
            {
                return(pRightType);
            }
            // i, u
            if (pLeftType.Primitive == LLPrimitive.Unsigned)
            {
                return(pLeftType);
            }
            if (pRightType.Primitive == LLPrimitive.Unsigned)
            {
                return(pRightType);
            }
            // i... should not get here, means both are Signed of the same size, should be same type handled earlier
            throw new NotSupportedException();
        }
示例#28
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);
        }
示例#29
0
 public static LLType GetOrCreateVectorType(LLType pElementType, int pElementCount)
 {
     LLType type = null;
     string signature = GetVectorSignature(pElementType, pElementCount);
     if (!sTypes.TryGetValue(signature, out type)) type = CreateVectorType(pElementType, pElementCount);
     return type;
 }
示例#30
0
 public static string GetPointerSignature(LLType pPointerBase, int pPointerDepth)
 {
     return(string.Format("(pointer:{0}:{1})", pPointerBase.Signature, pPointerDepth));
 }
示例#31
0
 public static string GetPointerSignature(LLType pPointerBase, int pPointerDepth)
 {
     return string.Format("(pointer:{0}:{1})", pPointerBase.Signature, pPointerDepth);
 }
示例#32
0
 public static string GetArraySignature(LLType pElementType, int pElementCount)
 {
     return string.Format("(array:{0}:{1})", pElementType.Signature, pElementCount);
 }
示例#33
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;
 }
示例#34
0
 public static string GetFunctionIdentifier(string pName, LLType pReturnType, List<LLParameter> pParameters)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("{0}:{1}", pReturnType, pName);
     foreach (LLParameter parameter in pParameters)
         sb.AppendFormat(":{0}", parameter.Type);
     return sb.ToString();
 }
示例#35
0
 private static LLType CreatePointerType(LLType pPointerBase, int pPointerDepth)
 {
     LLType type = new LLType();
     type.Primitive = LLPrimitive.Pointer;
     type.SizeInBits = LLModule.PointerSizeInBits;
     type.PointerBase = pPointerBase;
     type.PointerDepth = pPointerDepth;
     sTypes[type.Signature] = type;
     return type;
 }
示例#36
0
 public static string GetArraySignature(LLType pElementType, int pElementCount)
 {
     return(string.Format("(array:{0}:{1})", pElementType.Signature, pElementCount));
 }
示例#37
0
 private static LLType CreateStructureType(string pName, bool pPacked, List<LLType> pFieldTypes)
 {
     LLType type = new LLType();
     type.Primitive = LLPrimitive.Structure;
     type.SizeInBits = pFieldTypes.Sum(t => t.SizeInBits);
     type.StructureName = pName;
     type.StructurePacked = pPacked;
     type.StructureFields = new List<LLType>(pFieldTypes);
     sTypes[type.Signature] = type;
     return type;
 }
示例#38
0
        public LLLocation EmitConversion(LLLocation pSource, LLType pType)
        {
            if (pSource.Type == pType)
            {
                return(pSource);
            }
            LLLocation destination = pSource;

            switch (pSource.Type.Primitive)
            {
            case LLPrimitive.Signed:
            {
                switch (pType.Primitive)
                {
                case LLPrimitive.Signed:             // Signed to Signed
                {
                    if (pSource.Type.SizeInBits != pType.SizeInBits)
                    {
                        destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    }
                    if (pSource.Type.SizeInBits > pType.SizeInBits)
                    {
                        EmitTruncate(destination, pSource);
                    }
                    else if (pSource.Type.SizeInBits < pType.SizeInBits)
                    {
                        EmitExtend(destination, pSource);
                    }
                    break;
                }

                case LLPrimitive.Unsigned:             // Signed to Unsigned
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    if (pSource.Type.SizeInBits > pType.SizeInBits)
                    {
                        EmitTruncate(destination, pSource);
                    }
                    else if (pSource.Type.SizeInBits < pType.SizeInBits)
                    {
                        EmitExtend(destination, pSource);
                    }
                    else
                    {
                        EmitAdd(destination, pSource, LLLiteralLocation.Create(LLLiteral.Create(pType, "0")));
                    }
                    break;
                }

                case LLPrimitive.Float:             // Signed to Float
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitIntegerToFloat(destination, pSource);
                    break;
                }

                case LLPrimitive.Pointer:             // Signed to Pointer
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitIntegerToPointer(destination, pSource);
                    break;
                }

                default: throw new NotSupportedException();
                }
                break;
            }

            case LLPrimitive.Unsigned:
            {
                switch (pType.Primitive)
                {
                case LLPrimitive.Signed:             // Unsigned to Signed
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    if (pSource.Type.SizeInBits > pType.SizeInBits)
                    {
                        EmitTruncate(destination, pSource);
                    }
                    else if (pSource.Type.SizeInBits < pType.SizeInBits)
                    {
                        EmitExtend(destination, pSource);
                    }
                    else
                    {
                        EmitAdd(destination, pSource, LLLiteralLocation.Create(LLLiteral.Create(pType, "0")));
                    }
                    break;
                }

                case LLPrimitive.Unsigned:             // Unsigned to Unsigned
                {
                    if (pSource.Type.SizeInBits != pType.SizeInBits)
                    {
                        destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    }
                    if (pSource.Type.SizeInBits > pType.SizeInBits)
                    {
                        EmitTruncate(destination, pSource);
                    }
                    else if (pSource.Type.SizeInBits < pType.SizeInBits)
                    {
                        EmitExtend(destination, pSource);
                    }
                    break;
                }

                case LLPrimitive.Float:             // Unsigned to Float
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitIntegerToFloat(destination, pSource);
                    break;
                }

                case LLPrimitive.Pointer:             // Unsigned to Pointer
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitIntegerToPointer(destination, pSource);
                    break;
                }

                default: throw new NotSupportedException();
                }
                break;
            }

            case LLPrimitive.Float:
            {
                switch (pType.Primitive)
                {
                case LLPrimitive.Signed:             // Float to Signed
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitFloatToInteger(destination, pSource);
                    break;
                }

                case LLPrimitive.Unsigned:             // Float to Unsigned
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitFloatToInteger(destination, pSource);
                    break;
                }

                case LLPrimitive.Float:             // Float to Float
                {
                    if (pSource.Type.SizeInBits != pType.SizeInBits)
                    {
                        destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    }
                    if (pSource.Type.SizeInBits > pType.SizeInBits)
                    {
                        EmitTruncate(destination, pSource);
                    }
                    else if (pSource.Type.SizeInBits < pType.SizeInBits)
                    {
                        EmitExtend(destination, pSource);
                    }
                    break;
                }

                case LLPrimitive.Pointer:             // Float to Pointer
                {
                    LLLocation temporaryInteger = LLTemporaryLocation.Create(Function.CreateTemporary(LLModule.GetOrCreateUnsignedType(pType.SizeInBits)));
                    EmitFloatToInteger(temporaryInteger, pSource);
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitIntegerToPointer(destination, temporaryInteger);
                    break;
                }

                default: throw new NotSupportedException();
                }
                break;
            }

            case LLPrimitive.Pointer:
            {
                switch (pType.Primitive)
                {
                case LLPrimitive.Signed:             // Pointer to Signed
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitPointerToInteger(destination, pSource);
                    break;
                }

                case LLPrimitive.Unsigned:             // Pointer to Unsigned
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitPointerToInteger(destination, pSource);
                    break;
                }

                case LLPrimitive.Float:             // Pointer to Float
                {
                    LLLocation temporaryInteger = LLTemporaryLocation.Create(Function.CreateTemporary(LLModule.GetOrCreateUnsignedType(pSource.Type.SizeInBits)));
                    EmitPointerToInteger(temporaryInteger, pSource);
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitIntegerToFloat(destination, temporaryInteger);
                    break;
                }

                case LLPrimitive.Pointer:             // Pointer to Pointer
                {
                    destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                    EmitBitcast(destination, pSource);
                    break;
                }

                default: throw new NotSupportedException();
                }
                break;
            }

            default: throw new NotSupportedException();
            }
            return(destination);
        }
示例#39
0
 public LLLocal CreateLocal(LLType pType, string pIdentifier)
 {
     if (mLocals == null) mLocals = new LLLocalList();
     LLLocal local = LLLocal.Create(pType.PointerDepthPlusOne, pIdentifier);
     mLocals.Add(local);
     return local;
 }
 public LLLocation EmitConversion(LLLocation pSource, LLType pType)
 {
     if (pSource.Type == pType) return pSource;
     LLLocation destination = pSource;
     switch (pSource.Type.Primitive)
     {
         case LLPrimitive.Signed:
             {
                 switch (pType.Primitive)
                 {
                     case LLPrimitive.Signed: // Signed to Signed
                         {
                             if (pSource.Type.SizeInBits != pType.SizeInBits) destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             if (pSource.Type.SizeInBits > pType.SizeInBits) EmitTruncate(destination, pSource);
                             else if (pSource.Type.SizeInBits < pType.SizeInBits) EmitExtend(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Unsigned: // Signed to Unsigned
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             if (pSource.Type.SizeInBits > pType.SizeInBits) EmitTruncate(destination, pSource);
                             else if (pSource.Type.SizeInBits < pType.SizeInBits) EmitExtend(destination, pSource);
                             else EmitAdd(destination, pSource, LLLiteralLocation.Create(LLLiteral.Create(pType, "0")));
                             break;
                         }
                     case LLPrimitive.Float: // Signed to Float
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitIntegerToFloat(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Pointer: // Signed to Pointer
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitIntegerToPointer(destination, pSource);
                             break;
                         }
                     default: throw new NotSupportedException();
                 }
                 break;
             }
         case LLPrimitive.Unsigned:
             {
                 switch (pType.Primitive)
                 {
                     case LLPrimitive.Signed: // Unsigned to Signed
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             if (pSource.Type.SizeInBits > pType.SizeInBits) EmitTruncate(destination, pSource);
                             else if (pSource.Type.SizeInBits < pType.SizeInBits) EmitExtend(destination, pSource);
                             else EmitAdd(destination, pSource, LLLiteralLocation.Create(LLLiteral.Create(pType, "0")));
                             break;
                         }
                     case LLPrimitive.Unsigned: // Unsigned to Unsigned
                         {
                             if (pSource.Type.SizeInBits != pType.SizeInBits) destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             if (pSource.Type.SizeInBits > pType.SizeInBits) EmitTruncate(destination, pSource);
                             else if (pSource.Type.SizeInBits < pType.SizeInBits) EmitExtend(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Float: // Unsigned to Float
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitIntegerToFloat(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Pointer: // Unsigned to Pointer
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitIntegerToPointer(destination, pSource);
                             break;
                         }
                     default: throw new NotSupportedException();
                 }
                 break;
             }
         case LLPrimitive.Float:
             {
                 switch (pType.Primitive)
                 {
                     case LLPrimitive.Signed: // Float to Signed
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitFloatToInteger(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Unsigned: // Float to Unsigned
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitFloatToInteger(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Float: // Float to Float
                         {
                             if (pSource.Type.SizeInBits != pType.SizeInBits) destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             if (pSource.Type.SizeInBits > pType.SizeInBits) EmitTruncate(destination, pSource);
                             else if (pSource.Type.SizeInBits < pType.SizeInBits) EmitExtend(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Pointer: // Float to Pointer
                         {
                             LLLocation temporaryInteger = LLTemporaryLocation.Create(Function.CreateTemporary(LLModule.GetOrCreateUnsignedType(pType.SizeInBits)));
                             EmitFloatToInteger(temporaryInteger, pSource);
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitIntegerToPointer(destination, temporaryInteger);
                             break;
                         }
                     default: throw new NotSupportedException();
                 }
                 break;
             }
         case LLPrimitive.Pointer:
             {
                 switch (pType.Primitive)
                 {
                     case LLPrimitive.Signed: // Pointer to Signed
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitPointerToInteger(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Unsigned: // Pointer to Unsigned
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitPointerToInteger(destination, pSource);
                             break;
                         }
                     case LLPrimitive.Float: // Pointer to Float
                         {
                             LLLocation temporaryInteger = LLTemporaryLocation.Create(Function.CreateTemporary(LLModule.GetOrCreateUnsignedType(pSource.Type.SizeInBits)));
                             EmitPointerToInteger(temporaryInteger, pSource);
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitIntegerToFloat(destination, temporaryInteger);
                             break;
                         }
                     case LLPrimitive.Pointer: // Pointer to Pointer
                         {
                             destination = LLTemporaryLocation.Create(Function.CreateTemporary(pType));
                             EmitBitcast(destination, pSource);
                             break;
                         }
                     default: throw new NotSupportedException();
                 }
                 break;
             }
         default: throw new NotSupportedException();
     }
     return destination;
 }
示例#41
0
 public LLTemporary CreateTemporary(LLType pType)
 {
     return(LLTemporary.Create(pType, mTemporaryIndexer++));
 }
示例#42
0
 protected LLLocation(LLType pType)
 {
     mType = pType;
 }
示例#43
0
 public LLTemporary CreateTemporary(LLType pType)
 {
     return LLTemporary.Create(pType, mTemporaryIndexer++);
 }
示例#44
0
 protected LLLocation(LLType pType)
 {
     mType = pType;
 }