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 14 #include <cstddef> 15 16 namespace mcld { 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 private: 30 friend class Operator; 31 BinaryOp()32 BinaryOp() : Operator(Operator::BINARY, TYPE), m_Size(0) { 33 m_pOperand[0] = m_pOperand[1] = NULL; 34 } 35 36 public: ~BinaryOp()37 ~BinaryOp() {} 38 39 IntOperand* eval(const Module& pModule, const TargetLDBackend& pBackend); 40 appendOperand(Operand * pOperand)41 void appendOperand(Operand* pOperand) { 42 m_pOperand[m_Size++] = pOperand; 43 if (m_Size == 2) 44 m_Size = 0; 45 } 46 47 private: 48 size_t m_Size; 49 Operand* m_pOperand[2]; 50 }; 51 52 template <> 53 IntOperand* BinaryOp<Operator::MUL>::eval(const Module&, 54 const TargetLDBackend&); 55 template <> 56 IntOperand* BinaryOp<Operator::DIV>::eval(const Module&, 57 const TargetLDBackend&); 58 template <> 59 IntOperand* BinaryOp<Operator::MOD>::eval(const Module&, 60 const TargetLDBackend&); 61 template <> 62 IntOperand* BinaryOp<Operator::ADD>::eval(const Module&, 63 const TargetLDBackend&); 64 template <> 65 IntOperand* BinaryOp<Operator::SUB>::eval(const Module&, 66 const TargetLDBackend&); 67 template <> 68 IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module&, 69 const TargetLDBackend&); 70 template <> 71 IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module&, 72 const TargetLDBackend&); 73 template <> 74 IntOperand* BinaryOp<Operator::LT>::eval(const Module&, const TargetLDBackend&); 75 template <> 76 IntOperand* BinaryOp<Operator::LE>::eval(const Module&, const TargetLDBackend&); 77 template <> 78 IntOperand* BinaryOp<Operator::GT>::eval(const Module&, const TargetLDBackend&); 79 template <> 80 IntOperand* BinaryOp<Operator::GE>::eval(const Module&, const TargetLDBackend&); 81 template <> 82 IntOperand* BinaryOp<Operator::EQ>::eval(const Module&, const TargetLDBackend&); 83 template <> 84 IntOperand* BinaryOp<Operator::NE>::eval(const Module&, const TargetLDBackend&); 85 template <> 86 IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(const Module&, 87 const TargetLDBackend&); 88 template <> 89 IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(const Module&, 90 const TargetLDBackend&); 91 template <> 92 IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(const Module&, 93 const TargetLDBackend&); 94 template <> 95 IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(const Module&, 96 const TargetLDBackend&); 97 template <> 98 IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(const Module&, 99 const TargetLDBackend&); 100 101 template <> 102 IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module&, 103 const TargetLDBackend&); 104 template <> 105 IntOperand* BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval( 106 const Module&, 107 const TargetLDBackend&); 108 template <> 109 IntOperand* BinaryOp<Operator::MAX>::eval(const Module&, 110 const TargetLDBackend&); 111 template <> 112 IntOperand* BinaryOp<Operator::MIN>::eval(const Module&, 113 const TargetLDBackend&); 114 template <> 115 IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(const Module&, 116 const TargetLDBackend&); 117 118 } // namespace mcld 119 120 #endif // MCLD_SCRIPT_BINARYOP_H_ 121