From 073ae410add8e721f1f8b027fd5ddd7a0824be31 Mon Sep 17 00:00:00 2001 From: urchlay Date: Fri, 1 Jul 2005 04:22:37 +0000 Subject: [PATCH] Added initial Yacc parser. This will replace DebuggerParser::decipher_args() and become the "mini-language" for conditional breaks/traps. The current lexer/parser combo benchmarks at 1/2 million parses/sec on my Athlon 2100. By comparison, Pitfall runs approx. 360,000 instructions/sec. We need to be able to check for a conditional break once per instruction, so on my box, I'll probably be able to run the emulator at full speed with one breakcond set, using all the CPU. Am still working on a way to speed things up: there's no reason we should have to fully lex and parse an expression every time we want to evaluate it. For now, the only place the new parser hooks into Stella is with an undocumented "expr" command. Try "expr 2+2" at the prompt. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@585 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/Makefile | 5 +++-- stella/configure | 3 ++- stella/src/debugger/Debugger.cxx | 5 ++++- stella/src/debugger/DebuggerParser.cxx | 15 ++++++++++++--- stella/src/emucore/m6502/src/M6502.cxx | 4 +++- stella/src/emucore/m6502/src/M6502.hxx | 7 +++++-- stella/src/emucore/m6502/src/M6502Hi.cxx | 6 ++++-- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/stella/Makefile b/stella/Makefile index 4ae559706..04e2aaf2b 100644 --- a/stella/Makefile +++ b/stella/Makefile @@ -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: Makefile,v 1.4 2005-06-29 13:11:03 stephena Exp $ +## $Id: Makefile,v 1.5 2005-07-01 04:22:26 urchlay Exp $ ## ## Based on code from ScummVM - Scumm Interpreter ## Copyright (C) 2002-2004 The ScummVM project @@ -90,7 +90,8 @@ MODULES += \ src/emucore \ src/emucore/m6502 \ src/gui \ - src/common + src/common \ + src/yacc ###################################################################### # The build rules follow - normally you should have no need to diff --git a/stella/configure b/stella/configure index 22c6ece76..5fa023949 100755 --- a/stella/configure +++ b/stella/configure @@ -646,6 +646,7 @@ CORE="$SRC/emucore" COMMON="$SRC/common" GUI="$SRC/gui" DBG="$SRC/debugger" +YACC="$SRC/yacc" INCLUDES="-I$CORE -I$CORE/m6502/src -I$CORE/m6502/src/bspf/src -I$COMMON -I$GUI" @@ -688,7 +689,7 @@ fi if test "$_build_developer" = yes ; then DEFINES="$DEFINES -DDEVELOPER_SUPPORT" MODULES="$MODULES $DBG" - INCLUDES="$INCLUDES -I$DBG" + INCLUDES="$INCLUDES -I$DBG -I$YACC" fi if test "$_build_snapshot" = yes ; then diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 098d2fb77..ba9ca9842 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.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: Debugger.cxx,v 1.42 2005-06-29 13:11:03 stephena Exp $ +// $Id: Debugger.cxx,v 1.43 2005-07-01 04:22:27 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -213,6 +213,9 @@ const string Debugger::state() result += " Frame:"; sprintf(buf, "%d", myTIAdebug->frameCount()); result += buf; + result += " 6502Ins:"; + sprintf(buf, "%d", mySystem->m6502().totalInstructionCount()); + result += buf; result += "\n "; result += disassemble(myDebugger->pc(), 1); diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index b42000e68..716bd4ce7 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.42 2005-06-29 00:31:48 urchlay Exp $ +// $Id: DebuggerParser.cxx,v 1.43 2005-07-01 04:22:27 urchlay Exp $ //============================================================================ #include "bspf.hxx" @@ -21,9 +21,8 @@ #include "DebuggerParser.hxx" #include "D6502.hxx" #include "DebuggerParser.hxx" +#include "YaccParser.hxx" -// TODO: finish this, replace run() and getArgs() with versions -// that use this table. Command DebuggerParser::commands[] = { { "a", @@ -854,6 +853,16 @@ bool DebuggerParser::validateArgs(int cmd) { string DebuggerParser::run(const string& command) { int i=0; + // special case: parser testing + if(strncmp(command.c_str(), "expr ", 5) == 0) { + commandResult = "parser test: status=="; + int status = YaccParser::parse(command.c_str() + 5); + commandResult += debugger->valueToString(status); + commandResult += ", result=="; + commandResult += debugger->valueToString(YaccParser::getResult()); + return commandResult; + } + getArgs(command); commandResult = ""; diff --git a/stella/src/emucore/m6502/src/M6502.cxx b/stella/src/emucore/m6502/src/M6502.cxx index b708c2674..938728491 100644 --- a/stella/src/emucore/m6502/src/M6502.cxx +++ b/stella/src/emucore/m6502/src/M6502.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: M6502.cxx,v 1.7 2005-06-21 05:00:45 urchlay Exp $ +// $Id: M6502.cxx,v 1.8 2005-07-01 04:22:37 urchlay Exp $ //============================================================================ #include "M6502.hxx" @@ -43,6 +43,8 @@ M6502::M6502(uInt32 systemCyclesPerProcessorCycle) myInstructionSystemCycleTable[t] = ourInstructionProcessorCycleTable[t] * mySystemCyclesPerProcessorCycle; } + + myTotalInstructionCount = 0; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/m6502/src/M6502.hxx b/stella/src/emucore/m6502/src/M6502.hxx index d9627202e..ae385d69a 100644 --- a/stella/src/emucore/m6502/src/M6502.hxx +++ b/stella/src/emucore/m6502/src/M6502.hxx @@ -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: M6502.hxx,v 1.6 2005-06-21 05:00:45 urchlay Exp $ +// $Id: M6502.hxx,v 1.7 2005-07-01 04:22:37 urchlay Exp $ //============================================================================ #ifndef M6502_HXX @@ -35,7 +35,7 @@ class Debugger; has a 64K addressing space. @author Bradford W. Mott - @version $Id: M6502.hxx,v 1.6 2005-06-21 05:00:45 urchlay Exp $ + @version $Id: M6502.hxx,v 1.7 2005-07-01 04:22:37 urchlay Exp $ */ class M6502 { @@ -178,6 +178,7 @@ class M6502 public: void setBreakPoints(PackedBitArray *bp); void setTraps(PackedBitArray *read, PackedBitArray *write); + int totalInstructionCount() { return myTotalInstructionCount; } protected: /** @@ -262,5 +263,7 @@ class M6502 // did we just now hit a trap? bool justHitTrap; + + int myTotalInstructionCount; }; #endif diff --git a/stella/src/emucore/m6502/src/M6502Hi.cxx b/stella/src/emucore/m6502/src/M6502Hi.cxx index b2eef0c29..54d2894da 100644 --- a/stella/src/emucore/m6502/src/M6502Hi.cxx +++ b/stella/src/emucore/m6502/src/M6502Hi.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: M6502Hi.cxx,v 1.8 2005-06-28 12:20:06 urchlay Exp $ +// $Id: M6502Hi.cxx,v 1.9 2005-07-01 04:22:37 urchlay Exp $ //============================================================================ #include "M6502Hi.hxx" @@ -89,8 +89,8 @@ bool M6502High::execute(uInt32 number) if(justHitTrap) { - justHitTrap = false; if(myDebugger->start()) { + justHitTrap = false; return true; } } @@ -127,6 +127,8 @@ bool M6502High::execute(uInt32 number) myExecutionStatus |= FatalErrorBit; } + myTotalInstructionCount++; + #ifdef DEBUG debugStream << hex << setw(4) << operandAddress << " "; debugStream << setw(4) << ourInstructionMnemonicTable[IR];