OpenASIP  2.0
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"
35 #include "InstructionReference.hh"
36 #include "Procedure.hh"
37 #include "Program.hh"
39 #include "NullInstruction.hh"
40 #include "GlobalScope.hh"
41 
42 using std::string;
43 
44 namespace 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  */
61 CodeLabel::CodeLabel(const InstructionReference& ins, std::string name)
62  :
63 
64  ins_(ins) {
65  proc_ = NULL;
66  setName(name);
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());
82  setAddress(proc.startAddress());
83  // scope is the global scope for now
84  setScope(proc.parent().globalScope());
85 }
86 
87 /**
88  * The destructor.
89  */
91 }
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  */
100 Address
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  */
135 const 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 }
TTAProgram
Definition: Estimator.hh:65
TTAProgram::InstructionReference::instruction
Instruction & instruction() const
Definition: InstructionReference.cc:138
TTAProgram::CodeSnippet::firstInstruction
virtual Instruction & firstInstruction() const
Definition: CodeSnippet.cc:216
TTAProgram::Address
Definition: Address.hh:51
TTAProgram::Label::setName
void setName(const std::string &name)
Definition: Label.cc:102
Procedure.hh
TTAProgram::CodeLabel::instructionReference
const InstructionReference instructionReference() const
Definition: CodeLabel.cc:117
TTAProgram::InstructionReferenceManager::createReference
InstructionReference createReference(Instruction &ins)
Definition: InstructionReferenceManager.cc:73
TTAProgram::CodeLabel::CodeLabel
CodeLabel(const InstructionReference &ins, std::string name)
Definition: CodeLabel.cc:61
TTAProgram::CodeLabel::ins_
const InstructionReference ins_
Reference to instruction corresponding to this label.
Definition: CodeLabel.hh:63
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
TTAProgram::Label::setAddress
void setAddress(Address address)
Definition: Label.cc:110
TTAProgram::CodeLabel::address
virtual Address address() const
Definition: CodeLabel.cc:101
TTAProgram::Label::setScope
void setScope(const Scope &scope)
Definition: Label.cc:118
GlobalScope.hh
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::CodeLabel::procedure
const Procedure & procedure() const
Definition: CodeLabel.cc:136
TTAProgram::Label::name
std::string name() const
Definition: Label.cc:74
Instruction.hh
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
NullInstruction.hh
TTAProgram::Instruction::parent
CodeSnippet & parent() const
Definition: Instruction.cc:109
TTAProgram::NullInstruction::instance
static NullInstruction & instance()
Definition: NullInstruction.cc:66
TTAProgram::CodeLabel::~CodeLabel
virtual ~CodeLabel()
Definition: CodeLabel.cc:90
TTAProgram::CodeLabel::proc_
const Procedure * proc_
Procedure corresponding to this label.
Definition: CodeLabel.hh:65
IllegalRegistration
Definition: Exception.hh:532
TTAProgram::Program::instructionReferenceManager
InstructionReferenceManager & instructionReferenceManager() const
Definition: Program.cc:688
Program.hh
InstructionReference.hh
TTAProgram::CodeSnippet::parent
virtual Program & parent() const
Definition: CodeSnippet.cc:118
InstructionReferenceManager.hh
TTAProgram::Procedure::name
TCEString name() const
Definition: Procedure.hh:66
TTAProgram::Program::globalScope
GlobalScope & globalScope()
Definition: Program.cc:180
TTAProgram::InstructionReference
Definition: InstructionReference.hh:49
TTAProgram::Procedure
Definition: Procedure.hh:55
CodeLabel.hh
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327