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