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 15namespace mcld 16{ 17 18class Operand; 19class IntOperand; 20class Module; 21class TargetLDBackend; 22 23/** \class BinaryOP 24 * \brief This class defines the interfaces to an binary operator token. 25 */ 26 27template<Operator::Type TYPE> 28class BinaryOp : public Operator 29{ 30private: 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 39public: 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 52private: 53 size_t m_Size; 54 Operand* m_pOperand[2]; 55}; 56 57template<> 58IntOperand* BinaryOp<Operator::MUL>::eval(const Module&, 59 const TargetLDBackend&); 60template<> 61IntOperand* BinaryOp<Operator::DIV>::eval(const Module&, 62 const TargetLDBackend&); 63template<> 64IntOperand* BinaryOp<Operator::MOD>::eval(const Module&, 65 const TargetLDBackend&); 66template<> 67IntOperand* BinaryOp<Operator::ADD>::eval(const Module&, 68 const TargetLDBackend&); 69template<> 70IntOperand* BinaryOp<Operator::SUB>::eval(const Module&, 71 const TargetLDBackend&); 72template<> 73IntOperand* BinaryOp<Operator::LSHIFT>::eval(const Module&, 74 const TargetLDBackend&); 75template<> 76IntOperand* BinaryOp<Operator::RSHIFT>::eval(const Module&, 77 const TargetLDBackend&); 78template<> 79IntOperand* BinaryOp<Operator::LT>::eval(const Module&, 80 const TargetLDBackend&); 81template<> 82IntOperand* BinaryOp<Operator::LE>::eval(const Module&, 83 const TargetLDBackend&); 84template<> 85IntOperand* BinaryOp<Operator::GT>::eval(const Module&, 86 const TargetLDBackend&); 87template<> 88IntOperand* BinaryOp<Operator::GE>::eval(const Module&, 89 const TargetLDBackend&); 90template<> 91IntOperand* BinaryOp<Operator::EQ>::eval(const Module&, 92 const TargetLDBackend&); 93template<> 94IntOperand* BinaryOp<Operator::NE>::eval(const Module&, 95 const TargetLDBackend&); 96template<> 97IntOperand* BinaryOp<Operator::BITWISE_AND>::eval(const Module&, 98 const TargetLDBackend&); 99template<> 100IntOperand* BinaryOp<Operator::BITWISE_XOR>::eval(const Module&, 101 const TargetLDBackend&); 102template<> 103IntOperand* BinaryOp<Operator::BITWISE_OR>::eval(const Module&, 104 const TargetLDBackend&); 105template<> 106IntOperand* BinaryOp<Operator::LOGICAL_AND>::eval(const Module&, 107 const TargetLDBackend&); 108template<> 109IntOperand* BinaryOp<Operator::LOGICAL_OR>::eval(const Module&, 110 const TargetLDBackend&); 111 112template<> 113IntOperand* BinaryOp<Operator::ALIGN>::eval(const Module&, 114 const TargetLDBackend&); 115template<> 116IntOperand* 117BinaryOp<Operator::DATA_SEGMENT_RELRO_END>::eval(const Module&, 118 const TargetLDBackend&); 119template<> 120IntOperand* BinaryOp<Operator::MAX>::eval(const Module&, 121 const TargetLDBackend&); 122template<> 123IntOperand* BinaryOp<Operator::MIN>::eval(const Module&, 124 const TargetLDBackend&); 125template<> 126IntOperand* BinaryOp<Operator::SEGMENT_START>::eval(const Module&, 127 const TargetLDBackend&); 128 129} // namespace of mcld 130 131#endif 132 133