llvm.org GIT mirror llvm / 0fd3806
improve the APIs for creating struct and function types with no arguments/elements to not have to create a temporary vector (in the API at least). Patch by Jay Foad! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74584 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
11 changed file(s) with 29 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
2626 Module *M = new Module("test");
2727
2828 // Create the main function: first create the type 'int ()'
29 FunctionType *FT = FunctionType::get(Type::Int32Ty, std::vector(),
30 /*not vararg*/false);
29 FunctionType *FT = FunctionType::get(Type::Int32Ty, /*not vararg*/false);
3130
3231 // By passing a module as the last parameter to the Function constructor,
3332 // it automatically gets appended to the Module.
158158 bool isVarArg ///< Whether this is a variable argument length function
159159 );
160160
161 /// FunctionType::get - Create a FunctionType taking no parameters.
162 ///
163 static FunctionType *get(
164 const Type *Result, ///< The result type
165 bool isVarArg ///< Whether this is a variable argument length function
166 ) {
167 return get(Result, std::vector(), isVarArg);
168 }
169
161170 /// isValidReturnType - Return true if the specified type is valid as a return
162171 /// type.
163172 static bool isValidReturnType(const Type *RetTy);
232241 ///
233242 static StructType *get(const std::vector &Params,
234243 bool isPacked=false);
244
245 /// StructType::get - Create an empty structure type.
246 ///
247 static StructType *get(bool isPacked=false) {
248 return get(std::vector(), isPacked);
249 }
235250
236251 /// StructType::get - This static method is a convenience method for
237252 /// creating structure types by specifying the elements as arguments.
252252
253253 private:
254254 static const FunctionType *create() {
255 std::vector params;
256 return FunctionType::get(TypeBuilder::get(), params, false);
255 return FunctionType::get(TypeBuilder::get(), false);
257256 }
258257 };
259258 template class TypeBuilder {
359358
360359 private:
361360 static const FunctionType *create() {
362 std::vector params;
363 return FunctionType::get(TypeBuilder::get(), params, true);
361 return FunctionType::get(TypeBuilder::get(), true);
364362 }
365363 };
366364 template
326326 DIFactory::DIFactory(Module &m)
327327 : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0),
328328 DeclareFn(0) {
329 EmptyStructPtr = PointerType::getUnqual(StructType::get(NULL, NULL));
329 EmptyStructPtr = PointerType::getUnqual(StructType::get());
330330 }
331331
332332 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
12431243 Lex.Lex(); // Consume the '{'
12441244
12451245 if (EatIfPresent(lltok::rbrace)) {
1246 Result = StructType::get(std::vector(), Packed);
1246 Result = StructType::get(Packed);
12471247 return false;
12481248 }
12491249
270270 // should be on the use list of the llvm.dbg.translation_units global.
271271 //
272272 GlobalVariable *Units =
273 M->getGlobalVariable("llvm.dbg.translation_units",
274 StructType::get(std::vector()));
273 M->getGlobalVariable("llvm.dbg.translation_units", StructType::get());
275274 if (Units == 0)
276275 throw "Program contains no debugging information!";
277276
353352 // should be on the use list of the llvm.dbg.translation_units global.
354353 //
355354 GlobalVariable *Units =
356 M->getGlobalVariable("llvm.dbg.globals",
357 StructType::get(std::vector()));
355 M->getGlobalVariable("llvm.dbg.globals", StructType::get());
358356 if (Units == 0)
359357 throw "Program contains no debugging information!";
360358
452452 // arguments. Make this function and return.
453453
454454 // First, create the function.
455 FunctionType *STy=FunctionType::get(RetTy, std::vector(), false);
455 FunctionType *STy=FunctionType::get(RetTy, false);
456456 Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
457457 F->getParent());
458458
19271927 if (Ctors[i]) {
19281928 CSVals[1] = Ctors[i];
19291929 } else {
1930 const Type *FTy = FunctionType::get(Type::VoidTy,
1931 std::vector(), false);
1930 const Type *FTy = FunctionType::get(Type::VoidTy, false);
19321931 const PointerType *PFTy = PointerType::getUnqual(FTy);
19331932 CSVals[1] = Constant::getNullValue(PFTy);
19341933 CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
9191 // i8*(...) * malloc
9292 // This handles the common declaration of: 'void *malloc();'
9393 const FunctionType *Malloc3Type =
94 FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
95 std::vector(), true);
94 FunctionType::get(PointerType::getUnqual(Type::Int8Ty), true);
9695 if (TyWeHave != Malloc3Type)
9796 // Give up
9897 MallocFunc = 0;
112111 // Check to see if the prototype was forgotten, giving us
113112 // void (...) * free
114113 // This handles the common forward declaration of: 'void free();'
115 const FunctionType* Free2Type = FunctionType::get(Type::VoidTy,
116 std::vector(),true);
114 const FunctionType* Free2Type = FunctionType::get(Type::VoidTy, true);
117115
118116 if (TyWeHave != Free2Type) {
119117 // One last try, check to see if we can find free as
120118 // int (...)* free. This handles the case where NOTHING was declared.
121 const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty,
122 std::vector(),true);
119 const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty, true);
123120
124121 if (TyWeHave != Free3Type) {
125122 // Give up.
8888 const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
8989 // Prototype malloc as "char* malloc(...)", because we don't know in
9090 // doInitialization whether size_t is int or long.
91 FunctionType *FT = FunctionType::get(BPTy, std::vector(), true);
91 FunctionType *FT = FunctionType::get(BPTy, true);
9292 MallocFunc = M.getOrInsertFunction("malloc", FT);
9393 FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
9494 return true;
145145 OS << "IntegerType::get(" << BitWidth << ")";
146146 } else if (VT == MVT::Other) {
147147 // MVT::OtherVT is used to mean the empty struct type here.
148 OS << "StructType::get(std::vector())";
148 OS << "StructType::get()";
149149 } else if (VT == MVT::f32) {
150150 OS << "Type::FloatTy";
151151 } else if (VT == MVT::f64) {