TernaryOp.h revision f33f6de54db174aa679a4b6d1e040d37e95541c0
1//===- TernaryOp.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_TERNARYOP_H 10#define MCLD_SCRIPT_TERNARYOP_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 TernaryOP 27 * \brief This class defines the interfaces to an binary operator token. 28 */ 29 30template<Operator::Type TYPE> 31class TernaryOp : public Operator 32{ 33private: 34 friend class Operator; 35 36 TernaryOp() 37 : Operator(Operator::TERNARY, TYPE) 38 { 39 m_pOperand[0] = m_pOperand[1] = m_pOperand[2] = NULL; 40 } 41 42public: 43 ~TernaryOp() 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 == 3) 52 m_Size = 0; 53 } 54 55private: 56 size_t m_Size; 57 Operand* m_pOperand[3]; 58}; 59 60template<> 61IntOperand* TernaryOp<Operator::TERNARY_IF>::eval(const Module&, 62 const TargetLDBackend&); 63 64template<> 65IntOperand* 66TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(const Module&, 67 const TargetLDBackend&); 68 69} // namespace of mcld 70 71#endif 72