Otawa  0.10
File.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * File class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2006-8, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef OTAWA_PROG_FILE_H
23 #define OTAWA_PROG_FILE_H
24 
25 #include <elm/inhstruct/DLList.h>
26 //#include <elm/Collection.h>
27 //#include <elm/datastruct/Map.h>
28 #include <otawa/instruction.h>
29 #include <otawa/prog/Symbol.h>
30 #include <otawa/prog/Segment.h>
31 
32 #include <elm/genstruct/Vector.h>
33 #include <elm/genstruct/HashTable.h>
34 
35 namespace otawa {
36 
37 using namespace elm::genstruct;
38 
39 // Defined classes
40 class ProgItem;
41 
42 // File class
43 class File: public PropList {
48 
49 
50 public:
51  inline File(String name): _name(name) { }
52  inline CString name(void) { return _name.toCString(); }
53  Inst *findInstAt(address_t address);
54  ProgItem *findItemAt(address_t address);
55 
56  // Segment management
57  inline void addSegment(Segment *seg) { segs.add(seg); }
58  Segment *findSegmentAt(Address addr);
59  class SegIter: public Vector<Segment *>::Iterator {
60  public:
61  inline SegIter(const File *file): Vector<Segment *>::Iterator(file->segs) { }
62  inline SegIter(const SegIter& iter): Vector<Segment *>::Iterator(iter) { }
63  };
64 
65  // Symbol management
66  inline void addSymbol(Symbol *sym) { syms.put(sym->name(), sym); }
67  inline void removeSymbol(Symbol *sym) { syms.remove(sym->name()); }
68  address_t findLabel(const String& label);
69  Symbol *findSymbol(String name);
70  class SymIter: public syms_t::Iterator {
71  public:
72  inline SymIter(const File *file): syms_t::Iterator(file->syms) { }
73  inline SymIter(const SymIter& iter): syms_t::Iterator(iter) { }
74  };
75 
76  // Deprecated
77  inline Inst *findByAddress(address_t address) { return findInstAt(address); }
78 
79 protected:
80  friend class Process;
81  ~File(void);
82 };
83 
84 // Properties
87 
88 } // otawa
89 
90 #endif // OTAWA_PROG_FILE_H
Inst * findByAddress(address_t address)
Definition: File.h:77
Definition: File.h:59
CString name(void)
Get the name of the file.
Definition: File.h:52
elm::io::IntFormat address(Address addr)
Build a format to display addresses.
Definition: base.cpp:213
String _name
Definition: File.h:44
In usual file format like ELF, COFF and so on, the program file is divided in segment according platf...
Definition: Segment.h:40
Definition: File.h:70
This class represents a file involved in the building of a process.
Definition: File.h:43
void addSegment(Segment *seg)
Add the given segment to the file.
Definition: File.h:57
SymIter(const File *file)
Build a symbol iterator on the given file.
Definition: File.h:72
Identifier< String > FUNCTION_LABEL
This property is put on instruction.
SegIter(const SegIter &iter)
Copy constructor.
Definition: File.h:62
void addSymbol(Symbol *sym)
Add the given symbol to the file.
Definition: File.h:66
A process is the realization of a program on a platform.
Definition: Process.h:136
The representation of an address in OTAWA.
Definition: base.h:54
Identifier< String > LABEL
Property with this identifier is put on instructions or basic blocks which a symbol is known for...
SegIter(const File *file)
Build a segment iterator on the given file.
Definition: File.h:61
File(String name)
Build a file with the given name.
Definition: File.h:51
HashTable< String, Symbol * > syms_t
Definition: File.h:46
syms_t syms
Definition: File.h:47
This class represents identifier with a typed associated value.
Definition: Identifier.h:51
cstring name
Definition: odisasm.cpp:107
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
This a list of properties.
Definition: PropList.h:63
Vector< Segment * > segs
Definition: File.h:45
SymIter(const SymIter &iter)
Copy constructor.
Definition: File.h:73
const String & name(void) const
Get the name of the symbol.
Definition: Symbol.h:36
Base class of the components of a program file segment.
Definition: ProgItem.h:23
A symbol is a name of a location in a program.
Definition: Symbol.h:21
void removeSymbol(Symbol *sym)
Definition: File.h:67