Cleaned up the EquateList API a little, in preparation for enhanced

symbol support.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1495 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2008-05-01 23:08:24 +00:00
parent 35ac942cc8
commit 43d64f7eec
5 changed files with 162 additions and 190 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Debugger.cxx,v 1.123 2008-04-19 21:11:52 stephena Exp $ // $Id: Debugger.cxx,v 1.124 2008-05-01 23:08:24 stephena Exp $
//============================================================================ //============================================================================
#include "bspf.hxx" #include "bspf.hxx"
@ -678,7 +678,7 @@ string Debugger::showWatches()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Debugger::addLabel(string label, int address) void Debugger::addLabel(string label, int address)
{ {
myEquateList->addEquate(label, address); myEquateList->addEquate(label, address, EQF_USER);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: DebuggerParser.cxx,v 1.105 2008-04-19 21:11:52 stephena Exp $ // $Id: DebuggerParser.cxx,v 1.106 2008-05-01 23:08:24 stephena Exp $
//============================================================================ //============================================================================
#include <fstream> #include <fstream>
@ -1302,7 +1302,7 @@ void DebuggerParser::executeTrapwrite()
// "undef" // "undef"
void DebuggerParser::executeUndef() void DebuggerParser::executeUndef()
{ {
if(debugger->equates().undefine(argStrings[0])) if(debugger->equates().removeEquate(argStrings[0]))
{ {
debugger->myRom->invalidate(); debugger->myRom->invalidate();
commandResult = argStrings[0] + " now undefined"; commandResult = argStrings[0] + " now undefined";

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EquateList.cxx,v 1.28 2008-04-02 01:54:31 stephena Exp $ // $Id: EquateList.cxx,v 1.29 2008-05-01 23:08:24 stephena Exp $
//============================================================================ //============================================================================
#include <fstream> #include <fstream>
@ -210,7 +210,6 @@ EquateList::EquateList()
myFwdMap.insert(make_pair(e.label, e)); myFwdMap.insert(make_pair(e.label, e));
myRevMap.insert(make_pair(e.address, e)); myRevMap.insert(make_pair(e.address, e));
} }
calcSize();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -221,73 +220,22 @@ EquateList::~EquateList()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EquateList::calcSize() void EquateList::addEquate(const string& label, int address, const int flags)
{ {
currentSize = myFwdMap.size(); Equate e;
return currentSize; e.label = label;
e.address = address;
e.flags = flags;
removeEquate(label);
myFwdMap.insert(make_pair(label, e));
myRevMap.insert(make_pair(address, e));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// DEPRECATED bool EquateList::removeEquate(const string& label)
const string& EquateList::getLabel(int addr)
{ {
return getLabel(addr, EQF_ANY); LabelToAddr::iterator iter = myFwdMap.find(label);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string& EquateList::getLabel(int addr, int flags)
{
addrToLabel::const_iterator iter = myRevMap.find(addr);
if(iter != myRevMap.end())
{
// FIXME - until we fix the issue of correctly setting the equate
// flags to something other than 'EQF_ANY' by default,
// this comparison will almost always fail
if(1)//flags == EQF_ANY || iter->second.flags & flags)
return iter->second.label;
}
return EmptyString;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// DEPRECATED
string EquateList::getFormatted(int addr, int places)
{
return getFormatted(addr, places, EQF_ANY);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// returns either the label, or a formatted hex string
// if no label found.
string EquateList::getFormatted(int addr, int places, int flags)
{
char fmt[10], buf[255];
const string& label = getLabel(addr, flags);
if(label != "")
return label;
sprintf(fmt, "$%%0%dx", places);
sprintf(buf, fmt, addr);
return buf;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EquateList::getAddress(const string& label)
{
labelToAddr::const_iterator iter = myFwdMap.find(label);
if(iter == myFwdMap.end())
return -1;
else
return iter->second.address;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EquateList::undefine(const string& label)
{
labelToAddr::iterator iter = myFwdMap.find(label);
if(iter == myFwdMap.end()) if(iter == myFwdMap.end())
{ {
return false; return false;
@ -303,26 +251,44 @@ bool EquateList::undefine(const string& label)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EquateList::saveFile(const string& file) const string& EquateList::getLabel(int addr, const int flags)
{ {
char buf[256]; AddrToLabel::const_iterator iter = myRevMap.find(addr);
ofstream out(file.c_str()); if(iter != myRevMap.end())
if(!out.is_open())
return false;
out << "--- Symbol List (sorted by symbol)" << endl;
labelToAddr::iterator iter;
for(iter = myFwdMap.begin(); iter != myFwdMap.end(); iter++)
{ {
sprintf(buf, "%-24s %04x \n", iter->second.label.c_str(), iter->second.address); // FIXME - until we fix the issue of correctly setting the equate
out << buf; // flags to something other than 'EQF_ANY' by default,
// this comparison will almost always fail
if(1)//flags == EQF_ANY || iter->second.flags & flags)
return iter->second.label;
}
return EmptyString;
} }
out << "--- End of Symbol List." << endl; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string EquateList::getFormatted(int addr, int places, const int flags)
{
char fmt[10], buf[255];
const string& label = getLabel(addr, flags);
return true; if(label != "")
return label;
sprintf(fmt, "$%%0%dx", places);
sprintf(buf, fmt, addr);
return buf;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EquateList::getAddress(const string& label, const int flags)
{
LabelToAddr::const_iterator iter = myFwdMap.find(label);
if(iter == myFwdMap.end())
return -1;
else
return iter->second.address;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -356,7 +322,9 @@ string EquateList::loadFile(const string& file)
if((curVal = extractValue(line)) < 0) if((curVal = extractValue(line)) < 0)
return "invalid symbol file"; return "invalid symbol file";
addEquate(curLabel, curVal); // For now, just make this equate EQF_ANY
// At some point, we should do some analysis to figure out its real type
addEquate(curLabel, curVal, EQF_ANY);
lines++; lines++;
} }
@ -368,40 +336,77 @@ string EquateList::loadFile(const string& file)
} }
in.close(); in.close();
calcSize(); // calcSize();
return "loaded " + file + " OK"; return "loaded " + file + " OK";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EquateList::addEquate(const string& label, int address) bool EquateList::saveFile(const string& file)
{ {
Equate e; char buf[256];
e.label = label;
e.address = address;
e.flags = EQF_ANY; // FIXME - this should be specified as a parameter
undefine(label); ofstream out(file.c_str());
myFwdMap.insert(make_pair(label, e)); if(!out.is_open())
myRevMap.insert(make_pair(address, e)); return false;
out << "--- Symbol List (sorted by symbol)" << endl;
LabelToAddr::iterator iter;
for(iter = myFwdMap.begin(); iter != myFwdMap.end(); iter++)
{
sprintf(buf, "%-24s %04x \n", iter->second.label.c_str(), iter->second.address);
out << buf;
}
out << "--- End of Symbol List." << endl;
return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EquateList::parse4hex(char *c) int EquateList::countCompletions(const char *in)
{ {
int ret = 0; int count = 0;
for(int i=0; i<4; i++) myCompletions = myCompPrefix = "";
LabelToAddr::iterator iter;
for(iter = myFwdMap.begin(); iter != myFwdMap.end(); iter++)
{ {
if(*c >= '0' && *c <= '9') const char *l = iter->first.c_str();
ret = (ret << 4) + (*c) - '0';
else if(*c >= 'a' && *c <= 'f') if(BSPF_strncasecmp(l, in, strlen(in)) == 0)
ret = (ret << 4) + (*c) - 'a' + 10; {
if(myCompPrefix == "")
myCompPrefix += l;
else else
return -1; {
int nonMatch = 0;
const char *c = myCompPrefix.c_str();
while(*c != '\0' && tolower(*c) == tolower(l[nonMatch]))
{
c++; c++;
nonMatch++;
}
myCompPrefix.erase(nonMatch, myCompPrefix.length());
} }
return ret; if(count++) myCompletions += " ";
myCompletions += l;
}
}
return count;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string EquateList::extractLabel(char *c)
{
string l = "";
while(*c != ' ')
l += *c++;
return l;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -421,62 +426,16 @@ int EquateList::extractValue(char *c)
c++; c++;
} }
return parse4hex(c); int ret = 0;
} for(int i=0; i<4; i++)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string EquateList::extractLabel(char *c)
{ {
string l = ""; if(*c >= '0' && *c <= '9')
while(*c != ' ') ret = (ret << 4) + (*c) - '0';
l += *c++; else if(*c >= 'a' && *c <= 'f')
ret = (ret << 4) + (*c) - 'a' + 10;
return l;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EquateList::countCompletions(const char *in)
{
int count = 0;
completions = compPrefix = "";
labelToAddr::iterator iter;
for(iter = myFwdMap.begin(); iter != myFwdMap.end(); iter++)
{
const char *l = iter->first.c_str();
if(BSPF_strncasecmp(l, in, strlen(in)) == 0)
{
if(compPrefix == "")
compPrefix += l;
else else
{ return -1;
int nonMatch = 0;
const char *c = compPrefix.c_str();
while(*c != '\0' && tolower(*c) == tolower(l[nonMatch]))
{
c++; c++;
nonMatch++;
} }
compPrefix.erase(nonMatch, compPrefix.length()); return ret;
}
if(count++) completions += " ";
completions += l;
}
}
return count;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char *EquateList::getCompletions()
{
return completions.c_str();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char *EquateList::getCompletionPrefix()
{
return compPrefix.c_str();
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EquateList.hxx,v 1.18 2008-04-02 01:54:31 stephena Exp $ // $Id: EquateList.hxx,v 1.19 2008-05-01 23:08:24 stephena Exp $
//============================================================================ //============================================================================
#ifndef EQUATELIST_HXX #ifndef EQUATELIST_HXX
@ -23,7 +23,6 @@
#include "bspf.hxx" #include "bspf.hxx"
#include "Equate.hxx" #include "Equate.hxx"
#include "Array.hxx"
class EquateList class EquateList
{ {
@ -31,41 +30,54 @@ class EquateList
EquateList(); EquateList();
~EquateList(); ~EquateList();
const string& getLabel(int addr); /**
const string& getLabel(int addr, int flags); Add an equate consisting of the given label and address
string getFormatted(int addr, int places); */
string getFormatted(int addr, int places, int flags); void addEquate(const string& label, int address, const int flags);
int getAddress(const string& label);
int getAddress(const string& label, const int flags); /**
void addEquate(const string& label, int address); Remove the equate with the given label
// void addEquate(string label, int address, const int flags); */
bool saveFile(const string& file); bool removeEquate(const string& label);
/**
Accessor methods for labels and addresses
*/
const string& getLabel(int addr, const int flags = EQF_ANY);
string getFormatted(int addr, int places, const int flags = EQF_ANY);
int getAddress(const string& label, const int flags = EQF_ANY);
/**
Load user equates from the given symbol file (generated by DASM)
*/
string loadFile(const string& file); string loadFile(const string& file);
bool undefine(const string& label);
bool undefine(const char *lbl); /**
//string dumpAll(); Save user equates into a symbol file similar to that generated by DASM
*/
bool saveFile(const string& file);
/**
Methods used by the command parser for tab-completion
*/
int countCompletions(const char *in); int countCompletions(const char *in);
const char *getCompletions(); const string& getCompletions() { return myCompletions; }
const char *getCompletionPrefix(); const string& getCompletionPrefix() { return myCompPrefix; }
private: private:
int calcSize(); // Extract labels and values from the given character stream
int parse4hex(char *c);
string extractLabel(char *c); string extractLabel(char *c);
int extractValue(char *c); int extractValue(char *c);
private: private:
typedef map<int, Equate> addrToLabel; typedef map<int, Equate> AddrToLabel;
typedef map<string, Equate> labelToAddr; typedef map<string, Equate> LabelToAddr;
typedef Common::Array<Equate> Equates;
string completions; string myCompletions;
string compPrefix; string myCompPrefix;
//Equates ourVcsEquates; LabelToAddr myFwdMap;
int currentSize; AddrToLabel myRevMap;
labelToAddr myFwdMap;
addrToLabel myRevMap;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: PromptWidget.cxx,v 1.23 2008-03-23 17:43:22 stephena Exp $ // $Id: PromptWidget.cxx,v 1.24 2008-05-01 23:08:24 stephena Exp $
// //
// Based on code from ScummVM - Scumm Interpreter // Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project // Copyright (C) 2002-2004 The ScummVM project
@ -261,8 +261,9 @@ bool PromptWidget::handleKeyDown(int ascii, int keycode, int modifiers)
break; break;
} }
completionList = equates.getCompletions(); // TODO - perhaps use strings instead of char pointers
prefix = equates.getCompletionPrefix(); completionList = equates.getCompletions().c_str();
prefix = equates.getCompletionPrefix().c_str();
} }
if(possibilities == 1) if(possibilities == 1)