OpenASIP  2.0
OperationBehavior.cc
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 OperationBehavior.cc
26  *
27  * Implementations of OperationBehavior class.
28  *
29  * @author Pekka Jääskeläinen 2004 (pekka.jaaskelainen-no.spam-tut.fi)
30  * @note rating: red
31  * @note reviewed 19 August 2004 by pj, jn, ao, ac
32  */
33 
34 #include <string>
35 
36 #include "OperationBehavior.hh"
37 #include "Application.hh"
38 #include "Exception.hh"
39 #include "OperationState.hh"
40 #include "OperationContext.hh"
41 #include "OperationPool.hh"
42 #include "OperationGlobals.hh"
43 #include "Operation.hh"
44 #include "Operand.hh"
45 
46 using std::string;
47 
48 
49 /**
50  * Constructor with NULL parent.
51  */
53  : parent_(NullOperation::instance()){
54 }
55 
56 /**
57  * Constructor with parent.
58  */
60  : parent_(parent) {
61 }
62 
63 /**
64  * Destructor.
65  */
67 }
68 
69 /**
70  * Simulates the process of starting the execution of an operation.
71  *
72  * Clients should invoke isTriggerLocking() before any attempt to call
73  * simulateTrigger() in current clock cycle. By default, an operation
74  * invocations are successful.
75  *
76  *
77  * @param io The input operands and the results of the operation.
78  * @param context The operation context affecting the operation results.
79  * @return bool True if all values could be computed, false otherwise.
80  * @exception Exception Depends on the implementation.
81  */
82 bool
84  SimValue**,
85  OperationContext&) const {
86  return true;
87 }
88 
89 /**
90  * The default implementation of input operand validation.
91  *
92  * This always return true. This is meant to be overridden in derived classes
93  * when necessary.
94  */
95 bool
97  const InputOperandVector& /*inputs*/,
98  const OperationContext& /*context*/) const {
99 
100  return true;
101 }
102 
103 
104 /**
105  * Writes text to the output stream specified
106  *
107  * @param text text to be written to the output stream
108  */
109 void
111  const char* text) const {
113 }
114 
115 
116 /**
117  * Creates the instance of operation state for this operation and adds it to
118  * its operation context.
119  *
120  * By default this function does nothing (assumes that the operation has no
121  * state). If the operation context already contains the required operation
122  * state instance, nothing is done.
123  *
124  * @param context The operation context to add the state to.
125  */
126 void
128 }
129 
130 /**
131  * Deletes the instance of operation state for this operation from its
132  * operation context.
133  *
134  * By default this function does nothing (assumes that the operation has no
135  * state). If the operation context does not contain the required operation
136  * state instance, nothing is done.
137  *
138  * @param context The operation context to delete the state from.
139  */
140 void
142 }
143 
144 /**
145  * Returns the name of the state of this operation behavior.
146  *
147  * By default returns an empty string which denotes that there is no state.
148  *
149  * @return The state name for this operation behavior.
150  */
151 const char*
153  return "";
154 }
155 
156 /**
157  * If behavior can be simulated.
158  *
159  * @return true If simulation of behavior is possible.
160  */
161 bool
163  return true;
164 }
165 
166 ///////////////////////////////////////////////////////////////////////////////
167 // NullOperationBehavior
168 ///////////////////////////////////////////////////////////////////////////////
169 
171 const char* ERROR_MESSAGE =
172  "Attempted to use a NULL OperationBehavior object.";
173 
174 /**
175  * Writes an error message to error log and aborts the program.
176  *
177  * @param io Not used.
178  * @param context Not used.
179  * @return Never returns.
180  */
181 bool
183  SimValue**,
184  OperationContext&) const {
185 
187  return true;
188 }
189 
190 /**
191  * Writes an error message to error log and aborts the program.
192  *
193  * @param io Not used.
194  * @param context Not used.
195  * @return Never returns.
196  */
197 bool
199  SimValue**,
200  OperationContext&) const {
201 
203  return true;
204 }
205 
OperationBehavior::writeOutput
virtual void writeOutput(const char *text) const
Definition: OperationBehavior.cc:110
NullOperation
Definition: Operation.hh:186
OperationBehavior::~OperationBehavior
virtual ~OperationBehavior()
Definition: OperationBehavior.cc:66
OperationBehavior::canBeSimulated
virtual bool canBeSimulated() const
Definition: OperationBehavior.cc:162
NullOperationBehavior::lateResult
virtual bool lateResult(SimValue **, OperationContext &context) const
Definition: OperationBehavior.cc:198
NullOperationBehavior::instance_
static NullOperationBehavior instance_
Definition: OperationBehavior.hh:108
Exception.hh
OperationContext
Definition: OperationContext.hh:56
OperationBehavior::areValid
virtual bool areValid(const InputOperandVector &inputs, const OperationContext &context) const
Definition: OperationBehavior.cc:96
OperationState.hh
OperationBehavior::createState
virtual void createState(OperationContext &context) const
Definition: OperationBehavior.cc:127
SimValue
Definition: SimValue.hh:96
OperationBehavior::simulateTrigger
virtual bool simulateTrigger(SimValue **io, OperationContext &context) const =0
Definition: OperationBehavior.cc:83
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
OperationBehavior::OperationBehavior
OperationBehavior()
Definition: OperationBehavior.cc:52
Application.hh
Operation.hh
NullOperationBehavior::simulateTrigger
virtual bool simulateTrigger(SimValue **, OperationContext &context) const
Definition: OperationBehavior.cc:182
OperationBehavior::stateName
virtual const char * stateName() const
Definition: OperationBehavior.cc:152
Operation
Definition: Operation.hh:59
Operand.hh
NullOperationBehavior
Definition: OperationBehavior.hh:93
OperationBehavior::InputOperandVector
std::vector< SimValue > InputOperandVector
Input operand type for areValid()
Definition: OperationBehavior.hh:57
OperationBehavior.hh
OperationBehavior::deleteState
virtual void deleteState(OperationContext &context) const
Definition: OperationBehavior.cc:141
ERROR_MESSAGE
const char * ERROR_MESSAGE
Definition: OperationBehavior.cc:171
OperationGlobals::outputStream
static std::ostream & outputStream()
Definition: OperationGlobals.cc:49
OperationPool.hh
OperationContext.hh
OperationGlobals.hh