2 * avr-sim: An atmel AVR simulator
3 * Copyright (C) 2008 Tom Haber
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 const std::string
Program::empty
;
27 void Program::addSymbolFlash(int addr
, const char *name
) {
29 std::cout
<< "Flash Symbol: " << name
<< " (" << std::hex
<< addr
<< std::dec
<< ")" << std::endl
;
31 flashSymbols
.insert( std::make_pair(addr
, name
) );
34 void Program::addSymbolEeprom(int addr
, const char *name
) {
36 std::cout
<< "Eeprom Symbol: " << name
<< " (" << std::hex
<< addr
<< std::dec
<< ")" << std::endl
;
40 void Program::addSymbolRam(int addr
, const char *name
) {
42 std::cout
<< "Ram Symbol: " << name
<< " (" << std::hex
<< addr
<< std::dec
<< ")" << std::endl
;
44 dataSymbols
.insert( std::make_pair(addr
, name
) );
47 const std::string
& Program::functionName(int addr
) const {
48 SymTable::const_iterator it
= flashSymbols
.upper_bound( addr
);
49 if( it
== flashSymbols
.end() )
52 if( it
->first
!= addr
)
60 SymbolFinder(const std::string
& name
) : name(name
) {}
63 bool operator() (const std::pair
<int, std::string
> & p
) {
64 return p
.second
== name
;
68 const std::string
& name
;
71 int Program::functionAddress(const std::string
& name
) const {
72 SymTable::const_iterator it
=
73 std::find_if(flashSymbols
.begin(), flashSymbols
.end(), SymbolFinder(name
) );
75 if( it
== flashSymbols
.end() )
81 int Program::dataAddress(const std::string
& name
) const {
82 SymTable::const_iterator it
=
83 std::find_if(dataSymbols
.begin(), dataSymbols
.end(), SymbolFinder(name
) );
85 if( it
== dataSymbols
.end() )
91 const std::string
& Program::dataName(int addr
) const {
92 SymTable::const_iterator it
= dataSymbols
.upper_bound( addr
);
93 if( it
== dataSymbols
.end() )
96 if( it
->first
!= addr
)