OpenASIP 2.2
Loading...
Searching...
No Matches
Immediate.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 Immediate.cc
26 *
27 * Implementation of Immediate class.
28 *
29 * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include "Immediate.hh"
34#include "Terminal.hh"
36#include "TerminalImmediate.hh"
37
38using namespace TTAMachine;
39
40namespace TTAProgram {
41
42/////////////////////////////////////////////////////////////////////////////
43// Immediate
44/////////////////////////////////////////////////////////////////////////////
45
46/**
47 * The constructor.
48 *
49 * Creates a long immediate with the given value. The value specifies,
50 * implicitly, also the width of the instruction field(s) where the
51 * immediate bits are encoded). The destination register and the set
52 * of instruction slots where the immediate bits are encoded are also
53 * given as parameters.
54 *
55 * The ownership of the destination terminal object will be passed to
56 * the immediate.
57 *
58 * @param value Value of the immediate.
59 * @param dst Destination register.
60 */
61
62// Immediate::Immediate(
63// SimValue value, Terminal* dst)
64// :
65// value_(value), dst_(dst) {
66//}
67
69 : value_(value), dst_(dst), parent_(nullptr) {}
70
71/**
72 * The destructor.
73 */
75 if (dst_ != NULL) {
76 delete dst_;
77 dst_ = NULL;
78 }
79
80 if (value_ != NULL) {
81 delete value_;
82 value_ = NULL;
83 }
84}
85
86/**
87 * Returns the destination register of this immediate.
88 *
89 * @return The destination register of this immediate.
90 */
91const Terminal&
93 assert(dst_ != NULL);
94 return *dst_;
95}
96
97/**
98 * Returns the value of this immediate.
99 *
100 * @return The value of this immediate.
101 */
104 assert(value_ != NULL);
105 return *value_;
106}
107
108/**
109 * Sets the value of immediate.
110 *
111 * @param Value to set for immediate.
112 */
113void
115 if (value_ != NULL) {
116 delete value_;
117 }
118 value_ = value;
119}
120
121/**
122 * Makes a copy of the immediate.
123 *
124 * The copy is identical, except that it is not registered to the
125 * instruction of the original immediate (and therefore, any address it
126 * refers to is not meaningful).
127 *
128 * @return A copy of the immediate.
129 */
130std::shared_ptr<Immediate>
132 return std::make_shared<Immediate>(
133 dynamic_cast<TerminalImmediate*>(value_->copy()), dst_->copy());
134}
135
136}
#define assert(condition)
void setValue(TerminalImmediate *value)
Definition Immediate.cc:114
TerminalImmediate & value() const
Definition Immediate.cc:103
Immediate(TerminalImmediate *value, Terminal *dst)
Definition Immediate.cc:68
const Terminal & destination() const
Definition Immediate.cc:92
Terminal * dst_
The destination register.
Definition Immediate.hh:79
TerminalImmediate * value_
Value of the immediate.
Definition Immediate.hh:76
std::shared_ptr< Immediate > copy() const
Definition Immediate.cc:131
virtual Terminal * copy() const
virtual Terminal * copy() const =0