OpenASIP 2.2
Loading...
Searching...
No Matches
Guard.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 Guard.hh
26 *
27 * Declaration of Guard class and its derived classes.
28 *
29 * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30 */
31
32#ifndef TTA_GUARD_HH
33#define TTA_GUARD_HH
34
35#include "MachinePart.hh"
36
37class ObjectState;
38
39namespace TTAMachine {
40
41class FUPort;
42class Bus;
43class RegisterFile;
44
45/////////////////////////////////////////////////////////////////////////////
46// Guard
47/////////////////////////////////////////////////////////////////////////////
48
49/**
50 * Guard expression representing an execution predicate.
51 *
52 * Evaluates to true (execute) or false (don't execute). This is a
53 * base class for real Guards.
54 */
55class Guard : public SubComponent {
56public:
57 virtual ~Guard();
58
59 virtual Bus* parentBus() const;
60 virtual void setParentBus(Bus* parentBus) {
62 }
63 virtual bool isEqual(const Guard& guard) const = 0;
64 virtual bool isInverted() const;
65 virtual bool isMoreRestrictive(const Guard& guard) const;
66 virtual bool isLessRestrictive(const Guard& guard) const;
67 virtual bool isOpposite(const Guard& guard) const = 0;
68 virtual bool isDisjoint(const Guard& guard) const;
69 virtual void copyTo(Bus& parentBus) const = 0;
70
71 virtual ObjectState* saveState() const;
72 virtual void loadState(const ObjectState* state);
73
74 /// ObjectState name for guard.
75 static const std::string OSNAME_GUARD;
76 /// ObjectState attribute key for inverted feature.
77 static const std::string OSKEY_INVERTED;
78
79protected:
80 Guard(bool inverted, Bus* parentBus);
81 Guard(const ObjectState* state, Bus& parentBus);
82
83private:
84 /// Indicated whether the condition term is inverted.
86 /// The parent bus of the guard.
88};
89
90
91/////////////////////////////////////////////////////////////////////////////
92// PortGuard
93/////////////////////////////////////////////////////////////////////////////
94
95/**
96 * Guard where the condition term is taken from the value of an
97 * output port of a FunctionUnit.
98 */
99class PortGuard : public Guard {
100public:
101 PortGuard(bool inverted, FUPort& port, Bus& parentBus);
102 PortGuard(const ObjectState* state, Bus& parentBus);
103 virtual ~PortGuard();
104
105 bool isEqual(const Guard& guard) const;
106 bool isOpposite(const Guard& guard) const;
107
108 FUPort* port() const;
109 virtual void copyTo(Bus& parentBus) const {
111 }
112
113 ObjectState* saveState() const;
114 void loadState(const ObjectState* state);
115
116 /// ObjectState name for PortGuard ObjectState.
117 static const std::string OSNAME_PORT_GUARD;
118 /// ObjectState attribute key for function unit name.
119 static const std::string OSKEY_FU;
120 /// ObjectState attribute key for port name.
121 static const std::string OSKEY_PORT;
122
123private:
124 /// Port from which the condition term is taken.
126};
127
128
129/////////////////////////////////////////////////////////////////////////////
130// RegisterGuard
131/////////////////////////////////////////////////////////////////////////////
132
133/**
134 * Guard where the condition term is taken from the value of a
135 * register (from a RegisterFile).
136 */
137class RegisterGuard : public Guard {
138public:
140 bool inverted, const RegisterFile& regFile, unsigned int registerIndex,
141 Bus* parentBus);
142 RegisterGuard(const ObjectState* state, Bus& parentBus);
143 virtual ~RegisterGuard();
144
145 bool isOpposite(const Guard& guard) const;
146 bool isEqual(const Guard& guard) const;
148 int registerIndex() const;
149 virtual void copyTo(Bus& parentBus) const {
150 new RegisterGuard(
152 &parentBus);
153 }
154
155 ObjectState* saveState() const;
156 void loadState(const ObjectState* state);
157
158 /// ObjectState name for RegisterGuard.
159 static const std::string OSNAME_REGISTER_GUARD;
160 /// ObjectState attribute key for register file name.
161 static const std::string OSKEY_REGFILE;
162 /// ObjectState attribute key for register index.
163 static const std::string OSKEY_INDEX;
164
165private:
166 /// RegisterFile from which the condition term is taken.
168 /// Index of the register from which the condition term is taken.
170};
171
172
173/////////////////////////////////////////////////////////////////////////////
174// UnconditionalGuard
175/////////////////////////////////////////////////////////////////////////////
176
177/**
178 * Always true guard term. Always false if inverted.
179 */
180class UnconditionalGuard : public Guard {
181public:
182 UnconditionalGuard(bool inverted, Bus& parentBus);
184 virtual ~UnconditionalGuard();
185
186 bool isOpposite(const Guard& /*guard*/) const { return false; }
187 bool isEqual(const Guard& guard) const;
188 ObjectState* saveState() const;
189 void loadState(const ObjectState* state);
190 virtual void copyTo(Bus& parentBus) const {
192 }
193
194 /// ObjectState name for UnconditionalGuard.
195 static const std::string OSNAME_UNCONDITIONAL_GUARD;
196};
197}
198
199#include "Guard.icc"
200
201#endif
virtual void setParentBus(Bus *parentBus)
Definition Guard.hh:60
virtual void loadState(const ObjectState *state)
Definition Guard.cc:164
virtual bool isLessRestrictive(const Guard &guard) const
Definition Guard.cc:124
bool inverted_
Indicated whether the condition term is inverted.
Definition Guard.hh:85
static const std::string OSKEY_INVERTED
ObjectState attribute key for inverted feature.
Definition Guard.hh:77
virtual bool isOpposite(const Guard &guard) const =0
static const std::string OSNAME_GUARD
ObjectState name for guard.
Definition Guard.hh:75
virtual bool isInverted() const
virtual bool isDisjoint(const Guard &guard) const
Definition Guard.cc:138
virtual bool isEqual(const Guard &guard) const =0
virtual Bus * parentBus() const
Bus * parent_
The parent bus of the guard.
Definition Guard.hh:87
virtual bool isMoreRestrictive(const Guard &guard) const
Definition Guard.cc:109
virtual ObjectState * saveState() const
Definition Guard.cc:149
virtual ~Guard()
Definition Guard.cc:90
virtual void copyTo(Bus &parentBus) const =0
static const std::string OSKEY_PORT
ObjectState attribute key for port name.
Definition Guard.hh:121
ObjectState * saveState() const
Definition Guard.cc:289
bool isOpposite(const Guard &guard) const
Definition Guard.cc:268
void loadState(const ObjectState *state)
Definition Guard.cc:312
virtual void copyTo(Bus &parentBus) const
Definition Guard.hh:109
static const std::string OSKEY_FU
ObjectState attribute key for function unit name.
Definition Guard.hh:119
bool isEqual(const Guard &guard) const
Definition Guard.cc:246
FUPort * port_
Port from which the condition term is taken.
Definition Guard.hh:125
virtual ~PortGuard()
Definition Guard.cc:235
static const std::string OSNAME_PORT_GUARD
ObjectState name for PortGuard ObjectState.
Definition Guard.hh:117
FUPort * port() const
void loadState(const ObjectState *state)
Definition Guard.cc:535
static const std::string OSNAME_REGISTER_GUARD
ObjectState name for RegisterGuard.
Definition Guard.hh:159
ObjectState * saveState() const
Definition Guard.cc:514
static const std::string OSKEY_INDEX
ObjectState attribute key for register index.
Definition Guard.hh:163
int registerIndex_
Index of the register from which the condition term is taken.
Definition Guard.hh:169
bool isEqual(const Guard &guard) const
Definition Guard.cc:467
const RegisterFile * regFile_
RegisterFile from which the condition term is taken.
Definition Guard.hh:167
const RegisterFile * registerFile() const
virtual void copyTo(Bus &parentBus) const
Definition Guard.hh:149
bool isOpposite(const Guard &guard) const
Definition Guard.cc:491
static const std::string OSKEY_REGFILE
ObjectState attribute key for register file name.
Definition Guard.hh:161
void loadState(const ObjectState *state)
Definition Guard.cc:696
bool isEqual(const Guard &guard) const
Definition Guard.cc:660
ObjectState * saveState() const
Definition Guard.cc:681
virtual void copyTo(Bus &parentBus) const
Definition Guard.hh:190
bool isOpposite(const Guard &) const
Definition Guard.hh:186
static const std::string OSNAME_UNCONDITIONAL_GUARD
ObjectState name for UnconditionalGuard.
Definition Guard.hh:195