2002-03-23 22:47:28 +00:00
|
|
|
//===-- llvm/Function.h - Class to represent a single VM function -*- C++ -*-=//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2002-03-23 22:47:28 +00:00
|
|
|
// This file contains the declaration of the Function class, which represents a
|
|
|
|
// single function/procedure in the VM.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2002-04-28 04:44:40 +00:00
|
|
|
// 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.
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-03-23 22:47:28 +00:00
|
|
|
#ifndef LLVM_FUNCTION_H
|
|
|
|
#define LLVM_FUNCTION_H
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-10-03 14:53:21 +00:00
|
|
|
#include "llvm/GlobalValue.h"
|
2002-02-12 21:02:38 +00:00
|
|
|
#include "llvm/ValueHolder.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-29 03:30:59 +00:00
|
|
|
class FunctionType;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-04-28 04:44:40 +00:00
|
|
|
class Function : public GlobalValue {
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2002-04-09 19:59:31 +00:00
|
|
|
typedef ValueHolder<Argument , Function, Function> ArgumentListType;
|
|
|
|
typedef ValueHolder<BasicBlock, Function, Function> BasicBlocksType;
|
2001-06-27 23:26:41 +00:00
|
|
|
|
|
|
|
// BasicBlock iterators...
|
2001-06-25 03:52:19 +00:00
|
|
|
typedef BasicBlocksType::iterator iterator;
|
2001-06-27 23:26:41 +00:00
|
|
|
typedef BasicBlocksType::const_iterator const_iterator;
|
2002-01-20 22:54:45 +00:00
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
2001-06-27 23:26:41 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
private:
|
|
|
|
|
2002-04-28 04:44:40 +00:00
|
|
|
// Important things that make up a function!
|
2001-10-22 13:58:08 +00:00
|
|
|
BasicBlocksType BasicBlocks; // The basic blocks
|
|
|
|
ArgumentListType ArgumentList; // The formal arguments
|
2002-04-28 04:44:40 +00:00
|
|
|
|
|
|
|
SymbolTable *SymTab, *ParentSymTab;
|
2001-10-22 13:58:08 +00:00
|
|
|
|
2002-03-23 22:47:28 +00:00
|
|
|
friend class ValueHolder<Function, Module, Module>;
|
2001-06-06 20:29:01 +00:00
|
|
|
void setParent(Module *parent);
|
|
|
|
|
|
|
|
public:
|
2002-03-29 03:30:59 +00:00
|
|
|
Function(const FunctionType *Ty, bool isInternal, const std::string &N = "");
|
2002-03-23 22:47:28 +00:00
|
|
|
~Function();
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
// Specialize setName to handle symbol table majik...
|
2002-01-20 22:54:45 +00:00
|
|
|
virtual void setName(const std::string &name, SymbolTable *ST = 0);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-29 03:30:59 +00:00
|
|
|
const Type *getReturnType() const; // Return the type of the ret val
|
|
|
|
const FunctionType *getFunctionType() const; // Return the FunctionType for me
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-04-28 04:44:40 +00:00
|
|
|
// 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
|
2001-07-15 06:35:24 +00:00
|
|
|
bool isExternal() const { return BasicBlocks.empty(); }
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-26 17:48:08 +00:00
|
|
|
// Get the underlying elements of the Function... both the argument list and
|
2002-04-28 04:44:40 +00:00
|
|
|
// basic block list are empty for external functions.
|
2001-10-14 23:26:24 +00:00
|
|
|
//
|
2001-06-27 23:26:41 +00:00
|
|
|
inline const ArgumentListType &getArgumentList() const{ return ArgumentList; }
|
|
|
|
inline ArgumentListType &getArgumentList() { return ArgumentList; }
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
inline const BasicBlocksType &getBasicBlocks() const { return BasicBlocks; }
|
|
|
|
inline BasicBlocksType &getBasicBlocks() { return BasicBlocks; }
|
|
|
|
|
2001-10-14 23:26:24 +00:00
|
|
|
inline const BasicBlock *getEntryNode() const { return front(); }
|
|
|
|
inline BasicBlock *getEntryNode() { return front(); }
|
2002-04-28 04:44:40 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// 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!
|
|
|
|
//
|
|
|
|
bool hasSymbolTable() const;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
SymbolTable *getSymbolTableSure(); // Implemented in Value.cpp
|
|
|
|
|
2001-10-14 23:20:44 +00:00
|
|
|
|
2001-06-27 23:26:41 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// BasicBlock iterator forwarding functions
|
|
|
|
//
|
|
|
|
inline iterator begin() { return BasicBlocks.begin(); }
|
|
|
|
inline const_iterator begin() const { return BasicBlocks.begin(); }
|
|
|
|
inline iterator end () { return BasicBlocks.end(); }
|
|
|
|
inline const_iterator end () const { return BasicBlocks.end(); }
|
|
|
|
|
|
|
|
inline reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
|
|
|
|
inline const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
|
|
|
|
inline reverse_iterator rend () { return BasicBlocks.rend(); }
|
|
|
|
inline const_reverse_iterator rend () const { return BasicBlocks.rend(); }
|
|
|
|
|
|
|
|
inline unsigned size() const { return BasicBlocks.size(); }
|
|
|
|
inline bool empty() const { return BasicBlocks.empty(); }
|
|
|
|
inline const BasicBlock *front() const { return BasicBlocks.front(); }
|
|
|
|
inline BasicBlock *front() { return BasicBlocks.front(); }
|
|
|
|
inline const BasicBlock *back() const { return BasicBlocks.back(); }
|
|
|
|
inline BasicBlock *back() { return BasicBlocks.back(); }
|
|
|
|
|
2002-04-08 21:56:02 +00:00
|
|
|
virtual void print(std::ostream &OS) const;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-10-01 16:18:37 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2002-03-23 22:47:28 +00:00
|
|
|
static inline bool classof(const Function *) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Value *V) {
|
2002-03-26 17:48:08 +00:00
|
|
|
return V->getValueType() == Value::FunctionVal;
|
2001-10-01 16:18:37 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
// 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();
|
2001-09-28 22:56:31 +00:00
|
|
|
};
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|