OpenASIP 2.2
Loading...
Searching...
No Matches
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
37using std::vector;
38using 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 */
67GuardState::GuardState() : target_(NULL), position_(-1) {
68}
69
70/**
71 * Destructor.
72 */
75
76/**
77 * Does nothing.
78 *
79 * The guard history is updated in advanceClock().
80 */
81void
84
85/**
86 * Updates the guard value history.
87 */
88void
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 */
101const 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 */
121
122/**
123 * Constructor.
124 */
127
128/**
129 * Destructor.
130 */
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 */
151
152
153/**
154 * Does nothing.
155 */
156void
159
160/**
161 * Does nothing.
162 */
163void
166
167/**
168 * Returns the current value of the guard.
169 *
170 * @return The current value of the guard.
171 */
172const SimValue&
174 return target_->value();
175}
176
#define assert(condition)
virtual void endClock()
virtual void advanceClock()
const ReadableState * target_
The target register watched by this guard.
virtual const SimValue & value() const
virtual ~DirectGuardState()
std::vector< SimValue > history_
Value history ring buffer.
Definition GuardState.hh:86
const ReadableState * target_
The target register watched by this guard.
Definition GuardState.hh:84
virtual const SimValue & value() const
virtual void endClock()
Definition GuardState.cc:82
virtual void advanceClock()
Definition GuardState.cc:89
GuardState()
Only subclasses allowed to create empty GuardStates.
Definition GuardState.cc:67
virtual ~GuardState()
Definition GuardState.cc:73
int position_
History ring buffer position. Point to the index of the current value of the guard.
Definition GuardState.hh:89
static NullGuardState instance_
Unique instance of NullGuardState (singleton).
static NullGuardState & instance()
virtual ~NullGuardState()
virtual const SimValue & value() const =0