store symbol table as a range

This commit is contained in:
Kelvin Sherlock 2013-08-23 23:04:23 -04:00
parent 53cda5c7b7
commit 9c9decbe3b
4 changed files with 43 additions and 9 deletions

View File

@ -75,7 +75,8 @@ namespace {
AddressMap wbrkMap; // write breaks.
ToolMap tbrkMap; // tool breaks.
std::map<std::string, uint32_t> SymbolTable;
Loader::DebugNameTable SymbolTable;
std::map<std::string, uint16_t> ErrorTable;
std::map<std::string, uint16_t> GlobalTable;
std::map<std::string, uint16_t> TrapTable;
@ -831,16 +832,20 @@ void SetXRegister(unsigned reg, uint32_t value)
}
// todo -- return a range
uint32_t VariableGet(const std::string &s)
{
auto iter = SymbolTable.find(s);
if (iter == SymbolTable.end()) return 0;
return iter->second;
return iter->second.first;
}
// TODO -- take a Token and construct a pair, if it's a range.
// var = expr : expr or var = expr@count
void VariableSet(const std::string &key, uint32_t value)
{
SymbolTable.emplace(key, value);
SymbolTable.emplace(key, std::make_pair(value, 0));
}
void Info(uint32_t address)
@ -848,11 +853,30 @@ void Info(uint32_t address)
// print info on the value.
Print(address);
// 1. as a pointer.
MM::Native::MemoryInfo(address);
// 2. (todo) - check SymbolTable for procedure address.
for (const auto &kv : SymbolTable)
{
const auto &name = kv.first;
auto range = kv.second;
//printf("%s: %x %x\n", name.c_str(), range.first, range.second);
// range end may be 0
if ((address == range.first) || (address >= range.first && address < range.second))
{
uint32_t offset = address - range.first;
if (offset)
printf("Routine: %s+$%x\n", name.c_str(), offset);
else
printf("Routine: %s\n", name.c_str());
break;
}
}
// 2. as a tool trap.
if (address >= 0xa000 && address <= 0xafff)

View File

@ -23,7 +23,9 @@ enum {
// ; commands
kHexdump = 1,
kInfo,
kList
kList,
kBreak,
kTBreak
};
struct Command {
@ -72,6 +74,9 @@ struct Token {
std::string *stringValue;
unsigned subtype;
// unsigned range?
// unsigned modifier?
#if 0
Token& operator=(uint32_t rhs)
@ -82,7 +87,7 @@ struct Token {
return *this;
}
#endif
operator uint32_t() const
{
return intValue;

View File

@ -363,7 +363,7 @@ namespace Loader {
//
void LoadDebugNames(std::map<std::string, uint32_t> &table)
void LoadDebugNames(DebugNameTable &table)
{
if (Segments.empty()) return;
@ -493,7 +493,6 @@ namespace Loader {
continue;
}
table.emplace(std::move(s), start + si.address);
// constant data
@ -504,8 +503,13 @@ namespace Loader {
pc = (pc + length + 1) & ~1;
}
// TODO -- should this include the name and data?
table.emplace(std::move(s), std::make_pair(start + si.address, pc + si.address));
// in case no link instruction...
start = pc;
}
}

View File

@ -8,6 +8,7 @@
namespace Loader {
typedef std::map<std::string, std::pair<uint32_t, uint32_t>> DebugNameTable;
namespace Native {
/*
@ -21,7 +22,7 @@ namespace Loader {
// scans segments for MacsBug debug names.
// associates them with the start of the segment.
void LoadDebugNames(std::map<std::string, uint32_t> &table);
void LoadDebugNames(DebugNameTable &table);
}