Example #1
0
 public static LLParameter Create(LLType pType, string pIdentifier)
 {
     LLParameter parameter = new LLParameter();
     parameter.mType = pType;
     parameter.mIdentifier = pIdentifier;
     return parameter;
 }
Example #2
0
 public static LLTemporary Create(LLType pType, int pIdentifier)
 {
     LLTemporary temporary = new LLTemporary();
     temporary.mType = pType;
     temporary.mIdentifier = pIdentifier;
     return temporary;
 }
Example #3
0
 public static LLLocal Create(LLType pType, string pIdentifier)
 {
     LLLocal local = new LLLocal();
     local.mType = pType;
     local.mIdentifier = pIdentifier;
     return local;
 }
Example #4
0
 public static LLLiteral Create(LLType pType, string pValue)
 {
     LLLiteral literal = new LLLiteral();
     literal.mType = pType;
     literal.mValue = pValue;
     return literal;
 }
Example #5
0
 public static LLGlobal Create(LLType pType, string pIdentifier)
 {
     LLGlobal global = new LLGlobal();
     global.mType = pType;
     global.mIdentifier = pIdentifier;
     return global;
 }
Example #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();
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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());
        }
Example #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);
        }
Example #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);
        }
Example #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;
 }
Example #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;
 }
Example #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();
 }
Example #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;
 }
Example #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;
 }
Example #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);
        }
Example #22
0
 public static string GetVectorSignature(LLType pElementType, int pElementCount)
 {
     return(string.Format("(vector:{0}:{1})", pElementType.Signature, pElementCount));
 }
Example #23
0
 public static string GetVectorSignature(LLType pElementType, int pElementCount)
 {
     return string.Format("(vector:{0}:{1})", pElementType.Signature, pElementCount);
 }
Example #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;
 }
Example #25
0
 public static LLGlobal CreateGlobal(LLType pType, string pIdentifier)
 {
     LLGlobal global = LLGlobal.Create(pType, pIdentifier);
     sGlobals.Add(global.Identifier, global);
     return global;
 }
Example #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;
 }
Example #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();
        }
Example #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);
        }
Example #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;
 }
Example #30
0
 public static string GetPointerSignature(LLType pPointerBase, int pPointerDepth)
 {
     return(string.Format("(pointer:{0}:{1})", pPointerBase.Signature, pPointerDepth));
 }
Example #31
0
 public static string GetPointerSignature(LLType pPointerBase, int pPointerDepth)
 {
     return string.Format("(pointer:{0}:{1})", pPointerBase.Signature, pPointerDepth);
 }
Example #32
0
 public static string GetArraySignature(LLType pElementType, int pElementCount)
 {
     return string.Format("(array:{0}:{1})", pElementType.Signature, pElementCount);
 }
Example #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;
 }
Example #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();
 }
Example #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;
 }
Example #36
0
 public static string GetArraySignature(LLType pElementType, int pElementCount)
 {
     return(string.Format("(array:{0}:{1})", pElementType.Signature, pElementCount));
 }
Example #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;
 }
Example #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);
        }
Example #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;
 }
Example #41
0
 public LLTemporary CreateTemporary(LLType pType)
 {
     return(LLTemporary.Create(pType, mTemporaryIndexer++));
 }
Example #42
0
 protected LLLocation(LLType pType)
 {
     mType = pType;
 }
Example #43
0
 public LLTemporary CreateTemporary(LLType pType)
 {
     return LLTemporary.Create(pType, mTemporaryIndexer++);
 }
Example #44
0
 protected LLLocation(LLType pType)
 {
     mType = pType;
 }