OpenASIP 2.2
Loading...
Searching...
No Matches
InstructionReference.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 InstructionReference.cc
26 *
27 * Implementation of InstructionReference class.
28 *
29 * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30 * @author Heikki Kultala 2009 (heikki.kultala-no.spam-tut.fi)
31 * @note rating: red
32 */
33
36#include "NullInstruction.hh"
37
38namespace TTAProgram {
39
40/////////////////////////////////////////////////////////////////////////////
41// InstructionReference
42/////////////////////////////////////////////////////////////////////////////
43
44/**
45 * Constructor.
46 *
47 * @note Instruction references should be created using
48 * InstructionReferenceManager.
49 * @param ins Referred instruction.
50 */
52 impl_(impl) {
53 if (impl_ != NULL) {
54 impl_->addRef(*this);
55 }
56}
57
58/**
59 * Constructor.
60 *
61 * @note Instruction references should be created using
62 * InstructionReferenceManager.
63 * @param ins Referred instruction.
64 */
66 impl_(ref.impl_) {
67 if (impl_ != NULL) {
68 impl_->addRef(*this);
69 }
70}
71
72/**
73 * Assignment operator.
74 *
75 * Changes this reference to point to another instruction. Only changes
76 * this reference, not other references pointing to same instruction.
77 */
80 const InstructionReference& ref) {
81 // if both point to same instruction, no need to do anything.
82 if (ref.impl_ != impl_) {
83 // stop pointing to old instruction
84 if (impl_ != NULL) {
85 impl_->removeRef(*this);
86 }
87 // pointing to new instruction
88 impl_ = ref.impl_;
89 if (impl_ != NULL) {
90 impl_->addRef(*this);
91 }
92 }
93 return *this;
94}
95
96
97/**
98 * Destructor.
99 *
100 * Tells the impl that we are no longer pointing to it.
101 * It may get also deleted if this was the last reference to it.
102 */
104 if (impl_ != NULL) {
105 impl_->removeRef(*this);
106 }
107}
108
109/**
110 * Sets a new referred instruction.
111 *
112 * The InstructionReferenceImpl is a "proxy object" that counts and
113 * keeps book of references
114 *
115 * @param newImpl New referred instruction.
116 * @return true if old impl stays alive, false if it is deleted.
117 */
118bool
120 bool staysAlive = true;
121 assert(newImpl != impl_);
122 if (impl_ != NULL) {
123 staysAlive = impl_->removeRef(*this);
124 }
125 impl_ = newImpl;
126 if (impl_ != NULL) {
127 impl_->addRef(*this);
128 }
129 return staysAlive;
130}
131
132/**
133 * Returns the referred instruction.
134 *
135 * @return Referred instruction.
136 */
139 if (impl_ == NULL) {
141 } else {
142 return impl_->instruction();
143 }
144}
145
146bool
148 return impl_ == other.impl_;
149}
150
151}
#define assert(condition)
bool removeRef(InstructionReference &ref)
bool setImpl(InstructionReferenceImpl *impl)
InstructionReference(InstructionReferenceImpl *impl)
bool operator==(const InstructionReference &other) const
InstructionReference & operator=(const InstructionReference &)
static NullInstruction & instance()