OpenASIP  2.0
RegisterFileState.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 RegisterFileState.cc
26  *
27  * Definition of RegisterFileState 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 <string>
35 
36 #include "RegisterFileState.hh"
37 #include "RegisterState.hh"
38 #include "SequenceTools.hh"
39 #include "Application.hh"
40 
41 using std::string;
42 
43 //////////////////////////////////////////////////////////////////////////////
44 // RegisterFileState
45 //////////////////////////////////////////////////////////////////////////////
46 
47 /**
48  * Constructor.
49  *
50  * @param size The size of the RegisterFileState.
51  * @param width Width of the registers.
52  * @param zeroRegister Tells whether the first index is hardcoded to zero
53  */
54 RegisterFileState::RegisterFileState(int size, int width, bool zeroRegister) :
55  zeroRegister_(zeroRegister) {
56  if (zeroRegister_) {
57  registerStates_.push_back(new RegisterState(width, true));
58  } else {
59  registerStates_.push_back(new RegisterState(width, false));
60  }
61  for (int i = 1; i < size; i++) {
62  registerStates_.push_back(new RegisterState(width, false));
63  }
64 }
65 
66 /**
67  * Destructor.
68  */
71 }
72 
73 /**
74  * Returns RegisterState with a given index.
75  *
76  * @param index Index of the wanted RegisterState.
77  * @return RegisterState with a given index.
78  * @exception OutOfRange If index is out of range.
79  */
82  if (index < 0 || index > static_cast<int>(registerStates_.size()) - 1) {
83  string msg = "Register index out of range";
84  throw OutOfRange(__FILE__, __LINE__, __func__, msg);
85  }
86  return *registerStates_[index];
87 }
88 
89 /**
90  * Returns the count of registers in the register file.
91  *
92  * @return Count of registers.
93  */
94 std::size_t
96  return registerStates_.size();
97 }
98 
99 //////////////////////////////////////////////////////////////////////////////
100 // NullRegisterFileState
101 //////////////////////////////////////////////////////////////////////////////
102 
104 
105 /**
106  * Returns the instance of NullRegisterFileState.
107  *
108  * @return The instance of NullRegisterFileState.
109  */
112  if (instance_ == NULL) {
114  }
115  return *instance_;
116 }
117 
118 /**
119  * Constructor.
120  */
122 }
123 
124 /**
125  * Destructor.
126  */
128 }
129 
130 /**
131  * Aborts the program with error message.
132  *
133  * @return Never returns.
134  * @exception OutOfRange Never throws.
135  */
138  Application::abortWithError("registerState()");
140 }
RegisterFileState::RegisterFileState
RegisterFileState(int size, int width, bool zeroRegister=false)
Definition: RegisterFileState.cc:54
RegisterFileState::registerStates_
std::vector< RegisterState * > registerStates_
Contains all the registers of the state.
Definition: RegisterFileState.hh:66
RegisterFileState::~RegisterFileState
virtual ~RegisterFileState()
Definition: RegisterFileState.cc:69
RegisterFileState.hh
NullRegisterFileState::instance_
static NullRegisterFileState * instance_
Unique instance of NullRegisterFileState.
Definition: RegisterFileState.hh:94
OutOfRange
Definition: Exception.hh:320
SequenceTools.hh
NullRegisterFileState::registerState
virtual RegisterState & registerState(int index)
Definition: RegisterFileState.cc:137
NullRegisterState::instance
static NullRegisterState & instance()
Definition: RegisterState.cc:108
SequenceTools::deleteAllItems
static void deleteAllItems(SequenceType &aSequence)
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
Application.hh
__func__
#define __func__
Definition: Application.hh:67
NullRegisterFileState::instance
static NullRegisterFileState & instance()
Definition: RegisterFileState.cc:111
NullRegisterFileState::~NullRegisterFileState
virtual ~NullRegisterFileState()
Definition: RegisterFileState.cc:127
RegisterFileState::registerCount
virtual std::size_t registerCount() const
Definition: RegisterFileState.cc:95
RegisterFileState::registerState
virtual RegisterState & registerState(int index)
Definition: RegisterFileState.cc:81
NullRegisterFileState
Definition: RegisterFileState.hh:78
RegisterFileState
Definition: RegisterFileState.hh:49
RegisterState
Definition: RegisterState.hh:50
RegisterState.hh
NullRegisterFileState::NullRegisterFileState
NullRegisterFileState()
Definition: RegisterFileState.cc:121
RegisterFileState::zeroRegister_
bool zeroRegister_
Definition: RegisterFileState.hh:68