Otawa  0.10
Segment.h
Go to the documentation of this file.
1 /*
2  * otawa::Segment -- program segment class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2003-7, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef OTAWA_PROG_SEGMENT_H
22 #define OTAWA_PROG_SEGMENT_H
23 
24 #include <elm/types.h>
25 #include <elm/PreIterator.h>
26 #include <elm/inhstruct/DLList.h>
27 #include <otawa/prog/ProgItem.h>
28 #include <otawa/prog/Symbol.h>
29 
30 namespace otawa {
31 
32 using namespace elm;
33 
34 // Defined classes
35 class ProgItem;
36 class CodeItem;
37 class Data;
38 
39 // Segment class
40 class Segment: public PropList {
41 public:
42  typedef t::uint32 flags_t;
43  const static flags_t EXECUTABLE = 0x01;
44  const static flags_t WRITABLE = 0x02;
45  const static flags_t INITIALIZED = 0x04;
46 
47  // Constructor
49 
50  // Accessors
51  inline CString name(void) const { return _name; }
52  inline flags_t flags(void) const { return _flags; }
53  inline bool isExecutable(void) const { return _flags & EXECUTABLE; }
54  inline bool isWritable(void) const { return _flags & WRITABLE; }
55  inline bool isInitialized(void) const { return _flags & INITIALIZED; }
56  inline address_t address(void) const { return _address; }
57  inline ot::size size(void) const { return _size; }
58  inline address_t topAddress(void) const { return _address + t::uint32(_size); }
59  ProgItem *findItemAt(const Address& addr);
60  Inst *findInstAt(const Address& addr);
61  inline bool contains(const Address& addr) const { return address() <= addr && addr < topAddress(); }
62 
63  // ItemIter class
64  class ItemIter: public PreIterator<ItemIter, ProgItem *> {
66  public:
67  inline ItemIter(Segment *seg): cur((ProgItem *)seg->items.first())
68  { if(seg->items.isEmpty()) cur = 0; }
69  inline ItemIter(const ItemIter& iter): cur(iter.cur) { }
70  inline ProgItem *item(void) const { return cur; }
71  inline bool ended(void) const { return cur == 0; }
72  inline void next(void) { cur = cur->next(); }
73  };
74 
75 protected:
76  friend class File;
77  virtual Inst *decode(address_t address);
78  virtual ~Segment(void);
79  void insert(ProgItem *item);
80 
81 private:
88 };
89 
90 }; // namespace otawa
91 
92 #endif // OTAWA_PROG_SEGMENT_H
bool isEmpty(void) const
int flags
ItemIter(Segment *seg)
Definition: Segment.h:67
bool isInitialized(void) const
Test if the segment is initialized.
Definition: Segment.h:55
Definition: Segment.h:64
bool isWritable(void) const
Test if the segment is writable.
Definition: Segment.h:54
address_t topAddress(void) const
Definition: Segment.h:58
ProgItem ** map
Definition: Segment.h:87
CString _name
Definition: Segment.h:83
Address _address
Definition: Segment.h:84
uint32 size
elm::io::IntFormat address(Address addr)
Build a format to display addresses.
Definition: base.cpp:213
ot::size _size
Definition: Segment.h:85
In usual file format like ELF, COFF and so on, the program file is divided in segment according platf...
Definition: Segment.h:40
This class represents a file involved in the building of a process.
Definition: File.h:43
bool isExecutable(void) const
Test if the segment is executable.
Definition: Segment.h:53
t::uint32 size
Definition: base.h:46
flags_t flags(void) const
Get flag information about the segment.
Definition: Segment.h:52
The representation of an address in OTAWA.
Definition: base.h:54
bool ended(void) const
Definition: Segment.h:71
t::uint32 flags_t
Definition: Segment.h:42
inhstruct::DLList items
Definition: Segment.h:86
bool contains(const Address &addr) const
Definition: Segment.h:61
ProgItem * item(void) const
Definition: Segment.h:70
ot::size size(void) const
Get the size of the segment.
Definition: Segment.h:57
cstring name
Definition: odisasm.cpp:107
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
void next(void)
Definition: Segment.h:72
This a list of properties.
Definition: PropList.h:63
Base class of the components of a program file segment.
Definition: ProgItem.h:23
ProgItem * cur
Definition: Segment.h:65
ItemIter(const ItemIter &iter)
Definition: Segment.h:69
address_t address(void) const
Get the base address of the segment.
Definition: Segment.h:56
CString name(void) const
Get tne name of the segment.
Definition: Segment.h:51
uint32_t uint32
flags_t _flags
Definition: Segment.h:82