From 2c38d65fd9340b745aeec55acb04819892ed4cb9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 12 Aug 2011 17:31:02 +0000 Subject: add new accessors to reflect new terminology in struct types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137468 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Type.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'lib/VMCore/Type.cpp') diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index bf8af07030..f7ba59606a 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -392,7 +392,7 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef ETypes, // Value not found. Create a new type! ST = new (Context.pImpl->TypeAllocator) StructType(Context); - ST->setSubclassData(SCDB_IsAnonymous); // Anonymous struct. + ST->setSubclassData(SCDB_IsLiteral); // Literal struct. ST->setBody(ETypes, isPacked); return ST; } @@ -478,6 +478,48 @@ StructType *StructType::get(Type *type, ...) { return llvm::StructType::get(Ctx, StructFields); } +StructType *StructType::create(LLVMContext &Context, ArrayRef Elements, + StringRef Name, bool isPacked) { + StructType *ST = createNamed(Context, Name); + ST->setBody(Elements, isPacked); + return ST; +} + +StructType *StructType::create(LLVMContext &Context, ArrayRef Elements) { + return create(Context, Elements, StringRef()); +} + + +StructType *StructType::create(ArrayRef Elements, StringRef Name, + bool isPacked) { + assert(!Elements.empty() && + "This method may not be invoked with an empty list"); + return create(Elements[0]->getContext(), Elements, Name, isPacked); +} + +StructType *StructType::create(ArrayRef Elements) { + assert(!Elements.empty() && + "This method may not be invoked with an empty list"); + return create(Elements[0]->getContext(), Elements, StringRef()); +} + +StructType *StructType::create(StringRef Name, Type *type, ...) { + assert(type != 0 && "Cannot create a struct type with no elements with this"); + LLVMContext &Ctx = type->getContext(); + va_list ap; + SmallVector StructFields; + va_start(ap, type); + while (type) { + StructFields.push_back(type); + type = va_arg(ap, llvm::Type*); + } + return llvm::StructType::create(Ctx, StructFields, Name); +} + + + + + StructType *StructType::createNamed(LLVMContext &Context, StringRef Name, ArrayRef Elements, bool isPacked) { StructType *ST = createNamed(Context, Name); @@ -506,7 +548,7 @@ StructType *StructType::createNamed(StringRef Name, Type *type, ...) { } StringRef StructType::getName() const { - assert(!isAnonymous() && "Anonymous structs never have names"); + assert(!isLiteral() && "Literal structs never have names"); if (SymbolTableEntry == 0) return StringRef(); return ((StringMapEntry *)SymbolTableEntry)->getKey(); -- cgit v1.2.3