Moved UnaryOperator::create to InstrTypes.cpp until there is an iUnaryOps.cpp
[oota-llvm.git] / lib / VMCore / iOperators.cpp
1 //===-- iBinaryOperators.cpp - Implement the BinaryOperators -----*- C++ -*--=//
2 //
3 // This file implements the nontrivial binary operator instructions.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/iBinary.h"
8 #include "llvm/Type.h"
9
10 BinaryOperator *BinaryOperator::create(unsigned Op, Value *S1, Value *S2,
11                                        const string &Name) {
12   switch (Op) {
13   case Add: return new AddInst(S1, S2, Name);
14   case Sub: return new SubInst(S1, S2, Name);
15   case SetLT:
16   case SetGT:
17   case SetLE:
18   case SetGE:
19   case SetEQ:
20   case SetNE:
21     return new SetCondInst((BinaryOps)Op, S1, S2, Name);
22
23   default:
24     cerr << "Don't know how to GetBinaryOperator " << Op << endl;
25     return 0;
26   }
27 }
28
29 //===----------------------------------------------------------------------===//
30 //                             SetCondInst Class
31 //===----------------------------------------------------------------------===//
32
33 SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2, 
34                          const string &Name) 
35   : BinaryOperator(opType, S1, S2, Name) {
36
37   OpType = opType;
38   setType(Type::BoolTy);   // setcc instructions always return bool type.
39
40   // Make sure it's a valid type...
41   assert(getOpcode() != "Invalid opcode type to SetCondInst class!");
42 }
43
44 string SetCondInst::getOpcode() const {
45   switch (OpType) {
46   case SetLE:  return "setle";
47   case SetGE:  return "setge";
48   case SetLT:  return "setlt";
49   case SetGT:  return "setgt";
50   case SetEQ:  return "seteq";
51   case SetNE:  return "setne";
52   default:
53     assert(0 && "Invalid opcode type to SetCondInst class!");
54     return "invalid opcode type to SetCondInst";
55   }
56 }