OpenASIP
2.0
src
applibs
Simulator
LongImmediateRegisterState.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 LongImmediateRegisterState.cc
26
*
27
* Definition of LongImmediateRegisterState class.
28
*
29
* @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30
* @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
31
* @note rating: red
32
*/
33
34
#include "
LongImmediateRegisterState.hh
"
35
#include "
LongImmediateUnitState.hh
"
36
#include "
SimValue.hh
"
37
38
using
std::string;
39
40
/**
41
* Constructor.
42
*
43
* @param parent Parent unit of the register.
44
* @param index Index of the register.
45
* @param width The bit width of the register.
46
* @param signExtend True in case written value should be sign extended
47
* (default is zero extension).
48
*/
49
LongImmediateRegisterState::LongImmediateRegisterState
(
50
LongImmediateUnitState
* parent,
int
index,
int
width,
bool
signExtend) :
51
StateData
(), parent_(parent), index_(index), width_(width),
52
signExtend_(signExtend) {
53
}
54
55
/**
56
* Destructor.
57
*/
58
LongImmediateRegisterState::~LongImmediateRegisterState
() {
59
}
60
61
/**
62
* Sets the value of the register.
63
*
64
* Also extends the value if it's narrower than the register width.
65
*
66
* @param value New value.
67
*/
68
void
69
LongImmediateRegisterState::setValue
(
const
SimValue
& value) {
70
// The value is extended in case it's smaller than WORD_BITWIDTH,
71
// which is the width of (int) otherwise we won't extend, as it's
72
// probably a double. In the future when we support 64 bit or larger
73
// integers, this check is not needed.
74
if
(
value
.
width
() <
width_
) {
75
SimValue
newValue(
width_
);
76
int
ext =
width_
-
value
.
width
();
77
78
if
(
signExtend_
) {
79
SLongWord
toBeExtended =
value
.
sLongWordValue
();
80
newValue = ((long)(toBeExtended << ext) >> ext);
81
}
else
{
82
// @todo: this might not be needed, we could assume the top bits
83
// to be zero already
84
ULongWord
toBeExtended =
value
.
uLongWordValue
();
85
newValue = ((toBeExtended << ext) >> ext);
86
}
87
parent_
->
setRegisterValue
(
index_
, newValue);
88
}
else
{
89
parent_
->
setRegisterValue
(
index_
,
value
);
90
}
91
}
92
93
/**
94
* Returns the register value.
95
*
96
* @return Register value.
97
*/
98
const
SimValue
&
99
LongImmediateRegisterState::value
()
const
{
100
return
parent_
->
registerValue
(
index_
);
101
}
102
LongImmediateRegisterState::setValue
virtual void setValue(const SimValue &value)
Definition:
LongImmediateRegisterState.cc:69
SimValue::sLongWordValue
SLongWord sLongWordValue() const
Definition:
SimValue.cc:997
LongImmediateUnitState::setRegisterValue
virtual void setRegisterValue(int index, const SimValue &value)
Definition:
LongImmediateUnitState.cc:114
SimValue
Definition:
SimValue.hh:96
LongImmediateUnitState.hh
LongImmediateRegisterState::LongImmediateRegisterState
LongImmediateRegisterState(LongImmediateUnitState *parent, int index, int width, bool signExtend)
Definition:
LongImmediateRegisterState.cc:49
LongImmediateRegisterState::parent_
LongImmediateUnitState * parent_
Parent unit of the register state.
Definition:
LongImmediateRegisterState.hh:66
LongImmediateRegisterState.hh
LongImmediateRegisterState::~LongImmediateRegisterState
virtual ~LongImmediateRegisterState()
Definition:
LongImmediateRegisterState.cc:58
LongImmediateRegisterState::signExtend_
bool signExtend_
True in case the written values should be sign extended.
Definition:
LongImmediateRegisterState.hh:72
SimValue::uLongWordValue
ULongWord uLongWordValue() const
Definition:
SimValue.cc:1027
SimValue::width
int width() const
Definition:
SimValue.cc:103
SimValue.hh
ULongWord
unsigned long ULongWord
Definition:
BaseType.hh:51
LongImmediateRegisterState::width_
int width_
The bit width of the register (needed only while extending).
Definition:
LongImmediateRegisterState.hh:70
StateData
Definition:
StateData.hh:44
LongImmediateUnitState::registerValue
virtual SimValue & registerValue(int index)
Definition:
LongImmediateUnitState.cc:98
SLongWord
long SLongWord
Definition:
BaseType.hh:52
LongImmediateRegisterState::index_
int index_
Index of the register.
Definition:
LongImmediateRegisterState.hh:68
LongImmediateUnitState
Definition:
LongImmediateUnitState.hh:55
LongImmediateRegisterState::value
virtual const SimValue & value() const
Definition:
LongImmediateRegisterState.cc:99
Generated by
1.8.17