OpenASIP  2.0
CodeSnippet.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 CodeSnippet.hh
26  *
27  * Declaration of CodeSnippet class.
28  *
29  * @author Ari Metsähalme 2005 (ari.metsahalme-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_CODESNIPPET_HH
34 #define TTA_CODESNIPPET_HH
35 
36 #include <vector>
37 
38 #include "Exception.hh"
39 #include "Address.hh"
40 
41 namespace TTAMachine {
42  class AddressSpace;
43 }
44 
45 namespace TTAProgram {
46  class Program;
47  class Instruction;
48  class Address;
49 
50 /**
51  * A code snippet is an ordered sequence of adjacent instructions.
52  *
53  * It is a helper class for representing pieces of code that are not
54  * necessarily full procedures, for example basic blocks. Code snippet
55  * doesn't care, whether the sequence of instructions in it makes sense
56  * or not. That's the responsibility of the client that created the
57  * snippet.
58  */
59 class CodeSnippet {
60 public:
61  CodeSnippet();
62  CodeSnippet(const TTAProgram::Address& start);
63 
64  virtual ~CodeSnippet();
65 
66  virtual void clear();
67 
68  virtual void removeLastInstruction();
69  virtual int instructionCount() const;
70 
71  virtual Program& parent() const;
72  virtual void setParent(Program& prog);
73  virtual bool isInProgram() const;
74 
75  virtual Address address(const Instruction& ins) const;
76 
77  virtual Address startAddress() const;
78  virtual void setStartAddress(Address start);
79  virtual Address endAddress() const;
80  virtual void setEndAddress(Address end);
81 
82  virtual Instruction& firstInstruction() const;
83  virtual Instruction& instructionAt(UIntWord address) const;
84 
85  virtual Instruction& instructionAtIndex(int index) const;
86  virtual Instruction& operator[](size_t index) const;
87 
88  virtual bool hasNextInstruction(const Instruction& ins) const;
89  virtual Instruction& nextInstruction(const Instruction& ins) const;
90  virtual Instruction& previousInstruction(const Instruction& ins) const;
91  virtual Instruction& lastInstruction() const;
92 
93  virtual void addFront(Instruction* ins);
94  virtual void add(Instruction* ins);
95  virtual void insertAfter(const Instruction& pos, Instruction* ins);
96  virtual void insertBefore(const Instruction& pos, Instruction* ins);
97 
98  virtual void remove(Instruction& ins);
99 
101 
102  virtual CodeSnippet* copy() const;
103 
104  virtual void prepend(const CodeSnippet& cs);
105  virtual void prepend(CodeSnippet* cs);
106  virtual void append(const CodeSnippet& cs);
107  virtual void append(CodeSnippet* cs);
108 
109  virtual void insertBefore(const Instruction& pos, const CodeSnippet& cs);
110  virtual void insertBefore(const Instruction& pos, CodeSnippet* cs);
111  virtual void insertAfter(const Instruction& pos, const CodeSnippet& cs);
112  virtual void insertAfter(const Instruction& pos, CodeSnippet* cs);
113 
114  bool hasReturn() const;
115 
116  virtual std::string disassembly() const;
117  virtual std::string toString() const { return disassembly(); }
118 
119 protected:
120  /// List of instructions.
121  typedef std::vector<Instruction*> InsList;
122  /// Iterator for the instruction list.
123  typedef InsList::iterator InsIter;
124 
125  /// The instructions in this procedure.
127  /// The parent program of the procedure.
129  /// The start (lowest) address of the procedure.
131  /// The highest address of the procedure.
133 
134 };
135 
136 }
137 
138 #endif
TTAProgram
Definition: Estimator.hh:65
UIntWord
Word UIntWord
Definition: BaseType.hh:144
TTAProgram::Program
Definition: Program.hh:63
TTAProgram::CodeSnippet::endAddr_
Address endAddr_
The highest address of the procedure.
Definition: CodeSnippet.hh:132
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
TTAProgram::CodeSnippet::firstInstruction
virtual Instruction & firstInstruction() const
Definition: CodeSnippet.cc:216
TTAProgram::CodeSnippet::append
virtual void append(const CodeSnippet &cs)
Definition: CodeSnippet.cc:711
TTAProgram::CodeSnippet::setParent
virtual void setParent(Program &prog)
Definition: CodeSnippet.cc:136
TTAProgram::Address
Definition: Address.hh:51
Exception.hh
TTAProgram::CodeSnippet::clear
virtual void clear()
Definition: CodeSnippet.cc:89
TTAProgram::CodeSnippet::setEndAddress
virtual void setEndAddress(Address end)
Definition: CodeSnippet.cc:195
TTAProgram::CodeSnippet::insertBefore
virtual void insertBefore(const Instruction &pos, Instruction *ins)
Definition: CodeSnippet.cc:514
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::CodeSnippet::deleteInstructionAt
virtual void deleteInstructionAt(InstructionAddress address)
Definition: CodeSnippet.cc:593
TTAProgram::CodeSnippet::removeLastInstruction
virtual void removeLastInstruction()
Definition: CodeSnippet.cc:104
TTAProgram::CodeSnippet::remove
virtual void remove(Instruction &ins)
Definition: CodeSnippet.cc:558
TTAProgram::CodeSnippet::nextInstruction
virtual Instruction & nextInstruction(const Instruction &ins) const
Definition: CodeSnippet.cc:318
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
TTAProgram::CodeSnippet::setStartAddress
virtual void setStartAddress(Address start)
Definition: CodeSnippet.cc:190
TTAProgram::CodeSnippet::disassembly
virtual std::string disassembly() const
Definition: CodeSnippet.cc:820
TTAProgram::CodeSnippet::~CodeSnippet
virtual ~CodeSnippet()
Definition: CodeSnippet.cc:73
TTAProgram::CodeSnippet::prepend
virtual void prepend(const CodeSnippet &cs)
Definition: CodeSnippet.cc:748
TTAProgram::CodeSnippet::hasReturn
bool hasReturn() const
Definition: CodeSnippet.cc:804
TTAProgram::CodeSnippet::insertAfter
virtual void insertAfter(const Instruction &pos, Instruction *ins)
Definition: CodeSnippet.cc:462
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
TTAProgram::CodeSnippet::add
virtual void add(Instruction *ins)
Definition: CodeSnippet.cc:432
TTAProgram::CodeSnippet::operator[]
virtual Instruction & operator[](size_t index) const
Definition: CodeSnippet.cc:290
TTAProgram::CodeSnippet::InsIter
InsList::iterator InsIter
Iterator for the instruction list.
Definition: CodeSnippet.hh:123
TTAProgram::CodeSnippet::previousInstruction
virtual Instruction & previousInstruction(const Instruction &ins) const
Definition: CodeSnippet.cc:352
TTAProgram::CodeSnippet::hasNextInstruction
virtual bool hasNextInstruction(const Instruction &ins) const
Definition: CodeSnippet.cc:303
TTAProgram::CodeSnippet::lastInstruction
virtual Instruction & lastInstruction() const
Definition: CodeSnippet.cc:387
TTAProgram::CodeSnippet::copy
virtual CodeSnippet * copy() const
Definition: CodeSnippet.cc:608
TTAProgram::CodeSnippet
Definition: CodeSnippet.hh:59
TTAProgram::CodeSnippet::addFront
virtual void addFront(Instruction *ins)
Definition: CodeSnippet.cc:406
TTAProgram::CodeSnippet::address
virtual Address address(const Instruction &ins) const
Definition: CodeSnippet.cc:163
Address.hh
TTAProgram::CodeSnippet::parent
virtual Program & parent() const
Definition: CodeSnippet.cc:118
TTAProgram::CodeSnippet::parent_
Program * parent_
The parent program of the procedure.
Definition: CodeSnippet.hh:128
TTAProgram::CodeSnippet::endAddress
virtual Address endAddress() const
Definition: CodeSnippet.cc:788
TTAProgram::CodeSnippet::instructionAtIndex
virtual Instruction & instructionAtIndex(int index) const
Definition: CodeSnippet.cc:285
TTAProgram::CodeSnippet::toString
virtual std::string toString() const
Definition: CodeSnippet.hh:117
TTAProgram::CodeSnippet::instructionAt
virtual Instruction & instructionAt(UIntWord address) const
Definition: CodeSnippet.cc:241
TTAMachine
Definition: Assembler.hh:48
TTAProgram::CodeSnippet::instructions_
InsList instructions_
The instructions in this procedure.
Definition: CodeSnippet.hh:126
TTAProgram::CodeSnippet::startAddr_
Address startAddr_
The start (lowest) address of the procedure.
Definition: CodeSnippet.hh:130
TTAProgram::CodeSnippet::InsList
std::vector< Instruction * > InsList
List of instructions.
Definition: CodeSnippet.hh:121
TTAProgram::CodeSnippet::CodeSnippet
CodeSnippet()
Definition: CodeSnippet.cc:55
TTAProgram::CodeSnippet::isInProgram
virtual bool isInProgram() const
Definition: CodeSnippet.cc:151