diff options
author | Chris Lattner <sabre@nondot.org> | 2010-02-12 20:49:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-02-12 20:49:41 +0000 |
commit | 392be58cad0f051b4e7e252b44cef14b547f9b81 (patch) | |
tree | 94d1ae41a937c2ba15293075eca262842da5d3fe /llvm/lib/VMCore/Core.cpp | |
parent | bdf1b9520cf4be11020a6d2af5b84b33c12e1514 (diff) | |
download | bcm5719-llvm-392be58cad0f051b4e7e252b44cef14b547f9b81.tar.gz bcm5719-llvm-392be58cad0f051b4e7e252b44cef14b547f9b81.zip |
Add support for a union type in LLVM IR. Patch by Talin!
llvm-svn: 96011
Diffstat (limited to 'llvm/lib/VMCore/Core.cpp')
-rw-r--r-- | llvm/lib/VMCore/Core.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp index 1755cd213e2..a044fc5b1a0 100644 --- a/llvm/lib/VMCore/Core.cpp +++ b/llvm/lib/VMCore/Core.cpp @@ -141,6 +141,8 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { return LLVMFunctionTypeKind; case Type::StructTyID: return LLVMStructTypeKind; + case Type::UnionTyID: + return LLVMUnionTypeKind; case Type::ArrayTyID: return LLVMArrayTypeKind; case Type::PointerTyID: @@ -299,6 +301,35 @@ LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) { return unwrap<StructType>(StructTy)->isPacked(); } +/*--.. Operations on union types ..........................................--*/ + +LLVMTypeRef LLVMUnionTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, + unsigned ElementCount) { + SmallVector<const Type*, 8> Tys; + for (LLVMTypeRef *I = ElementTypes, + *E = ElementTypes + ElementCount; I != E; ++I) + Tys.push_back(unwrap(*I)); + + return wrap(UnionType::get(&Tys[0], Tys.size())); +} + +LLVMTypeRef LLVMUnionType(LLVMTypeRef *ElementTypes, + unsigned ElementCount, int Packed) { + return LLVMUnionTypeInContext(LLVMGetGlobalContext(), ElementTypes, + ElementCount); +} + +unsigned LLVMCountUnionElementTypes(LLVMTypeRef UnionTy) { + return unwrap<UnionType>(UnionTy)->getNumElements(); +} + +void LLVMGetUnionElementTypes(LLVMTypeRef UnionTy, LLVMTypeRef *Dest) { + UnionType *Ty = unwrap<UnionType>(UnionTy); + for (FunctionType::param_iterator I = Ty->element_begin(), + E = Ty->element_end(); I != E; ++I) + *Dest++ = wrap(*I); +} + /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/ LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) { |