Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Program.h
blob95e0bf6168e775f72138faa99f1ee8711c579f4f
1 #ifndef AVR_PROGRAM_H
2 #define AVR_PROGRAM_H
4 #include <string>
5 #include <map>
7 namespace avr {
9 /**
10 * @author Tom Haber
11 * @date May 13, 2008
12 * @brief Abstraction of program file formats
14 * A single section of the program. Contains the data
15 * associated with a specific address range and location (Flash or Eeprom)
17 class Section {
18 public:
19 enum Type { NONE, FLASH, EEPROM };
20 Section() : type(NONE), addr(0), siz(0), d(0) {}
21 Section(Type type, unsigned int address, unsigned int size);
22 ~Section();
24 public:
25 void init(Type type, unsigned int address, unsigned int size);
26 void clear();
28 public:
29 unsigned char *data() { return d; }
30 unsigned int size() const { return siz; }
31 unsigned int address() const { return addr; }
32 bool isFlash() const { return type == FLASH; }
33 bool isEeprom() const { return type == EEPROM; }
35 private:
36 Type type;
37 unsigned int addr;
38 unsigned int siz;
39 unsigned char *d;
42 /**
43 * @author Tom Haber
44 * @date May 23, 2008
45 * @brief Abstraction of a Program
47 * Abstraction of a Program, contains methods for
48 * loading files and reading sections.
49 * Additionally, it stores the symbols with the program
50 * and has convenient lookup functions for flash and data
51 * symbols.
53 class Program {
54 public:
55 virtual ~Program() {}
57 public:
58 /**
59 * Opens and loads a file.
61 virtual void load(const char * filename) = 0;
63 /**
64 * Reads the next available section from the file
65 * and returns the data in \e sec.
67 * \returns false if no further sections are available.
69 virtual bool readNextSection(Section & sec) = 0;
71 public:
72 const std::string & functionName(int addr) const;
73 const std::string & dataName(int addr) const;
75 int functionAddress(const std::string & name) const;
76 int dataAddress(const std::string & name) const;
78 protected:
79 void addSymbolFlash(int addr, const char *name);
80 void addSymbolEeprom(int addr, const char *name);
81 void addSymbolRam(int addr, const char *name);
83 private:
84 typedef std::map<int, std::string> SymTable;
85 SymTable flashSymbols;
86 SymTable dataSymbols;
88 static const std::string empty;
91 inline Section::Section(Type type, unsigned int address, unsigned int size) {
92 init( type, address, size );
95 inline Section::~Section() {
96 clear();
99 inline void Section::init(Type type, unsigned int address, unsigned int size) {
100 this->type = type;
101 this->addr = address;
102 this->siz = size;
104 this->d = new unsigned char[size];
107 inline void Section::clear() {
108 if( d != 0 ) {
109 delete [] d;
110 d = 0;
113 addr = 0;
114 siz = 0;
115 type = NONE;
120 #endif /*AVR_PROGRAM_H*/