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 
12 #include "mcld/Script/Operator.h"
13 
14 #include <cstddef>
15 
16 namespace mcld {
17 
18 class IntOperand;
19 class Module;
20 class Operand;
21 class TargetLDBackend;
22 
23 /** \class TernaryOP
24  *  \brief This class defines the interfaces to an binary operator token.
25  */
26 
27 template <Operator::Type TYPE>
28 class TernaryOp : public Operator {
29  private:
30   friend class Operator;
31 
TernaryOp()32   TernaryOp() : Operator(Operator::TERNARY, TYPE) {
33     m_pOperand[0] = m_pOperand[1] = m_pOperand[2] = NULL;
34   }
35 
36  public:
~TernaryOp()37   ~TernaryOp() {}
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 == 3)
44       m_Size = 0;
45   }
46 
47  private:
48   size_t m_Size;
49   Operand* m_pOperand[3];
50 };
51 
52 template <>
53 IntOperand* TernaryOp<Operator::TERNARY_IF>::eval(const Module&,
54                                                   const TargetLDBackend&);
55 
56 template <>
57 IntOperand* TernaryOp<Operator::DATA_SEGMENT_ALIGN>::eval(
58     const Module&,
59     const TargetLDBackend&);
60 
61 }  // namespace mcld
62 
63 #endif  // MCLD_SCRIPT_TERNARYOP_H_
64