Push LLVMContexts through the IntegerType APIs.
[oota-llvm.git] / lib / VMCore / Module.cpp
index 35db8d25b5bf598cfa933f5de267d1ad784054c8..add24491079e04c0c362909c54457702c589e518 100644 (file)
@@ -31,14 +31,15 @@ using namespace llvm;
 //
 
 GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
-  GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), Type::Int32Ty,
+  GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), 
+                                           Type::getInt32Ty(getGlobalContext()),
                                            false, GlobalValue::ExternalLinkage);
   // This should not be garbage monitored.
   LeakDetector::removeGarbageObject(Ret);
   return Ret;
 }
 GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
-  GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
+  GlobalAlias *Ret = new GlobalAlias(Type::getInt32Ty(getGlobalContext()),
                                      GlobalValue::ExternalLinkage);
   // This should not be garbage monitored.
   LeakDetector::removeGarbageObject(Ret);
@@ -67,6 +68,7 @@ Module::~Module() {
   FunctionList.clear();
   AliasList.clear();
   LibraryList.clear();
+  NamedMDList.clear();
   delete ValSymTab;
   delete TypeSymTab;
 }
@@ -152,8 +154,8 @@ Constant *Module::getOrInsertFunction(const StringRef &Name,
 
   // If the function exists but has the wrong type, return a bitcast to the
   // right type.
-  if (F->getType() != Context.getPointerTypeUnqual(Ty))
-    return Context.getConstantExprBitCast(F, Context.getPointerTypeUnqual(Ty));
+  if (F->getType() != PointerType::getUnqual(Ty))
+    return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
   
   // Otherwise, we just found the existing function or a prototype.
   return F;  
@@ -202,7 +204,7 @@ Constant *Module::getOrInsertFunction(const StringRef &Name,
 
   // Build the function type and chain to the other getOrInsertFunction...
   return getOrInsertFunction(Name,
-                             Context.getFunctionType(RetTy, ArgTys, false),
+                             FunctionType::get(RetTy, ArgTys, false),
                              AttributeList);
 }
 
@@ -220,7 +222,7 @@ Constant *Module::getOrInsertFunction(const StringRef &Name,
 
   // Build the function type and chain to the other getOrInsertFunction...
   return getOrInsertFunction(Name, 
-                             Context.getFunctionType(RetTy, ArgTys, false),
+                             FunctionType::get(RetTy, ArgTys, false),
                              AttrListPtr::get((AttributeWithIndex *)0, 0));
 }
 
@@ -270,8 +272,8 @@ Constant *Module::getOrInsertGlobal(const StringRef &Name, const Type *Ty) {
 
   // If the variable exists but has the wrong type, return a bitcast to the
   // right type.
-  if (GV->getType() != Context.getPointerTypeUnqual(Ty))
-    return Context.getConstantExprBitCast(GV, Context.getPointerTypeUnqual(Ty));
+  if (GV->getType() != PointerType::getUnqual(Ty))
+    return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
   
   // Otherwise, we just found the existing function or a prototype.
   return GV;
@@ -288,6 +290,24 @@ GlobalAlias *Module::getNamedAlias(const StringRef &Name) const {
   return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
 }
 
+/// getNamedMetadata - Return the first NamedMDNode in the module with the
+/// specified name. This method returns null if a NamedMDNode with the 
+//// specified name is not found.
+NamedMDNode *Module::getNamedMetadata(const StringRef &Name) const {
+  return dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name));
+}
+
+/// getOrInsertNamedMetadata - Return the first named MDNode in the module 
+/// with the specified name. This method returns a new NamedMDNode if a 
+/// NamedMDNode with the specified name is not found.
+NamedMDNode *Module::getOrInsertNamedMetadata(const StringRef &Name) {
+  NamedMDNode *NMD =
+    dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name));
+  if (!NMD)
+    NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this);
+  return NMD;
+}
+
 //===----------------------------------------------------------------------===//
 // Methods for easy access to the types in the module.
 //