1 //===-- iBinaryOperators.cpp - Implement the BinaryOperators -----*- C++ -*--=//
3 // This file implements the nontrivial binary operator instructions.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iBinary.h"
10 UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source,
11 const Type *DestTy = 0) {
12 if (DestTy == 0) DestTy = Source->getType();
14 case Not: assert(DestTy == Source->getType());
15 case Cast: return new GenericUnaryInst(Op, Source, DestTy);
17 cerr << "Don't know how to GetUnaryOperator " << Op << endl;
22 const char *GenericUnaryInst::getOpcodeName() const {
23 switch (getOpcode()) {
24 case Not: return "not";
25 case Cast: return "cast";
27 cerr << "Invalid unary operator type!" << getOpcode() << endl;
32 //===----------------------------------------------------------------------===//
33 // BinaryOperator Class
34 //===----------------------------------------------------------------------===//
36 BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
39 // Binary comparison operators...
40 case SetLT: case SetGT: case SetLE:
41 case SetGE: case SetEQ: case SetNE:
42 return new SetCondInst(Op, S1, S2, Name);
45 return new GenericBinaryInst(Op, S1, S2, Name);
49 //===----------------------------------------------------------------------===//
50 // GenericBinaryInst Class
51 //===----------------------------------------------------------------------===//
53 const char *GenericBinaryInst::getOpcodeName() const {
54 switch (getOpcode()) {
55 // Standard binary operators...
56 case Add: return "add";
57 case Sub: return "sub";
58 case Mul: return "mul";
59 case Div: return "div";
60 case Rem: return "rem";
62 // Logical operators...
63 case And: return "and";
64 case Or : return "or";
65 case Xor: return "xor";
67 cerr << "Invalid binary operator type!" << getOpcode() << endl;
72 //===----------------------------------------------------------------------===//
74 //===----------------------------------------------------------------------===//
76 SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2,
78 : BinaryOperator(opType, S1, S2, Name) {
81 setType(Type::BoolTy); // setcc instructions always return bool type.
83 // Make sure it's a valid type...
84 assert(getOpcodeName() != 0);
87 const char *SetCondInst::getOpcodeName() const {
89 case SetLE: return "setle";
90 case SetGE: return "setge";
91 case SetLT: return "setlt";
92 case SetGT: return "setgt";
93 case SetEQ: return "seteq";
94 case SetNE: return "setne";
96 assert(0 && "Invalid opcode type to SetCondInst class!");
97 return "invalid opcode type to SetCondInst";