OpenASIP 2.2
Loading...
Searching...
No Matches
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
41namespace TTAMachine {
42 class AddressSpace;
43}
44
45namespace 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 */
60public:
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;
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
119protected:
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
Word UIntWord
Definition BaseType.hh:144
UInt32 InstructionAddress
Definition BaseType.hh:175
virtual Instruction & nextInstruction(const Instruction &ins) const
virtual void addFront(Instruction *ins)
virtual Instruction & previousInstruction(const Instruction &ins) const
virtual void setParent(Program &prog)
Address endAddr_
The highest address of the procedure.
InsList::iterator InsIter
Iterator for the instruction list.
virtual Address endAddress() const
Address startAddr_
The start (lowest) address of the procedure.
virtual Instruction & firstInstruction() const
virtual bool isInProgram() const
virtual void append(const CodeSnippet &cs)
virtual void insertAfter(const Instruction &pos, Instruction *ins)
virtual std::string toString() const
Program * parent_
The parent program of the procedure.
virtual Address address(const Instruction &ins) const
virtual void add(Instruction *ins)
virtual void prepend(const CodeSnippet &cs)
virtual int instructionCount() const
virtual std::string disassembly() const
virtual void setStartAddress(Address start)
virtual Instruction & instructionAt(UIntWord address) const
virtual void remove(Instruction &ins)
InsList instructions_
The instructions in this procedure.
virtual CodeSnippet * copy() const
virtual void deleteInstructionAt(InstructionAddress address)
virtual Program & parent() const
virtual void removeLastInstruction()
virtual Address startAddress() const
virtual void insertBefore(const Instruction &pos, Instruction *ins)
virtual Instruction & lastInstruction() const
virtual void setEndAddress(Address end)
virtual Instruction & instructionAtIndex(int index) const
std::vector< Instruction * > InsList
List of instructions.
virtual Instruction & operator[](size_t index) const
virtual bool hasNextInstruction(const Instruction &ins) const