OpenASIP  2.0
InstructionReferenceManager.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 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 InstructionReferenceManager.hh
26  *
27  * Declaration of InstructionReferenceManager class.
28  *
29  * The instruction reference handles references to instructions.
30  *
31  * The design consists of 3 classes:
32  *
33  * InstructionReferenceManager: a single high-level object. Contains the
34  * external interface, maps to locate a reference to an instruction
35  * based on instruction, and ways to iterate over all instruction references.
36  *
37  * InstructionReference: The class which is shown to a client. Encapsulates
38  * a reference into a single instruction. Multiple InstructionReferences
39  * may point to a single instruction and these can be freely copied etc.
40  * You should not use pointers to these classes, but always copy your
41  * existing objects with copy constructor/assignment into the new one when
42  * returning from functions etc.
43  *
44  * InstructionReferenceImpl: This is internal intermediate implementation
45  * class. It is not shown to the user. There is always exactly one
46  * InstructionReferenceImpl per target instruction.
47  * If two instruction references that originally pointed to different
48  * instructions (and so had different InstructionReferenceImpl objects),
49  * these objects are automatically merged and all the internal pointers
50  * and bookkeeping updated accordingly.
51  *
52  * Multiple instructionreferences typically point to InstructionReferenceImpl,
53  * and instructionReferenceImpl contains pointers to all of these, so it
54  * can notify them in case the instructionReferenceImpl is merged with
55  * another.
56  *
57  * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
58  * @author Heikki Kultala 2009 (heikki.kultala-no.spam-tut.fi)
59  * @note rating: red
60  */
61 
62 #ifndef TTA_INSTRUCTION_REFERENCE_MANAGER_HH
63 #define TTA_INSTRUCTION_REFERENCE_MANAGER_HH
64 
65 #include <map>
66 #include "Exception.hh"
68 
69 namespace TTAProgram {
70 
71 class Instruction;
72 class InstructionReference;
73 class InstructionReferenceImpl;
74 
75 /**
76  * Helps in keeping instructions referenced in POM up-to-date.
77  *
78  * Instructions are not referenced directly, but through an
79  * InstructionReference instance. The actual Instruction instance
80  * referred can be changed as needed.
81  */
83 public:
84  /// Map for instruction references. faster to search than list.
85  typedef std::map<Instruction*, InstructionReferenceImpl*> RefMap;
86 
89 
91  void replace(Instruction& insA, Instruction& insB);
92  void clearReferences();
93  bool hasReference(Instruction& ins) const;
94  unsigned int referenceCount(Instruction& ins) const;
95  void referenceDied(Instruction* ins);
96 
97  void validate();
98 
99  class Iterator {
100  public:
101  inline Iterator& operator++(); // ++i
102  inline const InstructionReference& operator*() const;
103  inline const InstructionReference* operator->() const;
104  inline bool operator !=(const Iterator& i) const;
105  inline Iterator(RefMap::iterator iter);
106  inline Iterator(RefMap::iterator& iter);
107  private:
108  RefMap::iterator iter_;
109  };
110 
111  inline Iterator begin();
112  inline Iterator end();
113 
114 private:
115  // disable copying and assignment.
118 
119  /// Instruction references to maintain.
121 
122 };
123 
125 
126 }
127 
128 
129 #endif
TTAProgram
Definition: Estimator.hh:65
TTAProgram::InstructionReferenceManager::end
Iterator end()
Exception.hh
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::InstructionReferenceManager::references_
RefMap references_
Instruction references to maintain.
Definition: InstructionReferenceManager.hh:120
TTAProgram::InstructionReferenceManager::createReference
InstructionReference createReference(Instruction &ins)
Definition: InstructionReferenceManager.cc:73
TTAProgram::InstructionReferenceManager::InstructionReferenceManager
InstructionReferenceManager()
Definition: InstructionReferenceManager.cc:54
TTAProgram::InstructionReferenceManager::validate
void validate()
Definition: InstructionReferenceManager.cc:181
TTAProgram::InstructionReferenceManager::clearReferences
void clearReferences()
Definition: InstructionReferenceManager.cc:125
TTAProgram::InstructionReferenceManager::Iterator::Iterator
Iterator(RefMap::iterator iter)
TTAProgram::InstructionReferenceManager::Iterator::operator!=
bool operator!=(const Iterator &i) const
InstructionReferenceImpl.hh
TTAProgram::InstructionReferenceManager::Iterator::iter_
RefMap::iterator iter_
Definition: InstructionReferenceManager.hh:108
TTAProgram::InstructionReferenceManager::~InstructionReferenceManager
virtual ~InstructionReferenceManager()
Definition: InstructionReferenceManager.cc:60
TTAProgram::InstructionReferenceManager::hasReference
bool hasReference(Instruction &ins) const
Definition: InstructionReferenceManager.cc:143
TTAProgram::InstructionReferenceManager::replace
void replace(Instruction &insA, Instruction &insB)
Definition: InstructionReferenceManager.cc:96
TTAProgram::InstructionReferenceManager::referenceCount
unsigned int referenceCount(Instruction &ins) const
Definition: InstructionReferenceManager.cc:151
TTAProgram::InstructionReferenceManager::operator=
InstructionReferenceManager & operator=(const InstructionReferenceManager &)
TTAProgram::InstructionReferenceManager
Definition: InstructionReferenceManager.hh:82
InstructionReferenceManager.icc
TTAProgram::InstructionReferenceManager::RefMap
std::map< Instruction *, InstructionReferenceImpl * > RefMap
Map for instruction references. faster to search than list.
Definition: InstructionReferenceManager.hh:85
TTAProgram::InstructionReferenceManager::Iterator::operator++
Iterator & operator++()
TTAProgram::InstructionReferenceManager::referenceDied
void referenceDied(Instruction *ins)
Definition: InstructionReferenceManager.cc:165
TTAProgram::InstructionReferenceManager::begin
Iterator begin()
TTAProgram::InstructionReferenceManager::Iterator::operator->
const InstructionReference * operator->() const
TTAProgram::InstructionReference
Definition: InstructionReference.hh:49
TTAProgram::InstructionReferenceManager::Iterator::operator*
const InstructionReference & operator*() const
TTAProgram::InstructionReferenceManager::Iterator
Definition: InstructionReferenceManager.hh:99