4ab8bb06fc6281c31999e34818c71a4b6dc7f915
[oota-llvm.git] / lib / VMCore / Module.cpp
1 //===-- Module.cpp - Implement the Module class ------------------*- C++ -*--=//
2 //
3 // This file implements the Module class for the VMCore library.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/Module.h"
8 #include "llvm/Method.h"
9 #include "llvm/BasicBlock.h"
10 #include "llvm/InstrTypes.h"
11 #include "llvm/ValueHolderImpl.h"
12 #include "llvm/Support/STLExtras.h"
13 #include "llvm/Type.h"
14
15 // Instantiate Templates - This ugliness is the price we have to pay
16 // for having a DefHolderImpl.h file seperate from DefHolder.h!  :(
17 //
18 template class ValueHolder<Method, Module, Module>;
19
20 Module::Module()
21   : Value(Type::VoidTy, Value::ModuleVal, ""), SymTabValue(this),
22     MethodList(this, this) {
23 }
24
25 Module::~Module() {
26   dropAllReferences();
27   MethodList.delete_all();
28   MethodList.setParent(0);
29 }
30
31
32 // dropAllReferences() - This function causes all the subinstructions to "let
33 // go" of all references that they are maintaining.  This allows one to
34 // 'delete' a whole class at a time, even though there may be circular
35 // references... first all references are dropped, and all use counts go to
36 // zero.  Then everything is delete'd for real.  Note that no operations are
37 // valid on an object that has "dropped all references", except operator 
38 // delete.
39 //
40 void Module::dropAllReferences() {
41   MethodListType::iterator MI = MethodList.begin();
42   for (; MI != MethodList.end(); ++MI)
43     (*MI)->dropAllReferences();
44 }
45
46 // reduceApply - Apply the specified function to all of the methods in this 
47 // module.  The result values are or'd together and the result is returned.
48 //
49 bool Module::reduceApply(bool (*Func)(Method*)) {
50   return reduce_apply_bool(begin(), end(), Func);
51 }
52 bool Module::reduceApply(bool (*Func)(const Method*)) const {
53   return reduce_apply_bool(begin(), end(), Func);
54 }
55