1 //===- BinaryOp.h ---------------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef MCLD_SCRIPT_BINARYOP_H 10 #define MCLD_SCRIPT_BINARYOP_H 11 12 #include <mcld/Script/Operator.h> 13 #include <cstddef> 14 15 namespace mcld 16 { 17 18 class Operand; 19 class IntOperand; 20 class Module; 21 class TargetLDBackend; 22 23 /** \class BinaryOP 24 * \brief This class defines the interfaces to an binary operator token. 25 */ 26 27 template<Operator::Type TYPE> 28 class BinaryOp : public Operator 29 { 30 private: 31 friend class Operator; 32 33 BinaryOp() 34 : Operator(Operator::BINARY, TYPE), m_Size(0) 35 { 36 m_pOperand[0] = m_pOperand[1] = NULL; 37 } 38 39 public: 40 ~BinaryOp() 41 {} 42 43 IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend); 44 45 void appendOperand(Operand* pOperand) 46 { 47 m_pOperand[m_Size++] = pOperand; 48 if (m_Size == 2) 49 m_Size = 0; 50 } 51 52 private: 53 size_t m_Size; 54 Operand* m_pOperand[2]; 55 }; 56 57 template<> 58 IntOperand* BinaryOp<Operator::MUL>::eval(const Module&, 59 const TargetLDBackend&); 60 template<> 61 IntOperand* BinaryOp<Operator::DIV>::eval(const Module&, 62 const TargetLDBackend&); 63 template<> 64 IntOperand* BinaryOp<Operator::MOD>::eval(const Module&, 65 const TargetLDBackend&); 66 template<> 67 IntOperand* BinaryOp<Operator::ADD>::eval(const Module&, 68 const TargetLDBackend&); 69 template<> 70 IntOperand* BinaryOp<Operator::SUB>::eval(const Module&, 71 const TargetLDBackend&); 72 template<> 73 IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module&, 74 const TargetLDBackend&); 75 template<> 76 IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module&, 77 const TargetLDBackend&); 78 template<> 79 IntOperand* BinaryOp<Operator::LT>::eval(const Module&, 80 const TargetLDBackend&); 81 template<> 82 IntOperand* BinaryOp<Operator::LE>::eval(const Module&, 83 const TargetLDBackend&); 84 template<> 85 IntOperand* BinaryOp<Operator::GT>::eval(const Module&, 86 const TargetLDBackend&); 87 template<> 88 IntOperand* BinaryOp<Operator::GE>::eval(const Module&, 89 const TargetLDBackend&); 90 template<> 91 IntOperand* BinaryOp<Operator::EQ>::eval(const Module&, 92 const TargetLDBackend&); 93 template<> 94 IntOperand* BinaryOp<Operator::NE>::eval(const Module&, 95 const TargetLDBackend&); 96 template<> 97 IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(const Module&, 98 const TargetLDBackend&); 99 template<> 100 IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(const Module&, 101 const TargetLDBackend&); 102 template<> 103 IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(const Module&, 104 const TargetLDBackend&); 105 template<> 106 IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(const Module&, 107 const TargetLDBackend&); 108 template<> 109 IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(const Module&, 110 const TargetLDBackend&); 111 112 template<> 113 IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module&, 114 const TargetLDBackend&); 115 template<> 116 IntOperand* 117 BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module&, 118 const TargetLDBackend&); 119 template<> 120 IntOperand* BinaryOp<Operator::MAX>::eval(const Module&, 121 const TargetLDBackend&); 122 template<> 123 IntOperand* BinaryOp<Operator::MIN>::eval(const Module&, 124 const TargetLDBackend&); 125 template<> 126 IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(const Module&, 127 const TargetLDBackend&); 128 129 } // namespace of mcld 130 131 #endif 132 133