OpenASIP  2.0
OperationPimpl.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 OperationPimpl.hh
26  *
27  * Declaration of OperationPimpl (private implementation) class.
28  *
29  * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef OPERATION_PIMPL_HH
34 #define OPERATION_PIMPL_HH
35 
36 #include <string>
37 #include <set>
38 #include <vector>
39 #include <map>
40 
41 #include "TCEString.hh"
42 
43 class Operation;
44 class OperationDAG;
45 class OperationBehavior;
46 class Operand;
47 class ObjectState;
48 class SimValue;
49 class OperationContext;
50 
51 /**
52  * A private implementation class for Operation
53  */
55 public:
56  friend class Operation;
58 
59  inline int numberOfInputs() const;
60  inline int numberOfOutputs() const;
61  TCEString name() const;
62  void setCall(bool setting);
63  void setBranch(bool setting);
64  void setControlFlowOperation(bool setting);
65 
66  Operand& operand(int id) const;
67 private:
69  const TCEString& name,
72 
73  /// Copying not allowed.
75  /// Assignment not allowed.
77 
78  TCEString description() const;
79 
80  void addDag(const TCEString& code);
81  void removeDag(int index);
82  int dagCount() const;
83  OperationDAG& dag(int index) const;
84  TCEString dagCode(int index) const;
85  void setDagCode(int index, const TCEString& code);
86  TCEString dagError(int index) const;
87 
88  inline bool usesMemory() const;
89  inline bool readsMemory() const;
90  inline bool writesMemory() const;
91  bool canTrap() const;
92  bool hasSideEffects() const;
93  bool isClocked() const;
94  bool isControlFlowOperation() const;
95  bool isCall() const;
96  bool isBranch() const;
97  bool dependsOn(const Operation& op) const;
98  void setReadsMemory(bool setting);
99  void setWritesMemory(bool setting);
100  int affectsCount() const;
101  int affectedByCount() const;
102  TCEString affects(unsigned int i) const;
103  TCEString affectedBy(unsigned int i) const;
104  bool canSwap(int id1, int id2) const;
105 
106  inline Operand& input(int index) const;
107  void addInput(Operand* operand);
108  Operand& output(int index) const;
109  void addOutput(Operand* operand);
110 
112  OperationBehavior& behavior() const;
113 
114  void loadState(const ObjectState* state);
115  ObjectState* saveState() const;
116 
117  bool simulateTrigger(
118  SimValue**,
119  OperationContext& context) const;
120 
121  void createState(OperationContext& context) const;
122  void deleteState(OperationContext& context) const;
123 
124  bool canBeSimulated() const;
125 
126  bool isNull() const;
127 
129 
130  /**
131  * Internal container for information of one DAG.
132  */
134  /// Source code for creating DAG for operation.
135  std::string code;
136  /// Error message if creating DAG failed.
137  std::string error;
138  /// If code was already tried to compile and it did not succeed.
140  /// DAG presentation of code. set to
141  /// NullOperationDAG if could not be created.
143 
144  };
145 
146  typedef std::vector<OperationDAGInfo> DAGContainer;
147 
148  void clear();
149 
150  Operand& fetchOperand(int id, const std::vector<Operand*>& ops) const;
151  Operand& fetchOperand(int id) const;
152  void insertOperand(Operand* operand, std::vector<Operand*>& ops);
153 
154  /// The behavior of the Operation.
156  /// Name of the Operation.
157  std::string name_;
158  /// Description of the Operation.
159  std::string description_;
160  /// Table of DAGs and their source codes of an operation.
162 
163  /// The number of inputs of the Operation.
164  int inputs_;
165  /// The number of outputs of the Operation.
166  int outputs_;
167  /// Flag indicating if Operation reads from memory.
169  /// Flag indicating if Operation writes to memory.
171  /// Flag indicating if Operation can trap.
172  bool canTrap_;
173  /// Flag indicating if Operation has side effects.
175  /// Flag indicating if Operation is clocked and needs AdvanceClock.
177  /// Flag indicating if the Operation can change program flow.
179  /// Operations that affects this Operation.
180  std::set<std::string> affects_;
181  /// Operations that are affected by this Operation.
182  std::set<std::string> affectedBy_;
183  /// Input Operands of the Operation.
184  std::vector<Operand*> inputOperands_;
185  /// Output Operands of the Operation.
186  std::vector<Operand*> outputOperands_;
187  /// Flag indicating if Operation is call.
188  bool isCall_;
189  /// Flag indicating if Operation is branch changing control flow.
190  bool isBranch_;
191 
192 };
193 
194 #include "OperationPimpl.icc"
195 
196 #endif
197 
Operand
Definition: Operand.hh:52
OperationPimpl::~OperationPimpl
~OperationPimpl()
Definition: OperationPimpl.cc:80
OperationPimpl::writesMemory
bool writesMemory() const
OperationPimpl.icc
OperationPimpl::affects_
std::set< std::string > affects_
Operations that affects this Operation.
Definition: OperationPimpl.hh:180
OperationPimpl::hasSideEffects
bool hasSideEffects() const
Definition: OperationPimpl.cc:268
OperationPimpl::setBranch
void setBranch(bool setting)
Definition: OperationPimpl.cc:861
OperationPimpl::name
TCEString name() const
Definition: OperationPimpl.cc:121
OperationPimpl::dagError
TCEString dagError(int index) const
Definition: OperationPimpl.cc:248
OperationPimpl::affectedByCount
int affectedByCount() const
Definition: OperationPimpl.cc:353
OperationPimpl::loadState
void loadState(const ObjectState *state)
Definition: OperationPimpl.cc:453
OperationPimpl::DAGContainer
std::vector< OperationDAGInfo > DAGContainer
Definition: OperationPimpl.hh:146
OperationPimpl::clear
void clear()
Definition: OperationPimpl.cc:88
OperationPimpl::isNull
bool isNull() const
OperationPimpl
Definition: OperationPimpl.hh:54
OperationPimpl::OperationDAGInfo::error
std::string error
Error message if creating DAG failed.
Definition: OperationPimpl.hh:137
OperationPimpl::addInput
void addInput(Operand *operand)
Definition: OperationPimpl.cc:620
OperationPimpl::OperationPimpl
OperationPimpl()
OperationPimpl::OperationDAGInfo::dag
OperationDAG * dag
DAG presentation of code. set to NullOperationDAG if could not be created.
Definition: OperationPimpl.hh:142
OperationContext
Definition: OperationContext.hh:56
OperationPimpl::isCall
bool isCall() const
Definition: OperationPimpl.cc:302
OperationPimpl::isControlFlowOperation
bool isControlFlowOperation() const
Definition: OperationPimpl.cc:290
OperationPimpl::isClocked
bool isClocked() const
Definition: OperationPimpl.cc:278
OperationPimpl::canTrap
bool canTrap() const
Definition: OperationPimpl.cc:258
OperationPimpl::setCall
void setCall(bool setting)
Definition: OperationPimpl.cc:852
OperationPimpl::inputs_
int inputs_
The number of inputs of the Operation.
Definition: OperationPimpl.hh:164
ObjectState
Definition: ObjectState.hh:59
OperationPimpl::addOutput
void addOutput(Operand *operand)
Definition: OperationPimpl.cc:626
OperationPimpl::affectedBy_
std::set< std::string > affectedBy_
Operations that are affected by this Operation.
Definition: OperationPimpl.hh:182
OperationPimpl::emulationFunctionName
TCEString emulationFunctionName() const
Definition: OperationPimpl.cc:819
OperationPimpl::canTrap_
bool canTrap_
Flag indicating if Operation can trap.
Definition: OperationPimpl.hh:172
SimValue
Definition: SimValue.hh:96
OperationPimpl::outputs_
int outputs_
The number of outputs of the Operation.
Definition: OperationPimpl.hh:166
OperationPimpl::name_
std::string name_
Name of the Operation.
Definition: OperationPimpl.hh:157
OperationPimpl::dagCode
TCEString dagCode(int index) const
Definition: OperationPimpl.cc:220
TCEString.hh
OperationPimpl::dagCount
int dagCount() const
Definition: OperationPimpl.cc:172
OperationPimpl::outputOperands_
std::vector< Operand * > outputOperands_
Output Operands of the Operation.
Definition: OperationPimpl.hh:186
OperationPimpl::numberOfOutputs
int numberOfOutputs() const
OperationPimpl::OperationDAGInfo
Definition: OperationPimpl.hh:133
OperationPimpl::setControlFlowOperation
void setControlFlowOperation(bool setting)
Definition: OperationPimpl.cc:844
OperationPimpl::isClocked_
bool isClocked_
Flag indicating if Operation is clocked and needs AdvanceClock.
Definition: OperationPimpl.hh:176
OperationPimpl::saveState
ObjectState * saveState() const
Definition: OperationPimpl.cc:557
OperationPimpl::setBehavior
void setBehavior(OperationBehavior &behavior)
Definition: OperationPimpl.cc:323
OperationPimpl::output
Operand & output(int index) const
Definition: OperationPimpl.cc:640
OperationPimpl::OperationDAGInfo::code
std::string code
Source code for creating DAG for operation.
Definition: OperationPimpl.hh:135
OperationDAG
Definition: OperationDAG.hh:43
OperationPimpl::writesMemory_
bool writesMemory_
Flag indicating if Operation writes to memory.
Definition: OperationPimpl.hh:170
OperationPimpl::simulateTrigger
bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: OperationPimpl.cc:750
OperationPimpl::affects
TCEString affects(unsigned int i) const
Definition: OperationPimpl.cc:364
OperationPimpl::setReadsMemory
void setReadsMemory(bool setting)
Definition: OperationPimpl.cc:869
OperationPimpl::operator=
OperationPimpl & operator=(const OperationPimpl &)
Assignment not allowed.
OperationPimpl::operand
Operand & operand(int id) const
Definition: OperationPimpl.cc:655
OperationPimpl::createState
void createState(OperationContext &context) const
Definition: OperationPimpl.cc:764
OperationPimpl::behavior
OperationBehavior & behavior() const
Definition: OperationPimpl.cc:333
Operation
Definition: Operation.hh:59
OperationPimpl::dags_
DAGContainer dags_
Table of DAGs and their source codes of an operation.
Definition: OperationPimpl.hh:161
OperationPimpl::insertOperand
void insertOperand(Operand *operand, std::vector< Operand * > &ops)
Definition: OperationPimpl.cc:723
OperationBehavior
Definition: OperationBehavior.hh:53
TCEString
Definition: TCEString.hh:53
OperationPimpl::fetchOperand
Operand & fetchOperand(int id, const std::vector< Operand * > &ops) const
Definition: OperationPimpl.cc:674
OperationPimpl::behavior_
OperationBehavior * behavior_
The behavior of the Operation.
Definition: OperationPimpl.hh:155
OperationPimpl::readsMemory
bool readsMemory() const
OperationPimpl::removeDag
void removeDag(int index)
Definition: OperationPimpl.cc:154
OperationPimpl::isBranch_
bool isBranch_
Flag indicating if Operation is branch changing control flow.
Definition: OperationPimpl.hh:190
OperationPimpl::inputOperands_
std::vector< Operand * > inputOperands_
Input Operands of the Operation.
Definition: OperationPimpl.hh:184
OperationPimpl::dependsOn
bool dependsOn(const Operation &op) const
Definition: OperationPimpl.cc:413
OperationPimpl::dag
OperationDAG & dag(int index) const
Definition: OperationPimpl.cc:186
OperationPimpl::canSwap
bool canSwap(int id1, int id2) const
Definition: OperationPimpl.cc:435
OperationPimpl::affectedBy
TCEString affectedBy(unsigned int i) const
Definition: OperationPimpl.cc:389
OperationPimpl::OperationDAGInfo::compilationFailed
bool compilationFailed
If code was already tried to compile and it did not succeed.
Definition: OperationPimpl.hh:139
OperationPimpl::affectsCount
int affectsCount() const
Definition: OperationPimpl.cc:343
OperationPimpl::readsMemory_
bool readsMemory_
Flag indicating if Operation reads from memory.
Definition: OperationPimpl.hh:168
OperationPimpl::canBeSimulated
bool canBeSimulated() const
Definition: OperationPimpl.cc:786
OperationPimpl::description_
std::string description_
Description of the Operation.
Definition: OperationPimpl.hh:159
OperationPimpl::isBranch
bool isBranch() const
Definition: OperationPimpl.cc:313
OperationPimpl::usesMemory
bool usesMemory() const
OperationPimpl::hasSideEffects_
bool hasSideEffects_
Flag indicating if Operation has side effects.
Definition: OperationPimpl.hh:174
OperationPimpl::addDag
void addDag(const TCEString &code)
Definition: OperationPimpl.cc:140
OperationPimpl::input
Operand & input(int index) const
OperationPimpl::controlFlowOperation_
bool controlFlowOperation_
Flag indicating if the Operation can change program flow.
Definition: OperationPimpl.hh:178
OperationPimpl::description
TCEString description() const
Definition: OperationPimpl.cc:131
OperationPimpl::setWritesMemory
void setWritesMemory(bool setting)
Definition: OperationPimpl.cc:877
OperationPimpl::deleteState
void deleteState(OperationContext &context) const
Definition: OperationPimpl.cc:775
OperationPimpl::isCall_
bool isCall_
Flag indicating if Operation is call.
Definition: OperationPimpl.hh:188
OperationPimpl::setDagCode
void setDagCode(int index, const TCEString &code)
Definition: OperationPimpl.cc:232
OperationPimpl::numberOfInputs
int numberOfInputs() const