From c7cf7743e3da79698b906700203d61df4af81b8d Mon Sep 17 00:00:00 2001 From: urchlay Date: Sat, 25 Jun 2005 06:27:01 +0000 Subject: [PATCH] Beginnings of new parser stuff: a struct to represent a command, including name, description, argument count & types, and a method pointer to actually execute the command. Instance method pointers in C++ are even more annoying that function pointers in C... The actual parser (the run() and getArgs()) methods don't use the new stuff, so the actual operation of the debugger is unchanged. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@561 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/debugger/DebuggerParser.cxx | 32 ++++++++++++++++++++-- stella/src/debugger/DebuggerParser.hxx | 38 +++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index def7a059a..2607b0727 100644 --- a/stella/src/debugger/DebuggerParser.cxx +++ b/stella/src/debugger/DebuggerParser.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DebuggerParser.cxx,v 1.34 2005-06-24 16:36:41 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.35 2005-06-25 06:27:01 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -22,6 +22,24 @@ #include "D6502.hxx" #include "EquateList.hxx" +// TODO: finish this, replace run() and getArgs() with versions +// that use this table. +Command DebuggerParser::commands[] = { + { + "a", + "Set Accumulator to value xx", + { kARG_BYTE, kARG_END_ARGS }, + &DebuggerParser::executeA + }, + + { + "base", + "Set default base (hex, dec, or bin)", + { kARG_BASE_SPCL, kARG_END_ARGS }, + &DebuggerParser::executeBase + } +}; + // Constants for argument processing enum { kIN_COMMAND, @@ -29,12 +47,12 @@ enum { kIN_ARG }; - DebuggerParser::DebuggerParser(Debugger* d) : debugger(d) { done = false; defaultBase = kBASE_16; + } DebuggerParser::~DebuggerParser() { @@ -658,6 +676,9 @@ string DebuggerParser::run(const string& command) { result += "Set base "; result += buf; return result; + } else if(subStringMatch(verb, "testcall")) { + METHOD m = commands[0].executor; + CALL_METHOD(m); } else if(subStringMatch(verb, "listsym")) { return debugger->equateList->dumpAll(); } else if(subStringMatch(verb, "quit") || subStringMatch(verb, "run")) { @@ -730,3 +751,10 @@ string DebuggerParser::run(const string& command) { return result; } + +void DebuggerParser::executeA() { + cerr << "called executeA()" << endl; +} + +void DebuggerParser::executeBase() { +} diff --git a/stella/src/debugger/DebuggerParser.hxx b/stella/src/debugger/DebuggerParser.hxx index b68a24297..ce9c97ac2 100644 --- a/stella/src/debugger/DebuggerParser.hxx +++ b/stella/src/debugger/DebuggerParser.hxx @@ -13,13 +13,14 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: DebuggerParser.hxx,v 1.16 2005-06-23 01:10:25 urchlay Exp $ +// $Id: DebuggerParser.hxx,v 1.17 2005-06-25 06:27:01 urchlay Exp $ //============================================================================ #ifndef DEBUGGER_PARSER_HXX #define DEBUGGER_PARSER_HXX class Debugger; +struct Command; #include "bspf.hxx" #include "EquateList.hxx" @@ -75,6 +76,41 @@ class DebuggerParser BaseFormat defaultBase; StringArray watches; + static Command commands[]; + + void executeA(); + void executeBase(); }; +// TODO: put in separate header file Command.hxx +#define kMAX_ARG_TYPES 10 + +// These next two deserve English explanations: + +// pointer to DebuggerParser instance method, no args, returns void. +typedef void (DebuggerParser::*METHOD)(); + +// call the pointed-to method on the this object. Whew. +#define CALL_METHOD(method) ( (this->*method)() ) + +typedef enum { + kARG_WORD, // single 16-bit value + kARG_MULTI_WORD, // multiple 16-bit values (must occur last) + kARG_BYTE, // single 8-bit value + kARG_MULTI_BYTE, // multiple 8-bit values (must occur last) + kARG_BOOL, // 0 or 1 only + kARG_LABEL, // label (need not be defined, treated as string) + kARG_FILE, // filename + kARG_BASE_SPCL, // base specifier: 2, 10, or 16 (or "bin" "dec" "hex") + kARG_END_ARGS // sentinel, occurs at end of list +} argType; + +struct Command { + string cmdString; + string description; + argType args[kMAX_ARG_TYPES]; + METHOD executor; +}; + + #endif