Bug fix: check if vm exists
[avr-sim.git] / Program.h
blobb59f75fcb06ada82106d6aa36ebeb6caed844038
1 #ifndef AVR_PROGRAM_H
2 #define AVR_PROGRAM_H
4 #include <string>
5 #include <map>
7 namespace avr {
9 class Section {
10 public:
11 enum Type { NONE, FLASH, EEPROM } type;
12 Section() : type(NONE), addr(0), siz(0), d(0) {}
13 Section(Type type, int address, int size);
14 ~Section();
16 public:
17 void init(Type type, int address, int size);
18 void clear();
20 public:
21 unsigned char *data() { return d; }
22 int size() const { return siz; }
23 int address() const { return addr; }
24 bool isFlash() const { return type == FLASH; }
25 bool isEeprom() const { return type == EEPROM; }
27 private:
28 int addr;
29 int siz;
30 unsigned char *d;
33 class Program {
34 public:
35 virtual ~Program() {}
37 public:
38 virtual void load(const char * filename) = 0;
39 virtual bool readNextSection(Section & sec) const = 0;
40 const std::string & functionName(int addr) const;
42 protected:
43 void addSymbolFlash(int addr, const char *name);
44 void addSymbolEeprom(int addr, const char *name);
45 void addSymbolRam(int addr, const char *name);
47 private:
48 typedef std::map<int, std::string> SymTable;
49 SymTable symbols;
52 inline Section::Section(Type type, int address, int size) {
53 init( type, address, size );
56 inline Section::~Section() {
57 clear();
60 inline void Section::init(Type type, int address, int size) {
61 this->type = type;
62 this->addr = address;
63 this->siz = size;
65 this->d = new unsigned char[size];
68 inline void Section::clear() {
69 if( d != 0 ) {
70 delete [] d;
71 d = 0;
74 addr = 0;
75 siz = 0;
76 type = NONE;
81 #endif /*AVR_PROGRAM_H*/