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