OpenASIP  2.0
Scope.hh
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 Scope.hh
26  *
27  * Declaration of Scope class.
28  *
29  * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_SCOPE_HH
34 #define TTA_SCOPE_HH
35 
36 #include <string>
37 #include <vector>
38 
39 #include "Address.hh"
40 #include "Exception.hh"
41 
42 namespace TTAProgram {
43 
44 class CodeLabel;
45 class DataLabel;
46 
47 /**
48  * Scopes provide containers for different visibility level labels.
49  *
50  * @todo Implement rest of the Scopes (only GlobalScope is supported
51  * currently).
52  */
53 class Scope {
54 public:
55  Scope();
56  virtual ~Scope();
57 
58  virtual bool isGlobal() const;
59  virtual bool isUnit() const;
60  virtual bool isProcedure() const;
61  virtual bool isLocal() const;
62 
63  bool containsCodeLabel(const std::string& name) const;
64  bool containsDataLabel(const std::string& name) const;
65 
66  const CodeLabel& codeLabel(const std::string& name) const;
67  const DataLabel& dataLabel(const std::string& name) const;
68 
69  int codeLabelCount(Address address) const;
70  const CodeLabel& codeLabel(Address address, int index) const;
71 
72  int dataLabelCount(Address address) const;
73  const DataLabel& dataLabel(Address address, int index) const;
74 
75  virtual void addCodeLabel(const CodeLabel* codeLabel);
76  virtual void addDataLabel(const DataLabel* dataLabel);
77  virtual void removeCodeLabels(InstructionAddress address);
78 
79  virtual Scope* copy() const = 0;
80 
81 protected:
82  /// List for child scopes.
83  typedef std::vector<const Scope*> ScopeList;
84  /// Child scopes.
86 
87  /// List of data labels.
88  typedef std::vector<const DataLabel*> DataLabelList;
89  /// List of code labels.
90  typedef std::vector<const CodeLabel*> CodeLabelList;
91 
92  /// Data labels contained by this scope.
94  /// Code labels contained by this scope.
96 
97  /// Adds a code label and its owner to the global label bookkeeping.
98  ///
99  /// @param dataLabel The code label to be added.
100  /// @param owner The owner scope of the label.
101  virtual void addGlobalCodeLabel(
102  const CodeLabel& codeLabel, const Scope& owner) = 0;
103 
104  /// Adds a data label and its owner to the global label bookkeeping.
105  ///
106  /// @param dataLabel The data label to be added.
107  /// @param owner The owner scope of the label.
108  virtual void addGlobalDataLabel(
109  const DataLabel& dataLabel, const Scope& owner) = 0;
110 
111  Scope& parent() const;
112  void setParent(Scope& scope);
113 
114  int childCount() const;
115  void addChild(const Scope& scope);
116  const Scope& child(int index) const;
117 
118 private:
119  /// Copying not allowed.
120  Scope(const Scope&);
121  /// Assignment not allowed.
122  Scope& operator=(const Scope&);
123 
124  /// The smallest outer scope that contains this scope.
126 };
127 
128 }
129 
130 #endif
TTAProgram
Definition: Estimator.hh:65
TTAProgram::Scope::codeLabel
const CodeLabel & codeLabel(const std::string &name) const
Definition: Scope.cc:233
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
TTAProgram::Address
Definition: Address.hh:51
TTAProgram::Scope::parent
Scope & parent() const
Definition: Scope.cc:132
TTAProgram::Scope::dataLabelCount
int dataLabelCount(Address address) const
Definition: Scope.cc:323
TTAProgram::Scope::addDataLabel
virtual void addDataLabel(const DataLabel *dataLabel)
Definition: Scope.cc:415
Exception.hh
TTAProgram::Scope::codeLabels_
CodeLabelList codeLabels_
Code labels contained by this scope.
Definition: Scope.hh:95
TTAProgram::Scope::parent_
Scope * parent_
The smallest outer scope that contains this scope.
Definition: Scope.hh:125
TTAProgram::Scope::isProcedure
virtual bool isProcedure() const
Definition: Scope.cc:92
TTAProgram::Scope::dataLabels_
DataLabelList dataLabels_
Data labels contained by this scope.
Definition: Scope.hh:93
TTAProgram::Scope::isLocal
virtual bool isLocal() const
Definition: Scope.cc:102
TTAProgram::Scope
Definition: Scope.hh:53
TTAProgram::Scope::addChild
void addChild(const Scope &scope)
Definition: Scope.cc:114
TTAProgram::Scope::Scope
Scope()
Definition: Scope.cc:48
TTAProgram::Scope::addCodeLabel
virtual void addCodeLabel(const CodeLabel *codeLabel)
Definition: Scope.cc:376
TTAProgram::Scope::addGlobalDataLabel
virtual void addGlobalDataLabel(const DataLabel &dataLabel, const Scope &owner)=0
Adds a data label and its owner to the global label bookkeeping.
TTAProgram::Scope::isUnit
virtual bool isUnit() const
Definition: Scope.cc:82
TTAProgram::DataLabel
Definition: DataLabel.hh:45
TTAProgram::Scope::isGlobal
virtual bool isGlobal() const
Definition: Scope.cc:72
TTAProgram::CodeLabel
Definition: CodeLabel.hh:49
TTAProgram::Scope::setParent
void setParent(Scope &scope)
Definition: Scope.cc:152
TTAProgram::Scope::removeCodeLabels
virtual void removeCodeLabels(InstructionAddress address)
Definition: Scope.cc:451
TTAProgram::Scope::copy
virtual Scope * copy() const =0
TTAProgram::Scope::~Scope
virtual ~Scope()
Definition: Scope.cc:54
TTAProgram::Scope::DataLabelList
std::vector< const DataLabel * > DataLabelList
List of data labels.
Definition: Scope.hh:88
TTAProgram::Scope::CodeLabelList
std::vector< const CodeLabel * > CodeLabelList
List of code labels.
Definition: Scope.hh:90
TTAProgram::Scope::ScopeList
std::vector< const Scope * > ScopeList
List for child scopes.
Definition: Scope.hh:83
Address.hh
TTAProgram::Scope::child
const Scope & child(int index) const
Definition: Scope.cc:184
TTAProgram::Scope::addGlobalCodeLabel
virtual void addGlobalCodeLabel(const CodeLabel &codeLabel, const Scope &owner)=0
Adds a code label and its owner to the global label bookkeeping.
TTAProgram::Scope::dataLabel
const DataLabel & dataLabel(const std::string &name) const
Definition: Scope.cc:251
TTAProgram::Scope::operator=
Scope & operator=(const Scope &)
Assignment not allowed.
TTAProgram::Scope::containsCodeLabel
bool containsCodeLabel(const std::string &name) const
Definition: Scope.cc:199
TTAProgram::Scope::codeLabelCount
int codeLabelCount(Address address) const
Definition: Scope.cc:269
TTAProgram::Scope::containsDataLabel
bool containsDataLabel(const std::string &name) const
Definition: Scope.cc:215
TTAProgram::Scope::children_
ScopeList children_
Child scopes.
Definition: Scope.hh:85
TTAProgram::Scope::childCount
int childCount() const
Definition: Scope.cc:171