Initial revision
[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/ValueHolderImpl.h"
8 #include "llvm/InstrTypes.h"
9 #include "llvm/BasicBlock.h"
10 #include "llvm/Method.h"
11 #include "llvm/Module.h"
12
13 // Instantiate Templates - This ugliness is the price we have to pay
14 // for having a DefHolderImpl.h file seperate from DefHolder.h!  :(
15 //
16 template class ValueHolder<Method, Module>;
17
18 Module::Module()
19   : SymTabValue(0/*TODO: REAL TYPE*/, Value::ModuleVal, ""),
20     MethodList(this, this) {
21 }
22
23 Module::~Module() {
24   dropAllReferences();
25   MethodList.delete_all();
26   MethodList.setParent(0);
27 }
28
29
30 // dropAllReferences() - This function causes all the subinstructions to "let
31 // go" of all references that they are maintaining.  This allows one to
32 // 'delete' a whole class at a time, even though there may be circular
33 // references... first all references are dropped, and all use counts go to
34 // zero.  Then everything is delete'd for real.  Note that no operations are
35 // valid on an object that has "dropped all references", except operator 
36 // delete.
37 //
38 void Module::dropAllReferences() {
39   MethodListType::iterator MI = MethodList.begin();
40   for (; MI != MethodList.end(); MI++)
41     (*MI)->dropAllReferences();
42 }