1 //===-- iOperators.cpp - Implement the Binary & Unary Operators --*- C++ -*--=//
3 // This file implements the nontrivial binary & unary operator instructions.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iOperators.h"
10 //===----------------------------------------------------------------------===//
11 // UnaryOperator Class
12 //===----------------------------------------------------------------------===//
14 UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source) {
16 case Not: return new GenericUnaryInst(Op, Source);
18 cerr << "Don't know how to Create UnaryOperator " << Op << endl;
24 //===----------------------------------------------------------------------===//
25 // GenericUnaryOperator Class
26 //===----------------------------------------------------------------------===//
28 const char *GenericUnaryInst::getOpcodeName() const {
29 switch (getOpcode()) {
30 case Not: return "not";
31 case Cast: return "cast";
33 cerr << "Invalid unary operator type!" << getOpcode() << endl;
39 //===----------------------------------------------------------------------===//
40 // BinaryOperator Class
41 //===----------------------------------------------------------------------===//
43 BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
46 // Binary comparison operators...
47 case SetLT: case SetGT: case SetLE:
48 case SetGE: case SetEQ: case SetNE:
49 return new SetCondInst(Op, S1, S2, Name);
52 return new GenericBinaryInst(Op, S1, S2, Name);
57 //===----------------------------------------------------------------------===//
58 // GenericBinaryInst Class
59 //===----------------------------------------------------------------------===//
61 const char *GenericBinaryInst::getOpcodeName() const {
62 switch (getOpcode()) {
63 // Standard binary operators...
64 case Add: return "add";
65 case Sub: return "sub";
66 case Mul: return "mul";
67 case Div: return "div";
68 case Rem: return "rem";
70 // Logical operators...
71 case And: return "and";
72 case Or : return "or";
73 case Xor: return "xor";
75 cerr << "Invalid binary operator type!" << getOpcode() << endl;
81 //===----------------------------------------------------------------------===//
83 //===----------------------------------------------------------------------===//
85 SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2,
87 : BinaryOperator(opType, S1, S2, Name) {
90 setType(Type::BoolTy); // setcc instructions always return bool type.
92 // Make sure it's a valid type...
93 assert(getOpcodeName() != 0);
96 const char *SetCondInst::getOpcodeName() const {
98 case SetLE: return "setle";
99 case SetGE: return "setge";
100 case SetLT: return "setlt";
101 case SetGT: return "setgt";
102 case SetEQ: return "seteq";
103 case SetNE: return "setne";
105 assert(0 && "Invalid opcode type to SetCondInst class!");
106 return "invalid opcode type to SetCondInst";