public static LLParameter Create(LLType pType, string pIdentifier) { LLParameter parameter = new LLParameter(); parameter.mType = pType; parameter.mIdentifier = pIdentifier; return parameter; }
public static LLTemporary Create(LLType pType, int pIdentifier) { LLTemporary temporary = new LLTemporary(); temporary.mType = pType; temporary.mIdentifier = pIdentifier; return temporary; }
public static LLLocal Create(LLType pType, string pIdentifier) { LLLocal local = new LLLocal(); local.mType = pType; local.mIdentifier = pIdentifier; return local; }
public static LLLiteral Create(LLType pType, string pValue) { LLLiteral literal = new LLLiteral(); literal.mType = pType; literal.mValue = pValue; return literal; }
public static LLGlobal Create(LLType pType, string pIdentifier) { LLGlobal global = new LLGlobal(); global.mType = pType; global.mIdentifier = pIdentifier; return global; }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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()); }
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); }
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); }
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; }
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; }
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(); }
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; }
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; }
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); }
public static string GetVectorSignature(LLType pElementType, int pElementCount) { return(string.Format("(vector:{0}:{1})", pElementType.Signature, pElementCount)); }
public static string GetVectorSignature(LLType pElementType, int pElementCount) { return string.Format("(vector:{0}:{1})", pElementType.Signature, pElementCount); }
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; }
public static LLGlobal CreateGlobal(LLType pType, string pIdentifier) { LLGlobal global = LLGlobal.Create(pType, pIdentifier); sGlobals.Add(global.Identifier, global); return global; }
private static LLType CreatePrimitiveType(LLPrimitive pPrimitive, int pSizeInBits) { LLType type = new LLType(); type.Primitive = pPrimitive; type.SizeInBits = pSizeInBits; sTypes[type.Signature] = type; return type; }
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(); }
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); }
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; }
public static string GetPointerSignature(LLType pPointerBase, int pPointerDepth) { return(string.Format("(pointer:{0}:{1})", pPointerBase.Signature, pPointerDepth)); }
public static string GetPointerSignature(LLType pPointerBase, int pPointerDepth) { return string.Format("(pointer:{0}:{1})", pPointerBase.Signature, pPointerDepth); }
public static string GetArraySignature(LLType pElementType, int pElementCount) { return string.Format("(array:{0}:{1})", pElementType.Signature, pElementCount); }
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; }
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(); }
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; }
public static string GetArraySignature(LLType pElementType, int pElementCount) { return(string.Format("(array:{0}:{1})", pElementType.Signature, pElementCount)); }
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; }
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); }
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; }
public LLTemporary CreateTemporary(LLType pType) { return(LLTemporary.Create(pType, mTemporaryIndexer++)); }
protected LLLocation(LLType pType) { mType = pType; }
public LLTemporary CreateTemporary(LLType pType) { return LLTemporary.Create(pType, mTemporaryIndexer++); }