1 //===-- llvm/Module.h - C++ class to represent a VM module -------*- C++ -*--=//
3 // This file contains the declarations for the Module class that is used to
4 // maintain all the information related to a VM module.
6 //===----------------------------------------------------------------------===//
11 #include "llvm/Value.h"
12 #include "llvm/SymTabValue.h"
13 #include "llvm/ValueHolder.h"
17 class Module : public Value, public SymTabValue {
19 typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType;
20 typedef ValueHolder<Method, Module, Module> MethodListType;
22 // Global Variable iterators...
23 typedef GlobalListType::iterator giterator;
24 typedef GlobalListType::const_iterator const_giterator;
25 typedef reverse_iterator<giterator> reverse_giterator;
26 typedef reverse_iterator<const_giterator> const_reverse_giterator;
28 // Method iterators...
29 typedef MethodListType::iterator iterator;
30 typedef MethodListType::const_iterator const_iterator;
31 typedef reverse_iterator<const_iterator> const_reverse_iterator;
32 typedef reverse_iterator<iterator> reverse_iterator;
35 GlobalListType GlobalList; // The Global Variables
36 MethodListType MethodList; // The Methods
42 // reduceApply - Apply the specified function to all of the methods in this
43 // module. The result values are or'd together and the result is returned.
45 bool reduceApply(bool (*Func)(GlobalVariable*));
46 bool reduceApply(bool (*Func)(const GlobalVariable*)) const;
47 bool reduceApply(bool (*Func)(Method*));
48 bool reduceApply(bool (*Func)(const Method*)) const;
51 // Get the underlying elements of the Module...
52 inline const GlobalListType &getGlobalList() const { return GlobalList; }
53 inline GlobalListType &getGlobalList() { return GlobalList; }
54 inline const MethodListType &getMethodList() const { return MethodList; }
55 inline MethodListType &getMethodList() { return MethodList; }
57 //===--------------------------------------------------------------------===//
58 // Module iterator forwarding functions
60 inline giterator gbegin() { return GlobalList.begin(); }
61 inline const_giterator gbegin() const { return GlobalList.begin(); }
62 inline giterator gend () { return GlobalList.end(); }
63 inline const_giterator gend () const { return GlobalList.end(); }
65 inline reverse_giterator grbegin() { return GlobalList.rbegin(); }
66 inline const_reverse_giterator grbegin() const { return GlobalList.rbegin(); }
67 inline reverse_giterator grend () { return GlobalList.rend(); }
68 inline const_reverse_giterator grend () const { return GlobalList.rend(); }
70 inline unsigned gsize() const { return GlobalList.size(); }
71 inline bool gempty() const { return GlobalList.empty(); }
72 inline const GlobalVariable *gfront() const { return GlobalList.front(); }
73 inline GlobalVariable *gfront() { return GlobalList.front(); }
74 inline const GlobalVariable *gback() const { return GlobalList.back(); }
75 inline GlobalVariable *gback() { return GlobalList.back(); }
79 inline iterator begin() { return MethodList.begin(); }
80 inline const_iterator begin() const { return MethodList.begin(); }
81 inline iterator end () { return MethodList.end(); }
82 inline const_iterator end () const { return MethodList.end(); }
84 inline reverse_iterator rbegin() { return MethodList.rbegin(); }
85 inline const_reverse_iterator rbegin() const { return MethodList.rbegin(); }
86 inline reverse_iterator rend () { return MethodList.rend(); }
87 inline const_reverse_iterator rend () const { return MethodList.rend(); }
89 inline unsigned size() const { return MethodList.size(); }
90 inline bool empty() const { return MethodList.empty(); }
91 inline const Method *front() const { return MethodList.front(); }
92 inline Method *front() { return MethodList.front(); }
93 inline const Method *back() const { return MethodList.back(); }
94 inline Method *back() { return MethodList.back(); }
97 // dropAllReferences() - This function causes all the subinstructions to "let
98 // go" of all references that they are maintaining. This allows one to
99 // 'delete' a whole class at a time, even though there may be circular
100 // references... first all references are dropped, and all use counts go to
101 // zero. Then everything is delete'd for real. Note that no operations are
102 // valid on an object that has "dropped all references", except operator
105 void dropAllReferences();