* Add virtual print methods
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
2 //
3 // This file contains the declarations for instructions that fall into the 
4 // grandios 'other' catagory...
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_IOTHER_H
9 #define LLVM_IOTHER_H
10
11 #include "llvm/InstrTypes.h"
12 #include "llvm/Function.h"
13
14 //===----------------------------------------------------------------------===//
15 //                                 CastInst Class
16 //===----------------------------------------------------------------------===//
17
18 // CastInst - This class represents a cast from Operand[0] to the type of
19 // the instruction (i->getType()).
20 //
21 class CastInst : public Instruction {
22   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
23     Operands.reserve(1);
24     Operands.push_back(Use(CI.Operands[0], this));
25   }
26 public:
27   CastInst(Value *S, const Type *Ty, const std::string &Name = "")
28     : Instruction(Ty, Cast, Name) {
29     Operands.reserve(1);
30     Operands.push_back(Use(S, this));
31   }
32
33   virtual Instruction *clone() const { return new CastInst(*this); }
34   virtual const char *getOpcodeName() const { return "cast"; }
35
36   // Methods for support type inquiry through isa, cast, and dyn_cast:
37   static inline bool classof(const CastInst *) { return true; }
38   static inline bool classof(const Instruction *I) {
39     return I->getOpcode() == Cast;
40   }
41   static inline bool classof(const Value *V) {
42     return isa<Instruction>(V) && classof(cast<Instruction>(V));
43   }
44 };
45
46
47 //===----------------------------------------------------------------------===//
48 //                           FunctionArgument Class
49 //===----------------------------------------------------------------------===//
50
51 class FunctionArgument : public Value {  // Defined in the InstrType.cpp file
52   Function *Parent;
53
54   friend class ValueHolder<FunctionArgument,Function,Function>;
55   inline void setParent(Function *parent) { Parent = parent; }
56
57 public:
58   FunctionArgument(const Type *Ty, const std::string &Name = "") 
59     : Value(Ty, Value::FunctionArgumentVal, Name) {
60     Parent = 0;
61   }
62
63   // Specialize setName to handle symbol table majik...
64   virtual void setName(const std::string &name, SymbolTable *ST = 0);
65
66   inline const Function *getParent() const { return Parent; }
67   inline       Function *getParent()       { return Parent; }
68
69   virtual void print(std::ostream &OS) const;
70
71   // Methods for support type inquiry through isa, cast, and dyn_cast:
72   static inline bool classof(const FunctionArgument *) { return true; }
73   static inline bool classof(const Value *V) {
74     return V->getValueType() == FunctionArgumentVal;
75   }
76 };
77
78
79 //===----------------------------------------------------------------------===//
80 //             Classes to function calls and method invocations
81 //===----------------------------------------------------------------------===//
82
83 class CallInst : public Instruction {
84   CallInst(const CallInst &CI);
85 public:
86   CallInst(Value *M, const std::vector<Value*> &Par, const std::string & = "");
87
88   virtual const char *getOpcodeName() const { return "call"; }
89
90   virtual Instruction *clone() const { return new CallInst(*this); }
91   bool hasSideEffects() const { return true; }
92
93   const Function *getCalledFunction() const {
94     return dyn_cast<Function>(Operands[0]);
95   }
96   Function *getCalledFunction() {
97     return dyn_cast<Function>(Operands[0]);
98   }
99
100   // getCalledValue - Get a pointer to a method that is invoked by this inst.
101   inline const Value *getCalledValue() const { return Operands[0]; }
102   inline       Value *getCalledValue()       { return Operands[0]; }
103
104   // Methods for support type inquiry through isa, cast, and dyn_cast:
105   static inline bool classof(const CallInst *) { return true; }
106   static inline bool classof(const Instruction *I) {
107     return I->getOpcode() == Instruction::Call; 
108   }
109   static inline bool classof(const Value *V) {
110     return isa<Instruction>(V) && classof(cast<Instruction>(V));
111   }
112 };
113
114
115 //===----------------------------------------------------------------------===//
116 //                                 ShiftInst Class
117 //===----------------------------------------------------------------------===//
118
119 // ShiftInst - This class represents left and right shift instructions.
120 //
121 class ShiftInst : public Instruction {
122   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
123     Operands.reserve(2);
124     Operands.push_back(Use(SI.Operands[0], this));
125     Operands.push_back(Use(SI.Operands[1], this));
126   }
127 public:
128   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "")
129     : Instruction(S->getType(), Opcode, Name) {
130     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
131     Operands.reserve(2);
132     Operands.push_back(Use(S, this));
133     Operands.push_back(Use(SA, this));
134   }
135
136   OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
137
138   virtual Instruction *clone() const { return new ShiftInst(*this); }
139   virtual const char *getOpcodeName() const {
140     return getOpcode() == Shl ? "shl" : "shr"; 
141   }
142
143   // Methods for support type inquiry through isa, cast, and dyn_cast:
144   static inline bool classof(const ShiftInst *) { return true; }
145   static inline bool classof(const Instruction *I) {
146     return (I->getOpcode() == Instruction::Shr) | 
147            (I->getOpcode() == Instruction::Shl);
148   }
149   static inline bool classof(const Value *V) {
150     return isa<Instruction>(V) && classof(cast<Instruction>(V));
151   }
152 };
153
154 #endif