OpenASIP  2.0
Operation.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 Operation.hh
26  *
27  * Declaration of Operation 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 This file is used in compiled simulation. Keep dependencies *clean*
32  * @note rating: yellow
33  * @note reviewed 17 August 2004 by jn, ll, tr, pj
34  */
35 
36 #ifndef TTA_OPERATION_HH
37 #define TTA_OPERATION_HH
38 
39 #include <map>
40 #include <vector>
41 
42 #include "Serializable.hh"
43 #include "SimValue.hh"
44 #include "OperationBehavior.hh"
45 
46 class OperationContext;
47 class OperationBehavior;
48 class OperationDAG;
49 class TCEString;
50 class OperationPimpl;
51 class Operand;
52 class RandomNumberGenerator;
53 class SeedType;
54 
55 /**
56  * Class that models the static properties and the behavior of operations
57  * of the target processor.
58  */
59 class Operation : public Serializable {
60 public:
61 
63 
64  /// Object state name for operation.
65  static const char* OPRN_OPERATION;
66  /// Object state name for name.
67  static const char* OPRN_NAME;
68  /// Object state name for description.
69  static const char* OPRN_DESCRIPTION;
70  /// Object state name for inputs.
71  static const char* OPRN_INPUTS;
72  /// Object state name for outputs.
73  static const char* OPRN_OUTPUTS;
74  /// Object state name for trap.
75  static const char* OPRN_TRAP;
76  /// Object state name for side effects.
77  static const char* OPRN_SIDE_EFFECTS;
78  /// Object state name for clockedness
79  static const char* OPRN_CLOCKED;
80  /// Object state name for control flow property.
81  static const char* OPRN_CONTROL_FLOW;
82  /// Object state name for reads memory.
83  static const char* OPRN_READS_MEMORY;
84  /// Object state name for writes memory.
85  static const char* OPRN_WRITES_MEMORY;
86  /// Object state name for affects.
87  static const char* OPRN_AFFECTS;
88  /// Object state name for affected by.
89  static const char* OPRN_AFFECTED_BY;
90  /// Object state name for input operand.
91  static const char* OPRN_IN;
92  /// Object state name for output operand.
93  static const char* OPRN_OUT;
94  /// Object state name for trigger semantics.
95  static const char* OPRN_TRIGGER;
96  /// Object state name for call property.
97  static const char* OPRN_ISCALL;
98  /// Object state name for branch property.
99  static const char* OPRN_ISBRANCH;
100 
102  virtual ~Operation();
103 
104  virtual TCEString name() const;
105  virtual TCEString description() const;
106 
107  virtual void addDag(const TCEString& code);
108  virtual void removeDag(int index);
109  virtual int dagCount() const;
110  virtual OperationDAG& dag(int index) const;
111  virtual TCEString dagCode(int index) const;
112  virtual void setDagCode(int index, const TCEString& code);
113  virtual TCEString dagError(int index) const;
114 
115  virtual int numberOfInputs() const;
116  virtual int numberOfOutputs() const;
117  virtual int operandCount() const;
118  virtual bool isVectorOperation() const;
119  virtual bool usesMemory() const;
120  virtual bool readsMemory() const;
121  virtual bool writesMemory() const;
122  virtual bool canTrap() const;
123  virtual bool hasSideEffects() const;
124  virtual bool isClocked() const;
125  virtual bool isControlFlowOperation() const;
126  virtual bool dependsOn(const Operation& op) const;
127  virtual void setReadsMemory(bool setting);
128  virtual void setWritesMemory(bool setting);
129  virtual int affectsCount() const;
130  virtual int affectedByCount() const;
131  virtual TCEString affects(unsigned int i) const;
132  virtual TCEString affectedBy(unsigned int i) const;
133  virtual bool canSwap(int id1, int id2) const;
134  virtual bool isCall() const;
135  virtual bool isBranch() const;
136  virtual bool isBaseOffsetMemOperation() const;
137  virtual void setCall(bool setting);
138  virtual void setBranch(bool setting);
139  virtual void setControlFlowOperation(bool setting);
140  virtual bool isPure() const;
141 
142  virtual Operand& input(int index) const;
143  virtual void addInput(Operand* operand);
144  virtual Operand& output(int index) const;
145  virtual void addOutput(Operand* operand);
146  virtual Operand& operand(int id) const;
147 
148  virtual void setBehavior(OperationBehavior& behavior);
149  virtual OperationBehavior& behavior() const;
150 
151  virtual void loadState(const ObjectState* state);
152  virtual ObjectState* saveState() const;
153 
154  virtual bool simulateTrigger(
155  SimValue**,
156  OperationContext& context) const;
157  virtual bool areValid(
158  const InputOperandVector& inputs,
159  const OperationContext& context) const;
160 
161  virtual void createState(OperationContext& context) const;
162  virtual void deleteState(OperationContext& context) const;
163 
164  virtual bool canBeSimulated() const;
165 
166  bool isNull() const;
167 
169 
170  OperationPimpl& impl() { return *pimpl_; }
171 private:
172  /// Private implementation in a separate source file.
174 };
175 
176 //////////////////////////////////////////////////////////////////////////////
177 // NullOperation
178 //////////////////////////////////////////////////////////////////////////////
179 
180 /**
181  * Singleton class that is used to represent a null operation behavior.
182  *
183  * All methods cause program abort with an error log message.
184  *
185  */
186 class NullOperation : public Operation {
187 public:
188 
189  virtual ~NullOperation();
190 
191  static NullOperation& instance();
192 
193  virtual TCEString name() const;
194  virtual TCEString description() const;
195  virtual int numberOfInputs() const;
196  virtual int numberOfOutputs() const;
197  virtual bool usesMemory() const;
198  virtual bool readsMemory() const;
199  virtual bool writesMemory() const;
200  virtual bool canTrap() const;
201  virtual bool hasSideEffects() const;
202  virtual bool isClocked() const;
203  virtual bool isControlFlowOperation() const;
204  virtual bool isCall() const;
205  virtual bool isBranch() const;
206  virtual bool dependsOn(const Operation& op) const;
207  virtual int affectsCount() const;
208  virtual int affectedByCount() const;
209  virtual TCEString affects(unsigned int i) const;
210  virtual TCEString affectedBy(unsigned int i) const;
211  virtual bool canSwap(int id1, int id2) const;
212 
213  virtual Operand& input(int id) const;
214  virtual Operand& output(int id) const;
215  virtual Operand& operand(int id) const;
216 
217  virtual void setBehavior(OperationBehavior& behavior);
218  virtual OperationBehavior& behavior() const;
219 
220  virtual bool simulateTrigger(
221  SimValue**,
222  OperationContext& context) const;
223 
224  virtual void createState(OperationContext& context) const;
225  virtual void deleteState(OperationContext& context) const;
226 
227 protected:
228  /// Some gcc versions warn about private constructors.
229  NullOperation();
230 private:
231  /// Copying not allowed.
233  /// Assignment not allowed.
235 
236  /// Unique instance of NullOperation.
238 };
239 
240 #include "Operation.icc"
241 
242 #endif
Operand
Definition: Operand.hh:52
NullOperation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:812
NullOperation::operand
virtual Operand & operand(int id) const
Definition: Operation.cc:760
Operation::affects
virtual TCEString affects(unsigned int i) const
Definition: Operation.cc:431
Operation::affectedByCount
virtual int affectedByCount() const
Definition: Operation.cc:416
NullOperation
Definition: Operation.hh:186
Operation::writesMemory
virtual bool writesMemory() const
Definition: Operation.cc:252
Operation::setReadsMemory
virtual void setReadsMemory(bool setting)
Definition: Operation.cc:631
Operation::isPure
virtual bool isPure() const
Definition: Operation.cc:346
Operation::removeDag
virtual void removeDag(int index)
Definition: Operation.cc:123
Operation::hasSideEffects
virtual bool hasSideEffects() const
Definition: Operation.cc:272
NullOperation::description
virtual TCEString description() const
Definition: Operation.cc:801
Operation::output
virtual Operand & output(int index) const
Definition: Operation.cc:526
OperationPimpl
Definition: OperationPimpl.hh:54
NullOperation::behavior
virtual OperationBehavior & behavior() const
Definition: Operation.cc:771
Operation::addOutput
virtual void addOutput(Operand *operand)
Definition: Operation.cc:513
Operation::dagError
virtual TCEString dagError(int index) const
Definition: Operation.cc:182
Operation::OPRN_IN
static const char * OPRN_IN
Object state name for input operand.
Definition: Operation.hh:91
OperationContext
Definition: OperationContext.hh:56
Serializable
Definition: Serializable.hh:44
Operation::Operation
Operation(const TCEString &name, OperationBehavior &behavior)
Definition: Operation.cc:73
Operation::~Operation
virtual ~Operation()
Definition: Operation.cc:82
NullOperation::instance_
static NullOperation instance_
Unique instance of NullOperation.
Definition: Operation.hh:237
Operation::dependsOn
virtual bool dependsOn(const Operation &op) const
Definition: Operation.cc:458
Operation::OPRN_NAME
static const char * OPRN_NAME
Object state name for name.
Definition: Operation.hh:67
NullOperation::NullOperation
NullOperation()
Some gcc versions warn about private constructors.
Definition: Operation.cc:652
Operation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:192
Operation::affectedBy
virtual TCEString affectedBy(unsigned int i) const
Definition: Operation.cc:447
ObjectState
Definition: ObjectState.hh:59
Operation::isClocked
virtual bool isClocked() const
Definition: Operation.cc:282
Operation::OPRN_AFFECTS
static const char * OPRN_AFFECTS
Object state name for affects.
Definition: Operation.hh:87
Operation::canBeSimulated
virtual bool canBeSimulated() const
Definition: Operation.cc:612
NullOperation::operator=
NullOperation & operator=(const NullOperation &)
Assignment not allowed.
NullOperation::affectsCount
virtual int affectsCount() const
Definition: Operation.cc:679
NullOperation::instance
static NullOperation & instance()
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
Operation::OPRN_AFFECTED_BY
static const char * OPRN_AFFECTED_BY
Object state name for affected by.
Definition: Operation.hh:89
NullOperation::name
virtual TCEString name() const
Definition: Operation.cc:790
Operation::pimpl_
OperationPimpl * pimpl_
Private implementation in a separate source file.
Definition: Operation.hh:173
Operation::dagCode
virtual TCEString dagCode(int index) const
Definition: Operation.cc:159
SimValue
Definition: SimValue.hh:96
Operation::canSwap
virtual bool canSwap(int id1, int id2) const
Definition: Operation.cc:470
NullOperation::canSwap
virtual bool canSwap(int id1, int id2) const
Definition: Operation.cc:727
Operation::OPRN_CONTROL_FLOW
static const char * OPRN_CONTROL_FLOW
Object state name for control flow property.
Definition: Operation.hh:81
Operation::setCall
virtual void setCall(bool setting)
Definition: Operation.cc:359
Operation::setBehavior
virtual void setBehavior(OperationBehavior &behavior)
Definition: Operation.cc:378
Operation::OPRN_DESCRIPTION
static const char * OPRN_DESCRIPTION
Object state name for description.
Definition: Operation.hh:69
Operation::OPRN_TRAP
static const char * OPRN_TRAP
Object state name for trap.
Definition: Operation.hh:75
Operation::OPRN_TRIGGER
static const char * OPRN_TRIGGER
Object state name for trigger semantics.
Definition: Operation.hh:95
Operation::areValid
virtual bool areValid(const InputOperandVector &inputs, const OperationContext &context) const
Definition: Operation.cc:574
NullOperation::input
virtual Operand & input(int id) const
Definition: Operation.cc:738
Operation::setControlFlowOperation
virtual void setControlFlowOperation(bool setting)
Definition: Operation.cc:335
Operation::emulationFunctionName
TCEString emulationFunctionName() const
Definition: Operation.cc:623
OperationDAG
Definition: OperationDAG.hh:43
NullOperation::isControlFlowOperation
virtual bool isControlFlowOperation() const
Definition: Operation.cc:900
Operation::OPRN_OPERATION
static const char * OPRN_OPERATION
Object state name for operation.
Definition: Operation.hh:65
NullOperation::setBehavior
virtual void setBehavior(OperationBehavior &behavior)
Definition: Operation.cc:780
Operation::OPRN_CLOCKED
static const char * OPRN_CLOCKED
Object state name for clockedness.
Definition: Operation.hh:79
Operation::OPRN_ISCALL
static const char * OPRN_ISCALL
Object state name for call property.
Definition: Operation.hh:97
Operation::loadState
virtual void loadState(const ObjectState *state)
Definition: Operation.cc:480
Operation::addDag
virtual void addDag(const TCEString &code)
Definition: Operation.cc:113
NullOperation::deleteState
virtual void deleteState(OperationContext &context) const
Definition: Operation.cc:952
Operation::OPRN_WRITES_MEMORY
static const char * OPRN_WRITES_MEMORY
Object state name for writes memory.
Definition: Operation.hh:85
Operation::readsMemory
virtual bool readsMemory() const
Definition: Operation.cc:242
Operation::isBaseOffsetMemOperation
virtual bool isBaseOffsetMemOperation() const
Definition: Operation.cc:323
Operation::canTrap
virtual bool canTrap() const
Definition: Operation.cc:262
Operation::saveState
virtual ObjectState * saveState() const
Definition: Operation.cc:490
Operation::OPRN_READS_MEMORY
static const char * OPRN_READS_MEMORY
Object state name for reads memory.
Definition: Operation.hh:83
NullOperation::output
virtual Operand & output(int id) const
Definition: Operation.cc:749
Operation::isVectorOperation
virtual bool isVectorOperation() const
Definition: Operation.cc:222
Operation::impl
OperationPimpl & impl()
Definition: Operation.hh:170
NullOperation::usesMemory
virtual bool usesMemory() const
Definition: Operation.cc:834
Operation::deleteState
virtual void deleteState(OperationContext &context) const
Definition: Operation.cc:601
Operation
Definition: Operation.hh:59
Operation::OPRN_OUT
static const char * OPRN_OUT
Object state name for output operand.
Definition: Operation.hh:93
Operation::operandCount
virtual int operandCount() const
Definition: Operation.cc:212
Operation::OPRN_INPUTS
static const char * OPRN_INPUTS
Object state name for inputs.
Definition: Operation.hh:71
Operation::description
virtual TCEString description() const
Definition: Operation.cc:103
Serializable.hh
Operation::input
virtual Operand & input(int index) const
Definition: Operation.cc:503
Operation::OPRN_SIDE_EFFECTS
static const char * OPRN_SIDE_EFFECTS
Object state name for side effects.
Definition: Operation.hh:77
NullOperation::createState
virtual void createState(OperationContext &context) const
Definition: Operation.cc:944
Operation::usesMemory
virtual bool usesMemory() const
Definition: Operation.cc:232
Operation::operand
virtual Operand & operand(int id) const
Definition: Operation.cc:541
OperationBehavior::InputOperandVector
std::vector< SimValue > InputOperandVector
Input operand type for areValid()
Definition: OperationBehavior.hh:57
Operation::createState
virtual void createState(OperationContext &context) const
Definition: Operation.cc:590
Operation::dagCount
virtual int dagCount() const
Definition: Operation.cc:134
Operation.icc
OperationBehavior.hh
OperationBehavior
Definition: OperationBehavior.hh:53
Operation::InputOperandVector
OperationBehavior::InputOperandVector InputOperandVector
Definition: Operation.hh:62
NullOperation::isClocked
virtual bool isClocked() const
Definition: Operation.cc:889
Operation::isNull
bool isNull() const
Operation::addInput
virtual void addInput(Operand *operand)
Definition: Operation.cc:508
SimValue.hh
TCEString
Definition: TCEString.hh:53
NullOperation::writesMemory
virtual bool writesMemory() const
Definition: Operation.cc:856
Operation::setDagCode
virtual void setDagCode(int index, const TCEString &code)
Definition: Operation.cc:171
NullOperation::canTrap
virtual bool canTrap() const
Definition: Operation.cc:867
NullOperation::hasSideEffects
virtual bool hasSideEffects() const
Definition: Operation.cc:878
Operation::simulateTrigger
virtual bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: Operation.cc:555
Operation::behavior
virtual OperationBehavior & behavior() const
Definition: Operation.cc:388
NullOperation::readsMemory
virtual bool readsMemory() const
Definition: Operation.cc:845
Operation::setWritesMemory
virtual void setWritesMemory(bool setting)
Definition: Operation.cc:639
Operation::isCall
virtual bool isCall() const
Definition: Operation.cc:318
NullOperation::~NullOperation
virtual ~NullOperation()
Definition: Operation.cc:659
NullOperation::isCall
virtual bool isCall() const
Definition: Operation.cc:910
NullOperation::affectedByCount
virtual int affectedByCount() const
Definition: Operation.cc:690
NullOperation::affectedBy
virtual TCEString affectedBy(unsigned int i) const
Definition: Operation.cc:715
NullOperation::isBranch
virtual bool isBranch() const
Definition: Operation.cc:920
NullOperation::dependsOn
virtual bool dependsOn(const Operation &op) const
Definition: Operation.cc:668
Operation::numberOfOutputs
virtual int numberOfOutputs() const
Definition: Operation.cc:202
Operation::OPRN_ISBRANCH
static const char * OPRN_ISBRANCH
Object state name for branch property.
Definition: Operation.hh:99
Operation::OPRN_OUTPUTS
static const char * OPRN_OUTPUTS
Object state name for outputs.
Definition: Operation.hh:73
Operation::affectsCount
virtual int affectsCount() const
Definition: Operation.cc:402
Operation::isBranch
virtual bool isBranch() const
Definition: Operation.cc:306
Operation::setBranch
virtual void setBranch(bool setting)
Definition: Operation.cc:368
Operation::dag
virtual OperationDAG & dag(int index) const
Definition: Operation.cc:148
NullOperation::numberOfOutputs
virtual int numberOfOutputs() const
Definition: Operation.cc:823
NullOperation::affects
virtual TCEString affects(unsigned int i) const
Definition: Operation.cc:702
NullOperation::simulateTrigger
virtual bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: Operation.cc:932
Operation::isControlFlowOperation
virtual bool isControlFlowOperation() const
Definition: Operation.cc:294