OpenASIP  2.0
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 
37 class ObjectState;
38 
39 namespace TTAMachine {
40 
41 class FUPort;
42 class Bus;
43 class 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  */
55 class Guard : public SubComponent {
56 public:
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 
79 protected:
80  Guard(bool inverted, Bus* parentBus);
81  Guard(const ObjectState* state, Bus& parentBus);
82 
83 private:
84  /// Indicated whether the condition term is inverted.
85  bool 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  */
99 class PortGuard : public Guard {
100 public:
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 
123 private:
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  */
137 class RegisterGuard : public Guard {
138 public:
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;
147  const RegisterFile* registerFile() 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 
165 private:
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  */
180 class UnconditionalGuard : public Guard {
181 public:
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
TTAMachine::Guard
Definition: Guard.hh:55
TTAMachine::UnconditionalGuard::saveState
ObjectState * saveState() const
Definition: Guard.cc:681
TTAMachine::Guard::saveState
virtual ObjectState * saveState() const
Definition: Guard.cc:149
TTAMachine::PortGuard::loadState
void loadState(const ObjectState *state)
Definition: Guard.cc:312
TTAMachine::Guard::OSNAME_GUARD
static const std::string OSNAME_GUARD
ObjectState name for guard.
Definition: Guard.hh:75
TTAMachine::SubComponent
Definition: MachinePart.hh:168
TTAMachine::Guard::isDisjoint
virtual bool isDisjoint(const Guard &guard) const
Definition: Guard.cc:138
TTAMachine::PortGuard::port
FUPort * port() const
TTAMachine::RegisterGuard::OSNAME_REGISTER_GUARD
static const std::string OSNAME_REGISTER_GUARD
ObjectState name for RegisterGuard.
Definition: Guard.hh:159
TTAMachine::RegisterGuard::registerIndex
int registerIndex() const
TTAMachine::RegisterGuard::copyTo
virtual void copyTo(Bus &parentBus) const
Definition: Guard.hh:149
TTAMachine::PortGuard::port_
FUPort * port_
Port from which the condition term is taken.
Definition: Guard.hh:125
TTAMachine::Guard::~Guard
virtual ~Guard()
Definition: Guard.cc:90
TTAMachine::Guard::isEqual
virtual bool isEqual(const Guard &guard) const =0
TTAMachine::Bus
Definition: Bus.hh:53
TTAMachine::PortGuard::~PortGuard
virtual ~PortGuard()
Definition: Guard.cc:235
TTAMachine::UnconditionalGuard::copyTo
virtual void copyTo(Bus &parentBus) const
Definition: Guard.hh:190
ObjectState
Definition: ObjectState.hh:59
TTAMachine::Guard::inverted_
bool inverted_
Indicated whether the condition term is inverted.
Definition: Guard.hh:85
TTAMachine::RegisterGuard::isOpposite
bool isOpposite(const Guard &guard) const
Definition: Guard.cc:491
TTAMachine::PortGuard::saveState
ObjectState * saveState() const
Definition: Guard.cc:289
MachinePart.hh
TTAMachine::UnconditionalGuard
Definition: Guard.hh:180
TTAMachine::RegisterGuard::~RegisterGuard
virtual ~RegisterGuard()
Definition: Guard.cc:456
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::Guard::copyTo
virtual void copyTo(Bus &parentBus) const =0
Guard.icc
TTAMachine::PortGuard::isEqual
bool isEqual(const Guard &guard) const
Definition: Guard.cc:246
TTAMachine::Guard::OSKEY_INVERTED
static const std::string OSKEY_INVERTED
ObjectState attribute key for inverted feature.
Definition: Guard.hh:77
TTAMachine::UnconditionalGuard::isOpposite
bool isOpposite(const Guard &) const
Definition: Guard.hh:186
TTAMachine::RegisterGuard
Definition: Guard.hh:137
TTAMachine::Guard::parent_
Bus * parent_
The parent bus of the guard.
Definition: Guard.hh:87
TTAMachine::RegisterGuard::loadState
void loadState(const ObjectState *state)
Definition: Guard.cc:535
TTAMachine::PortGuard::OSKEY_PORT
static const std::string OSKEY_PORT
ObjectState attribute key for port name.
Definition: Guard.hh:121
TTAMachine::UnconditionalGuard::isEqual
bool isEqual(const Guard &guard) const
Definition: Guard.cc:660
TTAMachine::Guard::isLessRestrictive
virtual bool isLessRestrictive(const Guard &guard) const
Definition: Guard.cc:124
TTAMachine::Guard::Guard
Guard(bool inverted, Bus *parentBus)
Definition: Guard.cc:64
TTAMachine::RegisterGuard::registerIndex_
int registerIndex_
Index of the register from which the condition term is taken.
Definition: Guard.hh:169
TTAMachine::UnconditionalGuard::UnconditionalGuard
UnconditionalGuard(bool inverted, Bus &parentBus)
Definition: Guard.cc:615
TTAMachine::PortGuard::isOpposite
bool isOpposite(const Guard &guard) const
Definition: Guard.cc:268
TTAMachine::RegisterGuard::RegisterGuard
RegisterGuard(bool inverted, const RegisterFile &regFile, unsigned int registerIndex, Bus *parentBus)
Definition: Guard.cc:393
TTAMachine::RegisterGuard::OSKEY_REGFILE
static const std::string OSKEY_REGFILE
ObjectState attribute key for register file name.
Definition: Guard.hh:161
TTAMachine::Guard::isOpposite
virtual bool isOpposite(const Guard &guard) const =0
TTAMachine::Guard::parentBus
virtual Bus * parentBus() const
TTAMachine::Guard::setParentBus
virtual void setParentBus(Bus *parentBus)
Definition: Guard.hh:60
TTAMachine::Guard::isInverted
virtual bool isInverted() const
TTAMachine::UnconditionalGuard::~UnconditionalGuard
virtual ~UnconditionalGuard()
Definition: Guard.cc:649
TTAMachine::Guard::loadState
virtual void loadState(const ObjectState *state)
Definition: Guard.cc:164
TTAMachine::PortGuard::OSKEY_FU
static const std::string OSKEY_FU
ObjectState attribute key for function unit name.
Definition: Guard.hh:119
TTAMachine::PortGuard::PortGuard
PortGuard(bool inverted, FUPort &port, Bus &parentBus)
Definition: Guard.cc:196
TTAMachine::RegisterGuard::OSKEY_INDEX
static const std::string OSKEY_INDEX
ObjectState attribute key for register index.
Definition: Guard.hh:163
TTAMachine::PortGuard
Definition: Guard.hh:99
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAMachine::Guard::isMoreRestrictive
virtual bool isMoreRestrictive(const Guard &guard) const
Definition: Guard.cc:109
TTAMachine::UnconditionalGuard::loadState
void loadState(const ObjectState *state)
Definition: Guard.cc:696
TTAMachine
Definition: Assembler.hh:48
TTAMachine::PortGuard::OSNAME_PORT_GUARD
static const std::string OSNAME_PORT_GUARD
ObjectState name for PortGuard ObjectState.
Definition: Guard.hh:117
TTAMachine::UnconditionalGuard::OSNAME_UNCONDITIONAL_GUARD
static const std::string OSNAME_UNCONDITIONAL_GUARD
ObjectState name for UnconditionalGuard.
Definition: Guard.hh:195
TTAMachine::RegisterGuard::registerFile
const RegisterFile * registerFile() const
TTAMachine::RegisterGuard::saveState
ObjectState * saveState() const
Definition: Guard.cc:514
TTAMachine::RegisterGuard::isEqual
bool isEqual(const Guard &guard) const
Definition: Guard.cc:467
TTAMachine::RegisterGuard::regFile_
const RegisterFile * regFile_
RegisterFile from which the condition term is taken.
Definition: Guard.hh:167
TTAMachine::PortGuard::copyTo
virtual void copyTo(Bus &parentBus) const
Definition: Guard.hh:109