-//===-- llvm/Function.h - Class to represent a single VM function -*- C++ -*-=//
+//===-- llvm/Function.h - Class to represent a single function --*- C++ -*-===//
//
// This file contains the declaration of the Function class, which represents a
-// single function/procedure in the VM.
+// single function/procedure in LLVM.
//
-// Note that BasicBlock's in the Function are Value's, because they are
-// referenced by instructions like calls and can go into virtual function tables
-// and stuff.
+// A function basically consists of a list of basic blocks, a list of arguments,
+// and a symbol table.
//
//===----------------------------------------------------------------------===//
: public SymbolTableListTraits<BasicBlock, Function, Function> {
// createNode is used to create a node that marks the end of the list...
- static BasicBlock *createNode() { return new BasicBlock(); }
+ static BasicBlock *createNode();
static iplist<BasicBlock> &getList(Function *F);
};
private:
// Important things that make up a function!
- BasicBlockListType BasicBlocks; // The basic blocks
+ BasicBlockListType BasicBlocks; // The basic blocks
ArgumentListType ArgumentList; // The formal arguments
SymbolTable *SymTab, *ParentSymTab;
void setPrev(Function *N) { Prev = N; }
public:
- Function(const FunctionType *Ty, bool isInternal, const std::string &N = "");
+ /// Function ctor - If the (optional) Module argument is specified, the
+ /// function is automatically inserted into the end of the function list for
+ /// the module.
+ ///
+ Function(const FunctionType *Ty, bool isInternal, const std::string &N = "",
+ Module *M = 0);
~Function();
// Specialize setName to handle symbol table majik...
const Type *getReturnType() const; // Return the type of the ret val
const FunctionType *getFunctionType() const; // Return the FunctionType for me
- // Is the body of this function unknown? (the basic block list is empty if so)
- // this is true for external functions, defined as forward "declare"ations
+ /// isExternal - Is the body of this function unknown? (the basic block list
+ /// is empty if so) this is true for external functions, defined as forward
+ /// "declare"ations
+ ///
bool isExternal() const { return BasicBlocks.empty(); }
- // getNext/Prev - Return the next or previous instruction in the list. The
- // last node in the list is a terminator instruction.
+ // getNext/Prev - Return the next or previous function in the list. These
+ // methods should never be used directly, and are only used to implement the
+ // function list as part of the module.
+ //
Function *getNext() { return Next; }
const Function *getNext() const { return Next; }
Function *getPrev() { return Prev; }
const Function *getPrev() const { return Prev; }
- // Get the underlying elements of the Function... both the argument list and
- // basic block list are empty for external functions.
- //
+ /// Get the underlying elements of the Function... both the argument list and
+ /// basic block list are empty for external functions.
+ ///
const ArgumentListType &getArgumentList() const { return ArgumentList; }
ArgumentListType &getArgumentList() { return ArgumentList; }
//===--------------------------------------------------------------------===//
// Symbol Table Accessing functions...
- // hasSymbolTable() - Returns true if there is a symbol table allocated to
- // this object AND if there is at least one name in it!
- //
+ /// hasSymbolTable() - Returns true if there is a symbol table allocated to
+ /// this object AND if there is at least one name in it!
+ ///
bool hasSymbolTable() const;
- // CAUTION: The current symbol table may be null if there are no names (ie,
- // the symbol table is empty)
- //
+ /// getSymbolTable() - CAUTION: The current symbol table may be null if there
+ /// are no names (ie, the symbol table is empty)
+ ///
inline SymbolTable *getSymbolTable() { return SymTab; }
inline const SymbolTable *getSymbolTable() const { return SymTab; }
- // getSymbolTableSure is guaranteed to not return a null pointer, because if
- // the function does not already have a symtab, one is created. Use this if
- // you intend to put something into the symbol table for the function.
- //
+ /// getSymbolTableSure is guaranteed to not return a null pointer, because if
+ /// the function does not already have a symtab, one is created. Use this if
+ /// you intend to put something into the symbol table for the function.
+ ///
SymbolTable *getSymbolTableSure(); // Implemented in Value.cpp
reverse_aiterator arend () { return ArgumentList.rend(); }
const_reverse_aiterator arend () const { return ArgumentList.rend(); }
- unsigned asize() const { return ArgumentList.size(); }
- bool aempty() const { return ArgumentList.empty(); }
- const Argument &afront() const { return ArgumentList.front(); }
- Argument &afront() { return ArgumentList.front(); }
- const Argument &aback() const { return ArgumentList.back(); }
- Argument &aback() { return ArgumentList.back(); }
+ unsigned asize() const { return ArgumentList.size(); }
+ bool aempty() const { return ArgumentList.empty(); }
+ const Argument &afront() const { return ArgumentList.front(); }
+ Argument &afront() { return ArgumentList.front(); }
+ const Argument &aback() const { return ArgumentList.back(); }
+ Argument &aback() { return ArgumentList.back(); }
virtual void print(std::ostream &OS) const;
- // Methods for support type inquiry through isa, cast, and dyn_cast:
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Function *) { return true; }
static inline bool classof(const Value *V) {
return V->getValueType() == Value::FunctionVal;
}
- // dropAllReferences() - This function causes all the subinstructions to "let
- // go" of all references that they are maintaining. This allows one to
- // 'delete' a whole class at a time, even though there may be circular
- // references... first all references are dropped, and all use counts go to
- // zero. Then everything is delete'd for real. Note that no operations are
- // valid on an object that has "dropped all references", except operator
- // delete.
- //
+ /// dropAllReferences() - This function causes all the subinstructions to "let
+ /// go" of all references that they are maintaining. This allows one to
+ /// 'delete' a whole class at a time, even though there may be circular
+ /// references... first all references are dropped, and all use counts go to
+ /// zero. Then everything is delete'd for real. Note that no operations are
+ /// valid on an object that has "dropped all references", except operator
+ /// delete.
+ ///
void dropAllReferences();
};