OpenASIP  2.0
GPRGuardEncoding.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 GPRGuardEncoding.cc
26  *
27  * Implementation of GPRGuardEncoding class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "GPRGuardEncoding.hh"
36 #include "GuardField.hh"
37 #include "ObjectState.hh"
38 
39 using std::string;
40 
42  "gpr_guard_enc";
43 const std::string GPRGuardEncoding::OSKEY_RF_NAME = "rf_name";
44 const std::string GPRGuardEncoding::OSKEY_REGISTER_INDEX = "reg_index";
45 
46 /**
47  * The constructor.
48  *
49  * Creates a guard encoding and Registers it into the given guard field
50  * automatically. The guard expression is identified by the name of register
51  * file, the index of the GPR and the "invert" flag, all given as parameters.
52  *
53  * @param regFile Name of the register file.
54  * @param index The index the GPR.
55  * @param inverted The "invert" flag.
56  * @param encoding The control code of the guard expression.
57  * @param parent The parent guard field.
58  * @exception ObjectAlreadyExists If the guard expression is already encoded
59  * in the parent field, or if the given control
60  * code is already assigned to another guard
61  * expression.
62  */
64  const std::string& regFile, int index, bool inverted, unsigned int encoding,
65  GuardField& parent)
66  : GuardEncoding(inverted, encoding), regFile_(regFile), index_(index) {
67  parent.addGuardEncoding(*this);
68  setParent(&parent);
69 }
70 
71 /**
72  * The constructor.
73  *
74  * Loads the state of the object from the given ObjectState instance.
75  *
76  * @param state The ObjectState instance.
77  * @param parent The parent guard field.
78  * @exception ObjectStateLoadingException If an error occurs while loading the
79  * state.
80  * @exception ObjectAlreadyExists If the guard expression is already encoded
81  * in the parent field, or if the given control
82  * code is already assigned to another guard
83  * expression.
84  */
86  : GuardEncoding(state), regFile_(""), index_(0) {
87  const string procName = "GPRGuardEncoding::GPRGuardEncoding";
88 
89  if (state->name() != OSNAME_GPR_GUARD_ENCODING) {
90  throw ObjectStateLoadingException(__FILE__, __LINE__, procName);
91  }
92 
93  try {
96  } catch (const Exception& exception) {
98  __FILE__, __LINE__, procName, exception.errorMessage());
99  }
100 
101  parent.addGuardEncoding(*this);
102  setParent(&parent);
103 }
104 
105 /**
106  * The destructor.
107  */
109  GuardField* parent = this->parent();
110  setParent(NULL);
111  parent->removeGuardEncoding(*this);
112 }
113 
114 
115 /**
116  * Returns the name of the register file that contains the GPR of this guard
117  * expression.
118  *
119  * @return The name of the register file.
120  */
121 std::string
123  return regFile_;
124 }
125 
126 
127 /**
128  * Returns the index of the GPR of this guard expression.
129  *
130  * @return The index of the GPR.
131  */
132 int
134  return index_;
135 }
136 
137 
138 /**
139  * Saves the state of the object to an ObjectState instance.
140  *
141  * @return The newly created ObjectState instance.
142  */
149  return state;
150 }
GPRGuardEncoding::GPRGuardEncoding
GPRGuardEncoding(const std::string &regFile, int index, bool inverted, unsigned int encoding, GuardField &parent)
Definition: GPRGuardEncoding.cc:63
GPRGuardEncoding::index_
int index_
Register index.
Definition: GPRGuardEncoding.hh:71
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
ObjectStateLoadingException
Definition: Exception.hh:551
GPRGuardEncoding::registerFile
std::string registerFile() const
Definition: GPRGuardEncoding.cc:122
GuardField.hh
GPRGuardEncoding::OSKEY_REGISTER_INDEX
static const std::string OSKEY_REGISTER_INDEX
ObjectState attribute key for register index.
Definition: GPRGuardEncoding.hh:65
ObjectState
Definition: ObjectState.hh:59
GuardField
Definition: GuardField.hh:55
ObjectState::setName
void setName(const std::string &name)
GuardField::addGuardEncoding
void addGuardEncoding(GPRGuardEncoding &encoding)
Definition: GuardField.cc:141
GPRGuardEncoding::saveState
virtual ObjectState * saveState() const
Definition: GPRGuardEncoding.cc:144
GPRGuardEncoding::regFile_
std::string regFile_
Name of the register file.
Definition: GPRGuardEncoding.hh:69
GuardEncoding::setParent
void setParent(GuardField *parent)
Definition: GuardEncoding.cc:137
GuardEncoding
Definition: GuardEncoding.hh:45
ObjectState.hh
Exception
Definition: Exception.hh:54
ObjectState::name
std::string name() const
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
GPRGuardEncoding.hh
GPRGuardEncoding::OSKEY_RF_NAME
static const std::string OSKEY_RF_NAME
ObjectState attribute key for the name of the register file.
Definition: GPRGuardEncoding.hh:63
GuardField::removeGuardEncoding
void removeGuardEncoding(GPRGuardEncoding &encoding)
Definition: GuardField.cc:163
GPRGuardEncoding::OSNAME_GPR_GUARD_ENCODING
static const std::string OSNAME_GPR_GUARD_ENCODING
ObjectState name for GPR guard encoding.
Definition: GPRGuardEncoding.hh:61
ObjectState::intAttribute
int intAttribute(const std::string &name) const
Definition: ObjectState.cc:276
GPRGuardEncoding::registerIndex
int registerIndex() const
Definition: GPRGuardEncoding.cc:133
GuardEncoding::saveState
virtual ObjectState * saveState() const
Definition: GuardEncoding.cc:123
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
GPRGuardEncoding::~GPRGuardEncoding
virtual ~GPRGuardEncoding()
Definition: GPRGuardEncoding.cc:108
GuardEncoding::parent
GuardField * parent() const
Definition: GuardEncoding.cc:90