OpenASIP  2.0
GuardState.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 GuardState.cc
26  *
27  * Definition of GuardState class.
28  *
29  * @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "Application.hh"
34 #include "GuardState.hh"
35 #include "SimValue.hh"
36 
37 using std::vector;
38 using std::string;
39 
40 //////////////////////////////////////////////////////////////////////////////
41 // GuardState
42 //////////////////////////////////////////////////////////////////////////////
43 
44 /**
45  * Constructor.
46  *
47  * @param targetRegister The target register this guard watches.
48  * @param latency The total guard latency modeled.
49  */
51  const ReadableState& targetRegister,
52  int latency) :
53  target_(&targetRegister) {
54  assert(latency && "Use DirectGuardState for 0-cycle latency");
55  for (int i = 0; i < latency; ++i) {
56  history_.push_back(targetRegister.value());
57  }
58  position_ = 0;
59 }
60 
61 /**
62  * Constructor.
63  *
64  * Creates an empty GuardState, only to be used by subclasses, i.e.,
65  * NullGuardState.
66  */
67 GuardState::GuardState() : target_(NULL), position_(-1) {
68 }
69 
70 /**
71  * Destructor.
72  */
74 }
75 
76 /**
77  * Does nothing.
78  *
79  * The guard history is updated in advanceClock().
80  */
81 void
83 }
84 
85 /**
86  * Updates the guard value history.
87  */
88 void
91  position_ = (position_ + 1);
92  if ((size_t)position_ >= history_.size())
93  position_ = 0;
94 }
95 
96 /**
97  * Returns the current value of the guard, taking the latency in account.
98  *
99  * @return The current value of the guard.
100  */
101 const SimValue&
103  return history_[position_];
104 }
105 
106 //////////////////////////////////////////////////////////////////////////////
107 // NullGuardState
108 //////////////////////////////////////////////////////////////////////////////
109 
111 
112 /**
113  * Returns the instance of NullGuardState.
114  *
115  * @return Instance of NullGuardState.
116  */
119  return instance_;
120 }
121 
122 /**
123  * Constructor.
124  */
126 }
127 
128 /**
129  * Destructor.
130  */
132 }
133 
134 //////////////////////////////////////////////////////////////////////////////
135 // DirectGuardState
136 //////////////////////////////////////////////////////////////////////////////
137 /**
138  * Constructor.
139  *
140  * @param targetRegister The targer register this guard watches.
141  */
143  target_(&targetRegister) {
144 }
145 
146 /**
147  * Destructor.
148  */
150 }
151 
152 
153 /**
154  * Does nothing.
155  */
156 void
158 }
159 
160 /**
161  * Does nothing.
162  */
163 void
165 }
166 
167 /**
168  * Returns the current value of the guard.
169  *
170  * @return The current value of the guard.
171  */
172 const SimValue&
174  return target_->value();
175 }
176 
NullGuardState::NullGuardState
NullGuardState()
Definition: GuardState.cc:125
GuardState::history_
std::vector< SimValue > history_
Value history ring buffer.
Definition: GuardState.hh:86
GuardState::~GuardState
virtual ~GuardState()
Definition: GuardState.cc:73
DirectGuardState::endClock
virtual void endClock()
Definition: GuardState.cc:157
DirectGuardState::advanceClock
virtual void advanceClock()
Definition: GuardState.cc:164
ReadableState
Definition: ReadableState.hh:41
GuardState.hh
GuardState::position_
int position_
History ring buffer position. Point to the index of the current value of the guard.
Definition: GuardState.hh:89
NullGuardState::instance_
static NullGuardState instance_
Unique instance of NullGuardState (singleton).
Definition: GuardState.hh:113
SimValue
Definition: SimValue.hh:96
NullGuardState::~NullGuardState
virtual ~NullGuardState()
Definition: GuardState.cc:131
assert
#define assert(condition)
Definition: Application.hh:86
NullGuardState
Definition: GuardState.hh:99
NullGuardState::instance
static NullGuardState & instance()
Definition: GuardState.cc:118
DirectGuardState::target_
const ReadableState * target_
The target register watched by this guard.
Definition: GuardState.hh:142
GuardState::GuardState
GuardState()
Only subclasses allowed to create empty GuardStates.
Definition: GuardState.cc:67
Application.hh
GuardState::advanceClock
virtual void advanceClock()
Definition: GuardState.cc:89
DirectGuardState::value
virtual const SimValue & value() const
Definition: GuardState.cc:173
SimValue.hh
DirectGuardState::~DirectGuardState
virtual ~DirectGuardState()
Definition: GuardState.cc:149
GuardState::value
virtual const SimValue & value() const
Definition: GuardState.cc:102
ReadableState::value
virtual const SimValue & value() const =0
GuardState::target_
const ReadableState * target_
The target register watched by this guard.
Definition: GuardState.hh:84
GuardState::endClock
virtual void endClock()
Definition: GuardState.cc:82
DirectGuardState::DirectGuardState
DirectGuardState()