OpenASIP 2.2
Loading...
Searching...
No Matches
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
45class ObjectState;
46
47/**
48 * Class that models Operation Operand.
49 *
50 * Contains the static properties of Operation inputs and outputs.
51 */
52class Operand : public Serializable {
53public:
54
55 /**
56 * Type of operand.
57 */
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
134private:
135 void clear();
136
137 /// Assignment not allowed.
139
140 /// Index of the Operand.
142 /// Direction of operand.
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 */
170class NullOperand : public Operand {
171public:
172 virtual ~NullOperand();
173
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
185private:
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
NullOperand & operator=(const NullOperand &)
Assignment not allowed.
virtual bool isAddress() const
Definition Operand.cc:626
std::set< int > swap_
Needed for one method, always empty.
Definition Operand.hh:194
virtual bool isInput() const
Definition Operand.cc:604
virtual bool isNull() const
Definition Operand.hh:183
virtual int index() const
Definition Operand.cc:593
virtual const std::set< int > & swap() const
Definition Operand.cc:648
virtual bool isOutput() const
Definition Operand.cc:615
static NullOperand * instance_
Unique instance.
Definition Operand.hh:191
virtual bool canSwap(const Operand &op) const
Definition Operand.cc:659
virtual ~NullOperand()
Definition Operand.cc:584
static NullOperand & instance()
virtual bool isMemoryData() const
Definition Operand.cc:637
bool isInput_
Direction of operand.
Definition Operand.hh:143
virtual bool isVector() const
Definition Operand.cc:268
virtual const std::string & typeString() const
Definition Operand.cc:185
virtual bool isMemoryData() const
Definition Operand.cc:351
static const std::string OPRND_IN
Object state name for input operand.
Definition Operand.hh:94
virtual int elementCount() const
Definition Operand.cc:298
virtual bool isAddress() const
Definition Operand.cc:328
virtual void setElementWidth(int elementWidth)
Definition Operand.cc:288
static const std::string FLOAT_WORD_STRING
Definition Operand.hh:75
static const std::string OPRND_CAN_SWAP
Object state name for can swap.
Definition Operand.hh:92
virtual bool isInput() const
Definition Operand.cc:145
void clear()
Definition Operand.cc:120
static const std::string OPRND_ELEM_WIDTH
Object state name for element width.
Definition Operand.hh:98
static const std::string SLONG_WORD_STRING
Definition Operand.hh:70
virtual bool isOutput() const
Definition Operand.cc:155
static const std::string OPRND_MEM_UNITS
Object state name for memory unit count.
Definition Operand.hh:88
virtual int index() const
Definition Operand.cc:135
virtual void setType(OperandType type)
Definition Operand.cc:175
bool isAddress_
Flag indicating whether Operand is address or not.
Definition Operand.hh:151
virtual const std::set< int > & swap() const
Definition Operand.cc:361
int index_
Index of the Operand.
Definition Operand.hh:141
static const std::string OPRND_TYPE
Object state name for operand type.
Definition Operand.hh:84
static int defaultElementWidth(OperandType type)
Definition Operand.cc:557
virtual int memoryUnits() const
Definition Operand.cc:341
Operand & operator=(const Operand &)
Assignment not allowed.
static const std::string OPRND_MEM_ADDRESS
Object state name for memory address.
Definition Operand.hh:86
static const std::string OPRND_OUT
Object state name for output operand.
Definition Operand.hh:96
int addressUnits_
size of the data this operation addresses. 0 if unknown.
Definition Operand.hh:153
static const std::string OPRND_ELEM_COUNT
Object state name for element count.
Definition Operand.hh:100
static const std::string HALF_FLOAT_WORD_STRING
Definition Operand.hh:74
virtual int width() const
Definition Operand.cc:318
static const std::string BOOL_STRING
Definition Operand.hh:77
virtual ~Operand()
Definition Operand.cc:110
OperandType type_
Type of the Operand.
Definition Operand.hh:145
virtual OperandType type() const
Definition Operand.cc:165
static const std::string DOUBLE_WORD_STRING
Definition Operand.hh:76
virtual void setElementCount(int elementCount)
Definition Operand.cc:308
OperandType
Definition Operand.hh:58
@ SLONG_WORD
Definition Operand.hh:66
@ FLOAT_WORD
Definition Operand.hh:61
@ ULONG_WORD
Definition Operand.hh:67
@ RAW_DATA
Definition Operand.hh:65
@ SINT_WORD
Definition Operand.hh:59
@ DOUBLE_WORD
Definition Operand.hh:62
@ UINT_WORD
Definition Operand.hh:60
@ HALF_FLOAT_WORD
Definition Operand.hh:63
virtual bool canSwap(const Operand &op) const
Definition Operand.cc:372
virtual TCEString CTypeString() const
Definition Operand.cc:222
static const std::string UNKNOWN_TYPE_STRING
Definition Operand.hh:79
virtual ObjectState * saveState() const
Definition Operand.cc:490
virtual bool isNull() const
Definition Operand.hh:130
static const std::string ULONG_WORD_STRING
Definition Operand.hh:71
int elementWidth_
Width of an element.
Definition Operand.hh:147
static const std::string OPRND_MEM_DATA
Object state name for memory data.
Definition Operand.hh:90
static const std::string OPRND_ID
Object state name for operand id.
Definition Operand.hh:82
static const std::string UINT_WORD_STRING
Definition Operand.hh:73
static const std::string RAW_DATA_STRING
Definition Operand.hh:78
static const std::string SINT_WORD_STRING
Definition Operand.hh:72
bool isMemoryData_
Flag indicating whether Operand is memory data or not.
Definition Operand.hh:155
virtual void loadState(const ObjectState *state)
Definition Operand.cc:383
std::set< int > swap_
Indexes of Operands which can be swapped with this Operand.
Definition Operand.hh:157
virtual int elementWidth() const
Definition Operand.cc:278
int elementCount_
Number of total elements.
Definition Operand.hh:149