36a26d7f25c32b476ab4b5f1497e7091efbc33ed
[oota-llvm.git] / include / llvm / Constant.h
1 //===-- llvm/Constant.h - Constant class definition --------------*- C++ -*--=//
2 //
3 // This file contains the declaration of the Constant class.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_CONSTANT_H
8 #define LLVM_CONSTANT_H
9
10 #include "llvm/User.h"
11
12 class Constant : public User {
13 protected:
14   inline Constant(const Type *Ty) : User(Ty, Value::ConstantVal) {}
15   ~Constant() {}
16
17   // destroyConstant - Called if some element of this constant is no longer
18   // valid.  At this point only other constants may be on the use_list for this
19   // constant.  Any constants on our Use list must also be destroy'd.  The
20   // implementation must be sure to remove the constant from the list of
21   // available cached constants.  Implementations should call
22   // destroyConstantImpl as the last thing they do, to destroy all users and
23   // delete this.
24   //
25   virtual void destroyConstant() { assert(0 && "Not reached!"); }
26   void destroyConstantImpl();
27 public:
28   // Specialize setName to handle symbol table majik...
29   virtual void setName(const std::string &name, SymbolTable *ST = 0);
30
31   // Static constructor to get a '0' constant of arbitrary type...
32   static Constant *getNullValue(const Type *Ty);
33
34   // isNullValue - Return true if this is the value that would be returned by
35   // getNullValue.
36   virtual bool isNullValue() const = 0;
37
38   virtual void print(std::ostream &O) const;
39
40   // isConstantExpr - Return true if this is a ConstantExpr
41   virtual bool isConstantExpr() const { return false; }
42   
43   // Methods for support type inquiry through isa, cast, and dyn_cast:
44   static inline bool classof(const Constant *) { return true; }
45   static inline bool classof(const Value *V) {
46     return V->getValueType() == Value::ConstantVal;
47   }
48
49   // WARNING: Only to be used by Bytecode & Assembly Parsers!  USER CODE SHOULD
50   // NOT USE THIS!!
51   // Returns the number of uses of OldV that were replaced.
52   virtual unsigned mutateReferences(Value* OldV, Value *NewV) { return 0; }
53   // END WARNING!!
54 };
55
56 #endif