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