OpenASIP 2.2
Loading...
Searching...
No Matches
CodeLabel.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 CodeLabel.cc
26 *
27 * Implementation of CodeLabel class.
28 *
29 * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include "CodeLabel.hh"
34#include "Instruction.hh"
36#include "Procedure.hh"
37#include "Program.hh"
39#include "NullInstruction.hh"
40#include "GlobalScope.hh"
41
42using std::string;
43
44namespace TTAProgram {
45
46/////////////////////////////////////////////////////////////////////////////
47// CodeLabel
48/////////////////////////////////////////////////////////////////////////////
49
50/**
51 * Constructor.
52 *
53 * Registers this label to the owning scope.
54 *
55 * @param ins Instruction corresponding to this label.
56 * @param name Name of the label. Must be unique within the owning scope.
57 * @exception IllegalRegistration if the given instruction does not belong
58 * to a procedure, or its parent procedure does not belong to a
59 * program.
60 */
61CodeLabel::CodeLabel(const InstructionReference& ins, std::string name)
62 :
63
64 ins_(ins) {
65 proc_ = NULL;
68 // scope is the global scope for now
70}
71
72/**
73 * An alternative constructor that takes the procedure.
74 *
75 * @param proc Procedure corresponding to this label
76 * @exception IllegalRegistration if the given procedure does not belong
77 * to a program.
78 */
80 : ins_(InstructionReference(NULL)), proc_(&proc) {
81 setName(proc.name());
83 // scope is the global scope for now
84 setScope(proc.parent().globalScope());
85}
86
87/**
88 * The destructor.
89 */
92
93/**
94 * Returns the address of the instruction or procedure corresponding to this
95 * label.
96 *
97 * @return The address of the instruction or procedure corresponding to this
98 * label.
99 */
103 return ins_.instruction().address();
104 } else {
105 return proc_->startAddress();
106 }
107}
108
109/**
110 * Returns a reference to the instruction corresponding to this label.
111 *
112 * @return a reference to the instruction corresponding to this label.
113 * @exception IllegalRegistration if the label points to a procedure that
114 * has no instructions.
115 */
119 return ins_;
120 } else if (proc_->instructionCount() == 0) {
121 throw IllegalRegistration(__FILE__, __LINE__);
122 } else {
124 }
125}
126
127/**
128 * Return the procedure that contains this label.
129 *
130 * @return The procedure that contains this label or the procedure at which
131 * this labels points.
132 * @exception IllegalRegistration if the label is not registered in a
133 * procedure.
134 */
135const Procedure&
137 if (proc_ == NULL) {
138 const Procedure* proc = dynamic_cast<const Procedure*>(
139 &(ins_.instruction().parent()));
140 assert(proc != NULL);
141 return *proc;
142 } else {
143 return *proc_;
144 }
145}
146}
#define assert(condition)
const Procedure & procedure() const
Definition CodeLabel.cc:136
const Procedure * proc_
Procedure corresponding to this label.
Definition CodeLabel.hh:65
virtual Address address() const
Definition CodeLabel.cc:101
const InstructionReference ins_
Reference to instruction corresponding to this label.
Definition CodeLabel.hh:63
const InstructionReference instructionReference() const
Definition CodeLabel.cc:117
CodeLabel(const InstructionReference &ins, std::string name)
Definition CodeLabel.cc:61
virtual Instruction & firstInstruction() const
virtual int instructionCount() const
virtual Program & parent() const
virtual Address startAddress() const
InstructionReference createReference(Instruction &ins)
Address address() const
CodeSnippet & parent() const
void setScope(const Scope &scope)
Definition Label.cc:118
std::string name() const
Definition Label.cc:74
void setAddress(Address address)
Definition Label.cc:110
void setName(const std::string &name)
Definition Label.cc:102
static NullInstruction & instance()
TCEString name() const
Definition Procedure.hh:66
GlobalScope & globalScope()
Definition Program.cc:180
InstructionReferenceManager & instructionReferenceManager() const
Definition Program.cc:688