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