OpenASIP  2.0
RegisterState.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 RegisterState.cc
26  *
27  * Definition of RegisterState class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31  * @note rating: red
32  */
33 
34 #include "RegisterState.hh"
35 #include "Application.hh"
36 
37 using std::string;
38 
39 //////////////////////////////////////////////////////////////////////////////
40 // RegisterState
41 //////////////////////////////////////////////////////////////////////////////
42 
43 
44 /**
45  * Constructor.
46  *
47  * @param width The width of the register.
48  * @param constantZero Tells whether the register is constant zero
49  */
50 RegisterState::RegisterState(int width, bool constantZero) :
51  StateData(), value_(*(new SimValue(width))), shared_(false),
52  constantZero_(constantZero) {
53 }
54 
55 /**
56  * Constructor for RegisterState which shares the actual register storage.
57  *
58  * @param sharedRegister The register which is shared with this.
59  */
61  StateData(), value_(sharedRegister), shared_(true),
62  constantZero_(false) {
63 }
64 
65 /**
66  * Destructor.
67  */
69  if (!shared_) {
70  delete &value_;
71  }
72 }
73 
74 /**
75  * Sets the value for the register.
76  *
77  * @param value Value to be set.
78  */
79 void
81  if (!constantZero_) {
82  value_ = value;
83  }
84 }
85 
86 /**
87  * Returns the value of the register.
88  *
89  * @return The value of the register.
90  */
91 const SimValue&
93  return value_;
94 }
95 
96 //////////////////////////////////////////////////////////////////////////////
97 // NullRegisterState
98 //////////////////////////////////////////////////////////////////////////////
99 
101 
102 /**
103  * Returns instance of NullRegisterState.
104  *
105  * @return The instance of NullRegisterState.
106  */
109  if (instance_ == NULL) {
111  }
112  return *instance_;
113 }
114 
115 /**
116  * Constructor.
117  */
119 }
120 
121 /**
122  * Destructor.
123  */
125 }
126 
127 /**
128  * Aborts the program with error message.
129  */
130 void
132  Application::abortWithError("setValue()");
133 }
134 
135 /**
136  * Aborts the program with error message.
137  *
138  * @return Never returns.
139  */
140 const SimValue&
142  Application::abortWithError("value()");
143  return NullSimValue::instance();
144 }
145 
RegisterState::shared_
bool shared_
Is the storage of this RegisterState shared with someone else?
Definition: RegisterState.hh:71
NullSimValue::instance
static SimValue & instance()
Definition: SimValue.cc:1642
RegisterState::constantZero_
bool constantZero_
Is this register constant zero?
Definition: RegisterState.hh:73
NullRegisterState::instance
static NullRegisterState & instance()
Definition: RegisterState.cc:108
NullRegisterState::value
virtual const SimValue & value() const
Definition: RegisterState.cc:141
NullRegisterState::setValue
virtual void setValue(const SimValue &value)
Definition: RegisterState.cc:131
SimValue
Definition: SimValue.hh:96
RegisterState::RegisterState
RegisterState(int width, bool constantZero=false)
Definition: RegisterState.cc:50
NullRegisterState
Definition: RegisterState.hh:83
RegisterState::value
virtual const SimValue & value() const
Definition: RegisterState.cc:92
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
RegisterState::~RegisterState
virtual ~RegisterState()
Definition: RegisterState.cc:68
NullRegisterState::instance_
static NullRegisterState * instance_
Unique instance of NullRegisterState.
Definition: RegisterState.hh:100
RegisterState::value_
SimValue & value_
Value of the RegisterState.
Definition: RegisterState.hh:63
Application.hh
NullRegisterState::NullRegisterState
NullRegisterState()
Definition: RegisterState.cc:118
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
RegisterState
Definition: RegisterState.hh:50
StateData
Definition: StateData.hh:44
RegisterState.hh
NullRegisterState::~NullRegisterState
virtual ~NullRegisterState()
Definition: RegisterState.cc:124
RegisterState::setValue
virtual void setValue(const SimValue &value)
Definition: RegisterState.cc:80