OpenASIP  2.0
Operand.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file Operand.hh
26  *
27  * Declaration of Operand class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @author Mikael Lepistö 2007 (tmlepist-no.spam-cs.tut.fi)
31  * @note rating: yellow
32  * @note reviewed 17 August 2004 by jn, ll, tr, pj
33  */
34 
35 #ifndef TTA_OPERAND_HH
36 #define TTA_OPERAND_HH
37 
38 #include <set>
39 #include <string>
40 #include <TCEString.hh>
41 
42 #include "Serializable.hh"
43 #include "Exception.hh"
44 
45 class ObjectState;
46 
47 /**
48  * Class that models Operation Operand.
49  *
50  * Contains the static properties of Operation inputs and outputs.
51  */
52 class Operand : public Serializable {
53 public:
54 
55  /**
56  * Type of operand.
57  */
58  enum OperandType {
68  };
69 
70  static const std::string SLONG_WORD_STRING;
71  static const std::string ULONG_WORD_STRING;
72  static const std::string SINT_WORD_STRING;
73  static const std::string UINT_WORD_STRING;
74  static const std::string HALF_FLOAT_WORD_STRING;
75  static const std::string FLOAT_WORD_STRING;
76  static const std::string DOUBLE_WORD_STRING;
77  static const std::string BOOL_STRING;
78  static const std::string RAW_DATA_STRING;
79  static const std::string UNKNOWN_TYPE_STRING;
80 
81  /// Object state name for operand id.
82  static const std::string OPRND_ID;
83  /// Object state name for operand type.
84  static const std::string OPRND_TYPE;
85  /// Object state name for memory address.
86  static const std::string OPRND_MEM_ADDRESS;
87  /// Object state name for memory unit count.
88  static const std::string OPRND_MEM_UNITS;
89  /// Object state name for memory data.
90  static const std::string OPRND_MEM_DATA;
91  /// Object state name for can swap.
92  static const std::string OPRND_CAN_SWAP;
93  /// Object state name for input operand.
94  static const std::string OPRND_IN;
95  /// Object state name for output operand.
96  static const std::string OPRND_OUT;
97  /// Object state name for element width.
98  static const std::string OPRND_ELEM_WIDTH;
99  /// Object state name for element count.
100  static const std::string OPRND_ELEM_COUNT;
101 
102  explicit Operand(bool isInput);
103  explicit Operand(bool isInput, int index, OperandType type);
104  Operand(const Operand& op);
105  virtual ~Operand();
106 
107  virtual int index() const;
108  virtual bool isInput() const;
109  virtual bool isOutput() const;
110  virtual OperandType type() const;
111  virtual void setType(OperandType type);
112  virtual const std::string& typeString() const;
113  virtual TCEString CTypeString() const;
114 
115  virtual bool isVector() const;
116  virtual int elementWidth() const;
117  virtual void setElementWidth(int elementWidth);
118  virtual int elementCount() const;
119  virtual void setElementCount(int elementCount);
120  virtual int width() const;
121  virtual bool isAddress() const;
122  virtual int memoryUnits() const;
123  virtual bool isMemoryData() const;
124  virtual bool canSwap(const Operand& op) const;
125  virtual const std::set<int>& swap() const;
126 
127  virtual void loadState(const ObjectState* state);
128  virtual ObjectState* saveState() const;
129 
130  virtual bool isNull() const { return false; }
131 
133 
134 private:
135  void clear();
136 
137  /// Assignment not allowed.
138  Operand& operator=(const Operand&);
139 
140  /// Index of the Operand.
141  int index_;
142  /// Direction of operand.
143  bool isInput_;
144  /// Type of the Operand.
146  /// Width of an element.
148  /// Number of total elements.
150  /// Flag indicating whether Operand is address or not.
152  /// size of the data this operation addresses. 0 if unknown.
154  /// Flag indicating whether Operand is memory data or not.
156  /// Indexes of Operands which can be swapped with this Operand.
157  std::set<int> swap_;
158 };
159 
160 //////////////////////////////////////////////////////////////////////////////
161 // NullOperand
162 //////////////////////////////////////////////////////////////////////////////
163 
164 /**
165  * Singleton class that is used to represent a null operand.
166  *
167  * All methods cause program abort with an error log message.
168  *
169  */
170 class NullOperand : public Operand {
171 public:
172  virtual ~NullOperand();
173 
174  static NullOperand& instance();
175 
176  virtual int index() const;
177  virtual bool isInput() const;
178  virtual bool isOutput() const;
179  virtual bool isAddress() const;
180  virtual bool isMemoryData() const;
181  virtual bool canSwap(const Operand& op) const;
182  virtual const std::set<int>& swap() const;
183  virtual bool isNull() const { return true; }
184 
185 private:
186  NullOperand();
187  /// Assignment not allowed.
189 
190  /// Unique instance.
192 
193  /// Needed for one method, always empty.
194  std::set<int> swap_;
195 };
196 
197 #include "Operand.icc"
198 
199 #endif
Operand
Definition: Operand.hh:52
Operand::elementCount_
int elementCount_
Number of total elements.
Definition: Operand.hh:149
Operand::OPRND_ELEM_COUNT
static const std::string OPRND_ELEM_COUNT
Object state name for element count.
Definition: Operand.hh:100
Operand::OPRND_MEM_DATA
static const std::string OPRND_MEM_DATA
Object state name for memory data.
Definition: Operand.hh:90
Operand::setElementCount
virtual void setElementCount(int elementCount)
Definition: Operand.cc:308
Operand::BOOL
@ BOOL
Definition: Operand.hh:64
NullOperand::NullOperand
NullOperand()
Definition: Operand.cc:578
Operand::SINT_WORD_STRING
static const std::string SINT_WORD_STRING
Definition: Operand.hh:72
NullOperand::isOutput
virtual bool isOutput() const
Definition: Operand.cc:615
Operand::SLONG_WORD_STRING
static const std::string SLONG_WORD_STRING
Definition: Operand.hh:70
Operand::OPRND_MEM_ADDRESS
static const std::string OPRND_MEM_ADDRESS
Object state name for memory address.
Definition: Operand.hh:86
NullOperand::isAddress
virtual bool isAddress() const
Definition: Operand.cc:626
Operand::addressUnits_
int addressUnits_
size of the data this operation addresses. 0 if unknown.
Definition: Operand.hh:153
Operand::OperandType
OperandType
Definition: Operand.hh:58
Operand::HALF_FLOAT_WORD
@ HALF_FLOAT_WORD
Definition: Operand.hh:63
Exception.hh
Operand::OPRND_MEM_UNITS
static const std::string OPRND_MEM_UNITS
Object state name for memory unit count.
Definition: Operand.hh:88
Operand::saveState
virtual ObjectState * saveState() const
Definition: Operand.cc:490
Operand::elementCount
virtual int elementCount() const
Definition: Operand.cc:298
Operand::elementWidth_
int elementWidth_
Width of an element.
Definition: Operand.hh:147
Operand::isAddress_
bool isAddress_
Flag indicating whether Operand is address or not.
Definition: Operand.hh:151
NullOperand::isMemoryData
virtual bool isMemoryData() const
Definition: Operand.cc:637
NullOperand::isInput
virtual bool isInput() const
Definition: Operand.cc:604
Serializable
Definition: Serializable.hh:44
Operand::UINT_WORD
@ UINT_WORD
Definition: Operand.hh:60
Operand::width
virtual int width() const
Definition: Operand.cc:318
Operand::setType
virtual void setType(OperandType type)
Definition: Operand.cc:175
Operand::OPRND_CAN_SWAP
static const std::string OPRND_CAN_SWAP
Object state name for can swap.
Definition: Operand.hh:92
ObjectState
Definition: ObjectState.hh:59
Operand::setElementWidth
virtual void setElementWidth(int elementWidth)
Definition: Operand.cc:288
NullOperand::instance
static NullOperand & instance()
Operand::elementWidth
virtual int elementWidth() const
Definition: Operand.cc:278
Operand::OPRND_OUT
static const std::string OPRND_OUT
Object state name for output operand.
Definition: Operand.hh:96
Operand::isOutput
virtual bool isOutput() const
Definition: Operand.cc:155
Operand::isNull
virtual bool isNull() const
Definition: Operand.hh:130
Operand::RAW_DATA_STRING
static const std::string RAW_DATA_STRING
Definition: Operand.hh:78
Operand::HALF_FLOAT_WORD_STRING
static const std::string HALF_FLOAT_WORD_STRING
Definition: Operand.hh:74
Operand::FLOAT_WORD_STRING
static const std::string FLOAT_WORD_STRING
Definition: Operand.hh:75
TCEString.hh
Operand::isVector
virtual bool isVector() const
Definition: Operand.cc:268
NullOperand::canSwap
virtual bool canSwap(const Operand &op) const
Definition: Operand.cc:659
Operand::OPRND_ID
static const std::string OPRND_ID
Object state name for operand id.
Definition: Operand.hh:82
Operand::canSwap
virtual bool canSwap(const Operand &op) const
Definition: Operand.cc:372
NullOperand::isNull
virtual bool isNull() const
Definition: Operand.hh:183
Operand::isInput_
bool isInput_
Direction of operand.
Definition: Operand.hh:143
Operand::SLONG_WORD
@ SLONG_WORD
Definition: Operand.hh:66
Operand::DOUBLE_WORD_STRING
static const std::string DOUBLE_WORD_STRING
Definition: Operand.hh:76
Operand::typeString
virtual const std::string & typeString() const
Definition: Operand.cc:185
NullOperand::swap
virtual const std::set< int > & swap() const
Definition: Operand.cc:648
Operand::FLOAT_WORD
@ FLOAT_WORD
Definition: Operand.hh:61
Operand::UINT_WORD_STRING
static const std::string UINT_WORD_STRING
Definition: Operand.hh:73
Operand::index
virtual int index() const
Definition: Operand.cc:135
Operand::swap_
std::set< int > swap_
Indexes of Operands which can be swapped with this Operand.
Definition: Operand.hh:157
Operand::SINT_WORD
@ SINT_WORD
Definition: Operand.hh:59
Operand::OPRND_IN
static const std::string OPRND_IN
Object state name for input operand.
Definition: Operand.hh:94
Operand::ULONG_WORD
@ ULONG_WORD
Definition: Operand.hh:67
Operand::clear
void clear()
Definition: Operand.cc:120
Operand::RAW_DATA
@ RAW_DATA
Definition: Operand.hh:65
Operand::operator=
Operand & operator=(const Operand &)
Assignment not allowed.
NullOperand::~NullOperand
virtual ~NullOperand()
Definition: Operand.cc:584
Operand::UNKNOWN_TYPE_STRING
static const std::string UNKNOWN_TYPE_STRING
Definition: Operand.hh:79
Operand::OPRND_TYPE
static const std::string OPRND_TYPE
Object state name for operand type.
Definition: Operand.hh:84
Serializable.hh
Operand::DOUBLE_WORD
@ DOUBLE_WORD
Definition: Operand.hh:62
Operand::OPRND_ELEM_WIDTH
static const std::string OPRND_ELEM_WIDTH
Object state name for element width.
Definition: Operand.hh:98
NullOperand::instance_
static NullOperand * instance_
Unique instance.
Definition: Operand.hh:191
NullOperand::operator=
NullOperand & operator=(const NullOperand &)
Assignment not allowed.
Operand::type
virtual OperandType type() const
Definition: Operand.cc:165
TCEString
Definition: TCEString.hh:53
Operand::Operand
Operand(bool isInput)
Definition: Operand.cc:75
Operand::CTypeString
virtual TCEString CTypeString() const
Definition: Operand.cc:222
Operand::isMemoryData
virtual bool isMemoryData() const
Definition: Operand.cc:351
Operand::type_
OperandType type_
Type of the Operand.
Definition: Operand.hh:145
Operand::memoryUnits
virtual int memoryUnits() const
Definition: Operand.cc:341
Operand::BOOL_STRING
static const std::string BOOL_STRING
Definition: Operand.hh:77
NullOperand
Definition: Operand.hh:170
NullOperand::index
virtual int index() const
Definition: Operand.cc:593
Operand::isAddress
virtual bool isAddress() const
Definition: Operand.cc:328
Operand::isMemoryData_
bool isMemoryData_
Flag indicating whether Operand is memory data or not.
Definition: Operand.hh:155
Operand::isInput
virtual bool isInput() const
Definition: Operand.cc:145
NullOperand::swap_
std::set< int > swap_
Needed for one method, always empty.
Definition: Operand.hh:194
Operand.icc
Operand::ULONG_WORD_STRING
static const std::string ULONG_WORD_STRING
Definition: Operand.hh:71
Operand::defaultElementWidth
static int defaultElementWidth(OperandType type)
Definition: Operand.cc:557
Operand::index_
int index_
Index of the Operand.
Definition: Operand.hh:141
Operand::~Operand
virtual ~Operand()
Definition: Operand.cc:110
Operand::loadState
virtual void loadState(const ObjectState *state)
Definition: Operand.cc:383
Operand::swap
virtual const std::set< int > & swap() const
Definition: Operand.cc:361