Move FunctionArgument out of iOther.h into Argument.h and rename class to
[oota-llvm.git] / include / llvm / Function.h
1 //===-- llvm/Function.h - Class to represent a single VM function -*- C++ -*-=//
2 //
3 // This file contains the declaration of the Function class, which represents a 
4 // single function/procedure in the VM.
5 //
6 // Note that basic blocks in the method are value's, because they are referenced
7 // by instructions like calls and can go into virtual function tables and stuff.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LLVM_FUNCTION_H
12 #define LLVM_FUNCTION_H
13
14 #include "llvm/SymTabValue.h"
15 #include "llvm/GlobalValue.h"
16 #include "llvm/ValueHolder.h"
17
18 class FunctionType;
19
20 class Function : public GlobalValue, public SymTabValue {
21 public:
22   typedef ValueHolder<Argument  , Function, Function> ArgumentListType;
23   typedef ValueHolder<BasicBlock, Function, Function> BasicBlocksType;
24
25   // BasicBlock iterators...
26   typedef BasicBlocksType::iterator iterator;
27   typedef BasicBlocksType::const_iterator const_iterator;
28   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
29   typedef std::reverse_iterator<iterator>             reverse_iterator;
30
31 private:
32
33   // Important things that make up a method!
34   BasicBlocksType  BasicBlocks;         // The basic blocks
35   ArgumentListType ArgumentList;        // The formal arguments
36   
37   friend class ValueHolder<Function, Module, Module>;
38   void setParent(Module *parent);
39
40 public:
41   Function(const FunctionType *Ty, bool isInternal, const std::string &N = "");
42   ~Function();
43
44   // Specialize setName to handle symbol table majik...
45   virtual void setName(const std::string &name, SymbolTable *ST = 0);
46
47   const Type *getReturnType() const;           // Return the type of the ret val
48   const FunctionType *getFunctionType() const; // Return the FunctionType for me
49
50   // Is the body of this method unknown? (the basic block list is empty if so)
51   // this is true for external methods, defined as forward "declare"ations
52   bool isExternal() const { return BasicBlocks.empty(); }
53
54   // Get the underlying elements of the Function... both the argument list and
55   // basic block list are empty for external methods.
56   //
57   inline const ArgumentListType &getArgumentList() const{ return ArgumentList; }
58   inline       ArgumentListType &getArgumentList()      { return ArgumentList; }
59
60   inline const BasicBlocksType  &getBasicBlocks() const { return BasicBlocks; }
61   inline       BasicBlocksType  &getBasicBlocks()       { return BasicBlocks; }
62
63   inline const BasicBlock       *getEntryNode() const   { return front(); }
64   inline       BasicBlock       *getEntryNode()         { return front(); }
65   
66   //===--------------------------------------------------------------------===//
67   // BasicBlock iterator forwarding functions
68   //
69   inline iterator                begin()       { return BasicBlocks.begin(); }
70   inline const_iterator          begin() const { return BasicBlocks.begin(); }
71   inline iterator                end  ()       { return BasicBlocks.end();   }
72   inline const_iterator          end  () const { return BasicBlocks.end();   }
73
74   inline reverse_iterator       rbegin()       { return BasicBlocks.rbegin(); }
75   inline const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
76   inline reverse_iterator       rend  ()       { return BasicBlocks.rend();   }
77   inline const_reverse_iterator rend  () const { return BasicBlocks.rend();   }
78
79   inline unsigned                 size() const { return BasicBlocks.size(); }
80   inline bool                    empty() const { return BasicBlocks.empty(); }
81   inline const BasicBlock       *front() const { return BasicBlocks.front(); }
82   inline       BasicBlock       *front()       { return BasicBlocks.front(); }
83   inline const BasicBlock        *back() const { return BasicBlocks.back(); }
84   inline       BasicBlock        *back()       { return BasicBlocks.back(); }
85
86   virtual void print(std::ostream &OS) const;
87
88   // Methods for support type inquiry through isa, cast, and dyn_cast:
89   static inline bool classof(const Function *) { return true; }
90   static inline bool classof(const Value *V) {
91     return V->getValueType() == Value::FunctionVal;
92   }
93
94   // dropAllReferences() - This function causes all the subinstructions to "let
95   // go" of all references that they are maintaining.  This allows one to
96   // 'delete' a whole class at a time, even though there may be circular
97   // references... first all references are dropped, and all use counts go to
98   // zero.  Then everything is delete'd for real.  Note that no operations are
99   // valid on an object that has "dropped all references", except operator 
100   // delete.
101   //
102   void dropAllReferences();
103 };
104
105 #endif