blob: 873984896165b74679a9a6106a02b7edd6b78823 [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===-- Module.cpp - Implement the Module class ---------------------------===//
Misha Brukmanb1c93172005-04-21 23:48:37 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb1c93172005-04-21 23:48:37 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +00009//
10// This file implements the Module class for the VMCore library.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner2f7c9632001-06-06 20:29:01 +000014#include "llvm/Module.h"
Chris Lattner31cf9842001-06-30 04:35:40 +000015#include "llvm/InstrTypes.h"
Chris Lattnerca142372002-04-28 19:55:58 +000016#include "llvm/Constants.h"
Chris Lattnera483b062002-03-29 03:44:18 +000017#include "llvm/DerivedTypes.h"
Owen Anderson6773d382009-07-01 16:58:40 +000018#include "llvm/LLVMContext.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000019#include "llvm/ADT/STLExtras.h"
Owen Anderson9eb1a262006-05-18 02:10:31 +000020#include "llvm/ADT/StringExtras.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000021#include "llvm/Support/LeakDetector.h"
Chris Lattner113f4f42002-06-25 16:13:24 +000022#include "SymbolTableListTraitsImpl.h"
Reid Spencer32af9e82007-01-06 07:24:44 +000023#include "llvm/TypeSymbolTable.h"
Chris Lattner113f4f42002-06-25 16:13:24 +000024#include <algorithm>
Chris Lattnerbd717d82003-08-31 00:19:28 +000025#include <cstdarg>
Owen Anderson9eb1a262006-05-18 02:10:31 +000026#include <cstdlib>
Chris Lattner189d19f2003-11-21 20:23:48 +000027using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000028
Chris Lattner09bd1a02003-12-31 08:43:01 +000029//===----------------------------------------------------------------------===//
Misha Brukman3bcead72004-04-21 18:27:56 +000030// Methods to implement the globals and functions lists.
Chris Lattner09bd1a02003-12-31 08:43:01 +000031//
32
Chris Lattnerf6c93e32005-01-30 00:09:23 +000033GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
Owen Andersonb17f3292009-07-08 19:03:57 +000034 GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), Type::Int32Ty,
35 false, GlobalValue::ExternalLinkage);
Chris Lattner184b2982002-09-08 18:59:35 +000036 // This should not be garbage monitored.
37 LeakDetector::removeGarbageObject(Ret);
38 return Ret;
Chris Lattner113f4f42002-06-25 16:13:24 +000039}
Anton Korobeynikova97b6942007-04-25 14:27:10 +000040GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
Owen Andersonb17f3292009-07-08 19:03:57 +000041 GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
Dan Gohman929391a2008-01-29 12:09:55 +000042 GlobalValue::ExternalLinkage);
Anton Korobeynikova97b6942007-04-25 14:27:10 +000043 // This should not be garbage monitored.
44 LeakDetector::removeGarbageObject(Ret);
45 return Ret;
46}
Chris Lattner113f4f42002-06-25 16:13:24 +000047
Chris Lattner113f4f42002-06-25 16:13:24 +000048// Explicit instantiations of SymbolTableListTraits since some of the methods
Chris Lattnereef2fe72006-01-24 04:13:11 +000049// are not in the public header file.
Chris Lattnerb47aa542007-04-17 03:26:42 +000050template class SymbolTableListTraits<GlobalVariable, Module>;
51template class SymbolTableListTraits<Function, Module>;
Anton Korobeynikova97b6942007-04-25 14:27:10 +000052template class SymbolTableListTraits<GlobalAlias, Module>;
Chris Lattner2f7c9632001-06-06 20:29:01 +000053
Chris Lattner09bd1a02003-12-31 08:43:01 +000054//===----------------------------------------------------------------------===//
55// Primitive Module methods.
56//
Chris Lattner446ad502001-10-13 06:58:40 +000057
Owen Anderson2a154432009-07-01 23:13:44 +000058Module::Module(const std::string &MID, LLVMContext& C)
Owen Anderson6773d382009-07-01 16:58:40 +000059 : Context(C), ModuleID(MID), DataLayout("") {
Reid Spencer3aaaa0b2007-02-05 20:47:22 +000060 ValSymTab = new ValueSymbolTable();
Reid Spencer32af9e82007-01-06 07:24:44 +000061 TypeSymTab = new TypeSymbolTable();
Chris Lattner2f7c9632001-06-06 20:29:01 +000062}
63
64Module::~Module() {
65 dropAllReferences();
Chris Lattner113f4f42002-06-25 16:13:24 +000066 GlobalList.clear();
Chris Lattner113f4f42002-06-25 16:13:24 +000067 FunctionList.clear();
Anton Korobeynikova97b6942007-04-25 14:27:10 +000068 AliasList.clear();
Reid Spencera0b05b32004-07-25 18:08:57 +000069 LibraryList.clear();
Reid Spencer32af9e82007-01-06 07:24:44 +000070 delete ValSymTab;
71 delete TypeSymTab;
Chris Lattner2f7c9632001-06-06 20:29:01 +000072}
73
Owen Anderson9eb1a262006-05-18 02:10:31 +000074/// Target endian information...
75Module::Endianness Module::getEndianness() const {
76 std::string temp = DataLayout;
Owen Anderson08aecf52006-05-18 05:46:08 +000077 Module::Endianness ret = AnyEndianness;
Owen Anderson9eb1a262006-05-18 02:10:31 +000078
Owen Anderson08aecf52006-05-18 05:46:08 +000079 while (!temp.empty()) {
Owen Anderson9eb1a262006-05-18 02:10:31 +000080 std::string token = getToken(temp, "-");
81
82 if (token[0] == 'e') {
Owen Anderson08aecf52006-05-18 05:46:08 +000083 ret = LittleEndian;
Owen Anderson9eb1a262006-05-18 02:10:31 +000084 } else if (token[0] == 'E') {
Owen Anderson08aecf52006-05-18 05:46:08 +000085 ret = BigEndian;
Owen Anderson9eb1a262006-05-18 02:10:31 +000086 }
87 }
88
Owen Anderson08aecf52006-05-18 05:46:08 +000089 return ret;
Owen Anderson9eb1a262006-05-18 02:10:31 +000090}
91
Owen Anderson9eb1a262006-05-18 02:10:31 +000092/// Target Pointer Size information...
93Module::PointerSize Module::getPointerSize() const {
94 std::string temp = DataLayout;
Owen Anderson08aecf52006-05-18 05:46:08 +000095 Module::PointerSize ret = AnyPointerSize;
Owen Anderson9eb1a262006-05-18 02:10:31 +000096
Owen Anderson08aecf52006-05-18 05:46:08 +000097 while (!temp.empty()) {
Owen Anderson9eb1a262006-05-18 02:10:31 +000098 std::string token = getToken(temp, "-");
99 char signal = getToken(token, ":")[0];
100
101 if (signal == 'p') {
102 int size = atoi(getToken(token, ":").c_str());
103 if (size == 32)
Owen Anderson08aecf52006-05-18 05:46:08 +0000104 ret = Pointer32;
Owen Anderson9eb1a262006-05-18 02:10:31 +0000105 else if (size == 64)
Owen Anderson08aecf52006-05-18 05:46:08 +0000106 ret = Pointer64;
Owen Anderson9eb1a262006-05-18 02:10:31 +0000107 }
108 }
109
Owen Anderson08aecf52006-05-18 05:46:08 +0000110 return ret;
Owen Anderson9eb1a262006-05-18 02:10:31 +0000111}
112
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000113/// getNamedValue - Return the first global value in the module with
114/// the specified name, of arbitrary type. This method returns null
115/// if a global with the specified name is not found.
116GlobalValue *Module::getNamedValue(const std::string &Name) const {
117 return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
118}
119
120GlobalValue *Module::getNamedValue(const char *Name) const {
121 llvm::Value *V = getValueSymbolTable().lookup(Name, Name+strlen(Name));
122 return cast_or_null<GlobalValue>(V);
123}
124
Chris Lattner09bd1a02003-12-31 08:43:01 +0000125//===----------------------------------------------------------------------===//
126// Methods for easy access to the functions in the module.
127//
128
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000129// getOrInsertFunction - Look up the specified function in the module symbol
130// table. If it does not exist, add a prototype for the function and return
131// it. This is nice because it allows most passes to get away with not handling
132// the symbol table directly for this common task.
133//
Chris Lattner505c06b2007-01-07 08:09:25 +0000134Constant *Module::getOrInsertFunction(const std::string &Name,
Nick Lewycky3a0c1062009-01-04 22:54:40 +0000135 const FunctionType *Ty,
136 AttrListPtr AttributeList) {
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000137 // See if we have a definition for the specified function already.
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000138 GlobalValue *F = getNamedValue(Name);
Chris Lattner505c06b2007-01-07 08:09:25 +0000139 if (F == 0) {
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000140 // Nope, add it
Gabor Greife9ecc682008-04-06 20:25:17 +0000141 Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
Nick Lewycky3a0c1062009-01-04 22:54:40 +0000142 if (!New->isIntrinsic()) // Intrinsics get attrs set on construction
143 New->setAttributes(AttributeList);
Chris Lattnera483b062002-03-29 03:44:18 +0000144 FunctionList.push_back(New);
Chris Lattner505c06b2007-01-07 08:09:25 +0000145 return New; // Return the new prototype.
Chris Lattnera483b062002-03-29 03:44:18 +0000146 }
Chris Lattner505c06b2007-01-07 08:09:25 +0000147
148 // Okay, the function exists. Does it have externally visible linkage?
Rafael Espindola6de96a12009-01-15 20:18:42 +0000149 if (F->hasLocalLinkage()) {
Chris Lattner42e983e2008-06-27 21:25:24 +0000150 // Clear the function's name.
151 F->setName("");
Chris Lattner505c06b2007-01-07 08:09:25 +0000152 // Retry, now there won't be a conflict.
Chris Lattner42e983e2008-06-27 21:25:24 +0000153 Constant *NewF = getOrInsertFunction(Name, Ty);
154 F->setName(&Name[0], Name.size());
155 return NewF;
Chris Lattner505c06b2007-01-07 08:09:25 +0000156 }
157
158 // If the function exists but has the wrong type, return a bitcast to the
159 // right type.
Christopher Lambedf07882007-12-17 01:12:55 +0000160 if (F->getType() != PointerType::getUnqual(Ty))
161 return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
Chris Lattner505c06b2007-01-07 08:09:25 +0000162
163 // Otherwise, we just found the existing function or a prototype.
164 return F;
Chris Lattnera483b062002-03-29 03:44:18 +0000165}
166
Dale Johannesenb842d522009-02-05 01:49:45 +0000167Constant *Module::getOrInsertTargetIntrinsic(const std::string &Name,
168 const FunctionType *Ty,
169 AttrListPtr AttributeList) {
Dale Johannesenb842d522009-02-05 01:49:45 +0000170 // See if we have a definition for the specified function already.
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000171 GlobalValue *F = getNamedValue(Name);
Dale Johannesenb842d522009-02-05 01:49:45 +0000172 if (F == 0) {
173 // Nope, add it
174 Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
175 New->setAttributes(AttributeList);
176 FunctionList.push_back(New);
177 return New; // Return the new prototype.
178 }
179
180 // Otherwise, we just found the existing function or a prototype.
181 return F;
182}
183
Nick Lewycky3a0c1062009-01-04 22:54:40 +0000184Constant *Module::getOrInsertFunction(const std::string &Name,
185 const FunctionType *Ty) {
186 AttrListPtr AttributeList = AttrListPtr::get((AttributeWithIndex *)0, 0);
187 return getOrInsertFunction(Name, Ty, AttributeList);
188}
189
Chris Lattnerbd717d82003-08-31 00:19:28 +0000190// getOrInsertFunction - Look up the specified function in the module symbol
191// table. If it does not exist, add a prototype for the function and return it.
192// This version of the method takes a null terminated list of function
193// arguments, which makes it easier for clients to use.
194//
Chris Lattner505c06b2007-01-07 08:09:25 +0000195Constant *Module::getOrInsertFunction(const std::string &Name,
Nick Lewycky3a0c1062009-01-04 22:54:40 +0000196 AttrListPtr AttributeList,
197 const Type *RetTy, ...) {
198 va_list Args;
199 va_start(Args, RetTy);
200
201 // Build the list of argument types...
202 std::vector<const Type*> ArgTys;
203 while (const Type *ArgTy = va_arg(Args, const Type*))
204 ArgTys.push_back(ArgTy);
205
206 va_end(Args);
207
208 // Build the function type and chain to the other getOrInsertFunction...
209 return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false),
210 AttributeList);
211}
212
213Constant *Module::getOrInsertFunction(const std::string &Name,
Chris Lattnerbd717d82003-08-31 00:19:28 +0000214 const Type *RetTy, ...) {
215 va_list Args;
216 va_start(Args, RetTy);
217
218 // Build the list of argument types...
219 std::vector<const Type*> ArgTys;
220 while (const Type *ArgTy = va_arg(Args, const Type*))
221 ArgTys.push_back(ArgTy);
222
223 va_end(Args);
224
225 // Build the function type and chain to the other getOrInsertFunction...
Nick Lewycky3a0c1062009-01-04 22:54:40 +0000226 return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false),
227 AttrListPtr::get((AttributeWithIndex *)0, 0));
Chris Lattnerbd717d82003-08-31 00:19:28 +0000228}
229
Chris Lattnera483b062002-03-29 03:44:18 +0000230// getFunction - Look up the specified function in the module symbol table.
231// If it does not exist, return null.
232//
Reid Spencer3aaaa0b2007-02-05 20:47:22 +0000233Function *Module::getFunction(const std::string &Name) const {
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000234 return dyn_cast_or_null<Function>(getNamedValue(Name));
Chris Lattner1f985e02002-11-08 20:34:02 +0000235}
236
Chris Lattnere43649f2008-06-27 21:09:10 +0000237Function *Module::getFunction(const char *Name) const {
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000238 return dyn_cast_or_null<Function>(getNamedValue(Name));
Chris Lattnere43649f2008-06-27 21:09:10 +0000239}
240
Chris Lattner09bd1a02003-12-31 08:43:01 +0000241//===----------------------------------------------------------------------===//
242// Methods for easy access to the global variables in the module.
243//
244
245/// getGlobalVariable - Look up the specified global variable in the module
Chris Lattner7d4d93c2005-12-05 05:30:21 +0000246/// symbol table. If it does not exist, return null. The type argument
247/// should be the underlying type of the global, i.e., it should not have
248/// the top-level PointerType, which represents the address of the global.
Rafael Espindola6de96a12009-01-15 20:18:42 +0000249/// If AllowLocal is set to true, this function will return types that
250/// have an local. By default, these types are not returned.
Chris Lattner09bd1a02003-12-31 08:43:01 +0000251///
Misha Brukmanb1c93172005-04-21 23:48:37 +0000252GlobalVariable *Module::getGlobalVariable(const std::string &Name,
Rafael Espindola6de96a12009-01-15 20:18:42 +0000253 bool AllowLocal) const {
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000254 if (GlobalVariable *Result =
255 dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
256 if (AllowLocal || !Result->hasLocalLinkage())
Chris Lattner09bd1a02003-12-31 08:43:01 +0000257 return Result;
Chris Lattner09bd1a02003-12-31 08:43:01 +0000258 return 0;
259}
260
Bill Wendlingf5f6f742008-11-05 23:42:27 +0000261/// getOrInsertGlobal - Look up the specified global in the module symbol table.
262/// 1. If it does not exist, add a declaration of the global and return it.
263/// 2. Else, the global exists but has the wrong type: return the function
264/// with a constantexpr cast to the right type.
265/// 3. Finally, if the existing global is the correct delclaration, return the
266/// existing global.
Bill Wendling2f409562008-11-04 22:51:24 +0000267Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
Bill Wendling2f409562008-11-04 22:51:24 +0000268 // See if we have a definition for the specified global already.
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000269 GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
Bill Wendling2f409562008-11-04 22:51:24 +0000270 if (GV == 0) {
271 // Nope, add it
272 GlobalVariable *New =
Owen Andersonb17f3292009-07-08 19:03:57 +0000273 new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
274 0, Name);
275 return New; // Return the new declaration.
Bill Wendling2f409562008-11-04 22:51:24 +0000276 }
277
278 // If the variable exists but has the wrong type, return a bitcast to the
279 // right type.
280 if (GV->getType() != PointerType::getUnqual(Ty))
281 return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
282
283 // Otherwise, we just found the existing function or a prototype.
284 return GV;
285}
286
Chris Lattner09bd1a02003-12-31 08:43:01 +0000287//===----------------------------------------------------------------------===//
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000288// Methods for easy access to the global variables in the module.
289//
290
291// getNamedAlias - Look up the specified global in the module symbol table.
292// If it does not exist, return null.
293//
294GlobalAlias *Module::getNamedAlias(const std::string &Name) const {
Daniel Dunbardcf8d3c2009-03-06 22:04:43 +0000295 return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000296}
297
298//===----------------------------------------------------------------------===//
Chris Lattner09bd1a02003-12-31 08:43:01 +0000299// Methods for easy access to the types in the module.
300//
301
Chris Lattner1f985e02002-11-08 20:34:02 +0000302
Chris Lattnerbe3596c2003-12-31 07:09:33 +0000303// addTypeName - Insert an entry in the symbol table mapping Str to Type. If
304// there is already an entry for this name, true is returned and the symbol
305// table is not modified.
306//
307bool Module::addTypeName(const std::string &Name, const Type *Ty) {
Reid Spencer32af9e82007-01-06 07:24:44 +0000308 TypeSymbolTable &ST = getTypeSymbolTable();
Chris Lattnerbe3596c2003-12-31 07:09:33 +0000309
Reid Spencer32af9e82007-01-06 07:24:44 +0000310 if (ST.lookup(Name)) return true; // Already in symtab...
Misha Brukmanb1c93172005-04-21 23:48:37 +0000311
Chris Lattnerbe3596c2003-12-31 07:09:33 +0000312 // Not in symbol table? Set the name with the Symtab as an argument so the
313 // type knows what to update...
Reid Spencerf9776c32004-07-10 16:37:42 +0000314 ST.insert(Name, Ty);
Chris Lattnerbe3596c2003-12-31 07:09:33 +0000315
316 return false;
317}
318
319/// getTypeByName - Return the type with the specified name in this module, or
320/// null if there is none by that name.
321const Type *Module::getTypeByName(const std::string &Name) const {
Reid Spencer32af9e82007-01-06 07:24:44 +0000322 const TypeSymbolTable &ST = getTypeSymbolTable();
323 return cast_or_null<Type>(ST.lookup(Name));
Chris Lattnerbe3596c2003-12-31 07:09:33 +0000324}
Chris Lattner1f985e02002-11-08 20:34:02 +0000325
Chris Lattner10b7cb52002-04-13 18:58:33 +0000326// getTypeName - If there is at least one entry in the symbol table for the
327// specified type, return it.
328//
Chris Lattnerbe3596c2003-12-31 07:09:33 +0000329std::string Module::getTypeName(const Type *Ty) const {
Reid Spencer32af9e82007-01-06 07:24:44 +0000330 const TypeSymbolTable &ST = getTypeSymbolTable();
Chris Lattner10b7cb52002-04-13 18:58:33 +0000331
Reid Spencer32af9e82007-01-06 07:24:44 +0000332 TypeSymbolTable::const_iterator TI = ST.begin();
333 TypeSymbolTable::const_iterator TE = ST.end();
Reid Spencerabb6f002004-05-25 08:52:20 +0000334 if ( TI == TE ) return ""; // No names for types
Chris Lattner10b7cb52002-04-13 18:58:33 +0000335
Reid Spencerabb6f002004-05-25 08:52:20 +0000336 while (TI != TE && TI->second != Ty)
Chris Lattner10b7cb52002-04-13 18:58:33 +0000337 ++TI;
338
339 if (TI != TE) // Must have found an entry!
340 return TI->first;
341 return ""; // Must not have found anything...
342}
343
Chris Lattner09bd1a02003-12-31 08:43:01 +0000344//===----------------------------------------------------------------------===//
345// Other module related stuff.
346//
347
348
Chris Lattnere0f6af9b2002-08-17 23:32:47 +0000349// dropAllReferences() - This function causes all the subelementss to "let go"
350// of all references that they are maintaining. This allows one to 'delete' a
351// whole module at a time, even though there may be circular references... first
352// all references are dropped, and all use counts go to zero. Then everything
Misha Brukmanfa100532003-10-10 17:54:14 +0000353// is deleted for real. Note that no operations are valid on an object that
Chris Lattnere0f6af9b2002-08-17 23:32:47 +0000354// has "dropped all references", except operator delete.
Chris Lattner2f7c9632001-06-06 20:29:01 +0000355//
356void Module::dropAllReferences() {
Chris Lattner113f4f42002-06-25 16:13:24 +0000357 for(Module::iterator I = begin(), E = end(); I != E; ++I)
358 I->dropAllReferences();
Chris Lattner446ad502001-10-13 06:58:40 +0000359
Chris Lattner531f9e92005-03-15 04:54:21 +0000360 for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I)
Chris Lattner113f4f42002-06-25 16:13:24 +0000361 I->dropAllReferences();
Anton Korobeynikovb18f8f82007-04-28 13:45:00 +0000362
363 for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I)
364 I->dropAllReferences();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000365}
Chris Lattner31cf9842001-06-30 04:35:40 +0000366
Reid Spencer3f4e6e82007-02-04 00:40:42 +0000367void Module::addLibrary(const std::string& Lib) {
368 for (Module::lib_iterator I = lib_begin(), E = lib_end(); I != E; ++I)
369 if (*I == Lib)
370 return;
371 LibraryList.push_back(Lib);
372}
373
374void Module::removeLibrary(const std::string& Lib) {
375 LibraryListType::iterator I = LibraryList.begin();
376 LibraryListType::iterator E = LibraryList.end();
377 for (;I != E; ++I)
378 if (*I == Lib) {
379 LibraryList.erase(I);
380 return;
381 }
382}