summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug/express.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/debug/express.cpp')
-rw-r--r--src/emu/debug/express.cpp292
1 files changed, 146 insertions, 146 deletions
diff --git a/src/emu/debug/express.cpp b/src/emu/debug/express.cpp
index bc90ddaf52e..3e15ba29a5b 100644
--- a/src/emu/debug/express.cpp
+++ b/src/emu/debug/express.cpp
@@ -46,6 +46,7 @@
#include "logmacro.h"
+namespace {
/***************************************************************************
CONSTANTS
@@ -103,7 +104,7 @@ enum
//**************************************************************************
-// TYPE DEFINITIONS
+// REGISTER SYMBOL ENTRY
//**************************************************************************
// a symbol entry representing a register, with read/write callbacks
@@ -116,8 +117,8 @@ public:
integer_symbol_entry(symbol_table &table, const char *name, symbol_table::getter_func getter, symbol_table::setter_func setter, const std::string &format);
// symbol access
- virtual bool is_lval() const override;
- virtual u64 value() const override;
+ virtual bool is_lval() const override { return m_setter != nullptr; }
+ virtual u64 value() const override { return m_getter(); }
virtual void set_value(u64 newvalue) override;
private:
@@ -128,105 +129,6 @@ private:
};
-// a symbol entry representing a function
-class function_symbol_entry : public symbol_entry
-{
-public:
- // construction/destruction
- function_symbol_entry(symbol_table &table, const char *name, int minparams, int maxparams, symbol_table::execute_func execute);
-
- // getters
- u16 minparams() const { return m_minparams; }
- u16 maxparams() const { return m_maxparams; }
-
- // symbol access
- virtual bool is_lval() const override;
- virtual u64 value() const override;
- virtual void set_value(u64 newvalue) override;
-
- // execution helper
- virtual u64 execute(int numparams, const u64 *paramlist);
-
-private:
- // internal state
- u16 m_minparams;
- u16 m_maxparams;
- symbol_table::execute_func m_execute;
-};
-
-
-
-//**************************************************************************
-// EXPRESSION ERROR
-//**************************************************************************
-
-//-------------------------------------------------
-// code_string - return a friendly string for a
-// given expression error
-//-------------------------------------------------
-
-std::string expression_error::code_string() const
-{
- switch (m_code)
- {
- case NOT_LVAL: return "not an lvalue";
- case NOT_RVAL: return "not an rvalue";
- case SYNTAX: return "syntax error";
- case UNKNOWN_SYMBOL: return "unknown symbol";
- case INVALID_NUMBER: return "invalid number";
- case INVALID_TOKEN: return "invalid token";
- case STACK_OVERFLOW: return "stack overflow";
- case STACK_UNDERFLOW: return "stack underflow";
- case UNBALANCED_PARENS: return "unbalanced parentheses";
- case DIVIDE_BY_ZERO: return "divide by zero";
- case OUT_OF_MEMORY: return "out of memory";
- case INVALID_PARAM_COUNT: return "invalid number of parameters";
- case TOO_FEW_PARAMS: return util::string_format("too few parameters (at least %d required)", m_num);
- case TOO_MANY_PARAMS: return util::string_format("too many parameters (no more than %d accepted)", m_num);
- case UNBALANCED_QUOTES: return "unbalanced quotes";
- case TOO_MANY_STRINGS: return "too many strings";
- case INVALID_MEMORY_SIZE: return "invalid memory size (b/w/d/q expected)";
- case NO_SUCH_MEMORY_SPACE: return "non-existent memory space";
- case INVALID_MEMORY_SPACE: return "invalid memory space (p/d/i/o/r/m expected)";
- case INVALID_MEMORY_NAME: return "invalid memory name";
- case MISSING_MEMORY_NAME: return "missing memory name";
- default: return "unknown error";
- }
-}
-
-
-
-//**************************************************************************
-// SYMBOL ENTRY
-//**************************************************************************
-
-//-------------------------------------------------
-// symbol_entry - constructor
-//-------------------------------------------------
-
-symbol_entry::symbol_entry(symbol_table &table, symbol_type type, const char *name, const std::string &format)
- : m_table(table),
- m_type(type),
- m_name(name),
- m_format(format)
-{
-}
-
-
-//-------------------------------------------------
-// ~symbol_entry - destructor
-//-------------------------------------------------
-
-symbol_entry::~symbol_entry()
-{
-}
-
-
-
-//**************************************************************************
-// REGISTER SYMBOL ENTRY
-//**************************************************************************
-
//-------------------------------------------------
// integer_symbol_entry - constructor
//-------------------------------------------------
@@ -265,26 +167,6 @@ integer_symbol_entry::integer_symbol_entry(symbol_table &table, const char *name
//-------------------------------------------------
-// is_lval - is this symbol allowable as an lval?
-//-------------------------------------------------
-
-bool integer_symbol_entry::is_lval() const
-{
- return (m_setter != nullptr);
-}
-
-
-//-------------------------------------------------
-// value - return the value of this symbol
-//-------------------------------------------------
-
-u64 integer_symbol_entry::value() const
-{
- return m_getter();
-}
-
-
-//-------------------------------------------------
// set_value - set the value of this symbol
//-------------------------------------------------
@@ -302,6 +184,33 @@ void integer_symbol_entry::set_value(u64 newvalue)
// FUNCTION SYMBOL ENTRY
//**************************************************************************
+// a symbol entry representing a function
+class function_symbol_entry : public symbol_entry
+{
+public:
+ // construction/destruction
+ function_symbol_entry(symbol_table &table, const char *name, int minparams, int maxparams, symbol_table::execute_func execute);
+
+ // getters
+ u16 minparams() const { return m_minparams; }
+ u16 maxparams() const { return m_maxparams; }
+
+ // symbol access
+ virtual bool is_lval() const override { return false; }
+ virtual u64 value() const override;
+ virtual void set_value(u64 newvalue) override;
+
+ // execution helper
+ virtual u64 execute(int numparams, const u64 *paramlist);
+
+private:
+ // internal state
+ u16 m_minparams;
+ u16 m_maxparams;
+ symbol_table::execute_func m_execute;
+};
+
+
//-------------------------------------------------
// function_symbol_entry - constructor
//-------------------------------------------------
@@ -316,16 +225,6 @@ function_symbol_entry::function_symbol_entry(symbol_table &table, const char *na
//-------------------------------------------------
-// is_lval - is this symbol allowable as an lval?
-//-------------------------------------------------
-
-bool function_symbol_entry::is_lval() const
-{
- return false;
-}
-
-
-//-------------------------------------------------
// value - return the value of this symbol
//-------------------------------------------------
@@ -360,6 +259,102 @@ u64 function_symbol_entry::execute(int numparams, const u64 *paramlist)
+/***************************************************************************
+ INLINE FUNCTIONS
+***************************************************************************/
+
+inline std::pair<device_t &, char const *> get_device_search(running_machine &machine, device_memory_interface *memintf, char const *tag)
+{
+ if (tag)
+ {
+ if (('.' == tag[0]) && (!tag[1] || (':' == tag[1]) || ('^' == tag[1])))
+ return std::pair<device_t &, char const *>(memintf ? memintf->device() : machine.root_device(), tag + ((':' == tag[1]) ? 2 : 1));
+ else if (('^' == tag[0]) && memintf)
+ return std::pair<device_t &, char const *>(memintf->device(), tag);
+ else
+ return std::pair<device_t &, char const *>(machine.root_device(), tag);
+ }
+ else if (memintf)
+ {
+ return std::pair<device_t &, char const *>(memintf->device(), "");
+ }
+ else
+ {
+ return std::pair<device_t &, char const *>(machine.root_device(), "");
+ }
+}
+
+} // anonymous namespace
+
+
+
+//**************************************************************************
+// EXPRESSION ERROR
+//**************************************************************************
+
+//-------------------------------------------------
+// code_string - return a friendly string for a
+// given expression error
+//-------------------------------------------------
+
+std::string expression_error::code_string() const
+{
+ switch (m_code)
+ {
+ case NOT_LVAL: return "not an lvalue";
+ case NOT_RVAL: return "not an rvalue";
+ case SYNTAX: return "syntax error";
+ case UNKNOWN_SYMBOL: return "unknown symbol";
+ case INVALID_NUMBER: return "invalid number";
+ case INVALID_TOKEN: return "invalid token";
+ case STACK_OVERFLOW: return "stack overflow";
+ case STACK_UNDERFLOW: return "stack underflow";
+ case UNBALANCED_PARENS: return "unbalanced parentheses";
+ case DIVIDE_BY_ZERO: return "divide by zero";
+ case OUT_OF_MEMORY: return "out of memory";
+ case INVALID_PARAM_COUNT: return "invalid number of parameters";
+ case TOO_FEW_PARAMS: return util::string_format("too few parameters (at least %d required)", m_num);
+ case TOO_MANY_PARAMS: return util::string_format("too many parameters (no more than %d accepted)", m_num);
+ case UNBALANCED_QUOTES: return "unbalanced quotes";
+ case TOO_MANY_STRINGS: return "too many strings";
+ case INVALID_MEMORY_SIZE: return "invalid memory size (b/w/d/q expected)";
+ case NO_SUCH_MEMORY_SPACE: return "non-existent memory space";
+ case INVALID_MEMORY_SPACE: return "invalid memory space (p/d/i/o/r/m expected)";
+ case INVALID_MEMORY_NAME: return "invalid memory name";
+ case MISSING_MEMORY_NAME: return "missing memory name";
+ default: return "unknown error";
+ }
+}
+
+
+
+//**************************************************************************
+// SYMBOL ENTRY
+//**************************************************************************
+
+//-------------------------------------------------
+// symbol_entry - constructor
+//-------------------------------------------------
+
+symbol_entry::symbol_entry(symbol_table &table, symbol_type type, const char *name, const std::string &format)
+ : m_table(table),
+ m_type(type),
+ m_name(name),
+ m_format(format)
+{
+}
+
+
+//-------------------------------------------------
+// ~symbol_entry - destructor
+//-------------------------------------------------
+
+symbol_entry::~symbol_entry()
+{
+}
+
+
+
//**************************************************************************
// SYMBOL TABLE
//**************************************************************************
@@ -551,17 +546,13 @@ expression_error symbol_table::expression_get_space(const char *tag, int &spacen
if (tag)
{
// convert to lowercase then lookup the name (tags are enforced to be all lower case)
- device_t *base;
- if ((('^' == tag[0]) || (('.' == tag[0]) && ((':' == tag[1]) || !tag[1]))) && m_memintf)
- base = &m_memintf->device();
- else
- base = &m_machine.root_device();
- device = base->subdevice(strmakelower(tag));
+ auto base = get_device_search(m_machine, m_memintf, tag);
+ device = base.first.subdevice(strmakelower(base.second));
// if that failed, treat the last component as an address space
if (!device)
{
- std::string_view t = tag;
+ std::string_view t = base.second;
auto const delimiter = t.find_last_of(":^");
bool const found = std::string_view::npos != delimiter;
if (!found || (':' == t[delimiter]))
@@ -569,7 +560,7 @@ expression_error symbol_table::expression_get_space(const char *tag, int &spacen
spacename = strmakelower(t.substr(found ? (delimiter + 1) : 0));
t = t.substr(0, !found ? 0 : !delimiter ? 1 : delimiter);
if (!t.empty())
- device = base->subdevice(strmakelower(t));
+ device = base.first.subdevice(strmakelower(t));
else
device = m_memintf ? &m_memintf->device() : &m_machine.root_device();
}
@@ -740,11 +731,12 @@ u64 symbol_table::read_program_direct(address_space &space, int opcode, offs_t a
u64 symbol_table::read_memory_region(const char *rgntag, offs_t address, int size)
{
- memory_region *region = m_machine.root_device().memregion(rgntag);
+ auto search = get_device_search(m_machine, m_memintf, rgntag);
+ memory_region *const region = search.first.memregion(search.second);
u64 result = ~u64(0) >> (64 - 8*size);
// make sure we get a valid base before proceeding
- if (region != nullptr)
+ if (region)
{
// call ourself recursively until we are byte-sized
if (size > 1)
@@ -900,10 +892,11 @@ void symbol_table::write_program_direct(address_space &space, int opcode, offs_t
void symbol_table::write_memory_region(const char *rgntag, offs_t address, int size, u64 data)
{
- memory_region *region = m_machine.root_device().memregion(rgntag);
+ auto search = get_device_search(m_machine, m_memintf, rgntag);
+ memory_region *const region = search.first.memregion(search.second);
// make sure we get a valid base before proceeding
- if (region != nullptr)
+ if (region)
{
// call ourself recursively until we are byte-sized
if (size > 1)
@@ -984,9 +977,16 @@ expression_error::error_code symbol_table::memory_valid(const char *name, expres
case EXPSPACE_REGION:
if (!name)
+ {
return expression_error::MISSING_MEMORY_NAME;
- if (!m_machine.root_device().memregion(name) || !m_machine.root_device().memregion(name)->base())
- return expression_error::INVALID_MEMORY_NAME;
+ }
+ else
+ {
+ auto search = get_device_search(m_machine, m_memintf, name);
+ memory_region *const region = search.first.memregion(search.second);
+ if (!region || !region->base())
+ return expression_error::INVALID_MEMORY_NAME;
+ }
break;
default: