OpenASIP  2.0
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"
35 #include "InstructionTemplate.hh"
36 #include "TerminalImmediate.hh"
37 
38 using namespace TTAMachine;
39 
40 namespace 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 
68 Immediate::Immediate(TerminalImmediate* value, Terminal* dst)
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  */
91 const 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  */
113 void
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  */
130 std::shared_ptr<Immediate>
132  return std::make_shared<Immediate>(
133  dynamic_cast<TerminalImmediate*>(value_->copy()), dst_->copy());
134 }
135 
136 }
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Immediate::value
TerminalImmediate & value() const
Definition: Immediate.cc:103
Terminal.hh
TTAProgram::Immediate::copy
std::shared_ptr< Immediate > copy() const
Definition: Immediate.cc:131
TTAProgram::Immediate::destination
const Terminal & destination() const
Definition: Immediate.cc:92
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::Immediate::dst_
Terminal * dst_
The destination register.
Definition: Immediate.hh:79
InstructionTemplate.hh
TTAProgram::TerminalImmediate::copy
virtual Terminal * copy() const
Definition: TerminalImmediate.cc:85
TTAProgram::Immediate::value_
TerminalImmediate * value_
Value of the immediate.
Definition: Immediate.hh:76
TTAProgram::Immediate::setValue
void setValue(TerminalImmediate *value)
Definition: Immediate.cc:114
TTAProgram::TerminalImmediate
Definition: TerminalImmediate.hh:44
TerminalImmediate.hh
Immediate.hh
TTAProgram::Terminal::copy
virtual Terminal * copy() const =0
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAMachine
Definition: Assembler.hh:48
TTAProgram::Immediate::~Immediate
virtual ~Immediate()
Definition: Immediate.cc:74