diff options
author | 2020-04-13 19:57:13 -0400 | |
---|---|---|
committer | 2020-04-13 20:04:25 -0400 | |
commit | 86e7693df08201e82d06e8f23a77cc5982e3dcd3 (patch) | |
tree | edee95c1e7f8d65e3201b73338e136ceb2abb352 | |
parent | dcf2109120ef5ec5c65ee6e15de46bea1d8f2822 (diff) |
Make expressions octal for applicable address spaces in disassembly view
debug/express.cpp, debugcpu.cpp: General cleanup (nw)
- Change default base from hardcoded macro to dynamic parameter for parsed_expression
- Change symbol table parameters and variables to references or std::reference_wrapper
- Remove the (unused) ability to construct a parsed_expression without a symbol table
- Eliminate symbol_table &table and void *memory_param arguments from callbacks (superfluous now that std::function can bind everything necessary)
- Eliminate globalref pointer from symbol_table
- Add explicitly defaulted move constructor and move assignment operator
-rw-r--r-- | src/devices/cpu/i386/i386.cpp | 20 | ||||
-rw-r--r-- | src/devices/cpu/i386/i386.h | 10 | ||||
-rw-r--r-- | src/emu/debug/debugcmd.cpp | 42 | ||||
-rw-r--r-- | src/emu/debug/debugcmd.h | 10 | ||||
-rw-r--r-- | src/emu/debug/debugcon.cpp | 3 | ||||
-rw-r--r-- | src/emu/debug/debugcpu.cpp | 211 | ||||
-rw-r--r-- | src/emu/debug/debugcpu.h | 27 | ||||
-rw-r--r-- | src/emu/debug/debugvw.cpp | 7 | ||||
-rw-r--r-- | src/emu/debug/debugvw.h | 3 | ||||
-rw-r--r-- | src/emu/debug/dvdisasm.cpp | 6 | ||||
-rw-r--r-- | src/emu/debug/express.cpp | 91 | ||||
-rw-r--r-- | src/emu/debug/express.h | 37 | ||||
-rw-r--r-- | src/frontend/mame/cheat.cpp | 14 | ||||
-rw-r--r-- | src/frontend/mame/cheat.h | 4 |
14 files changed, 192 insertions, 293 deletions
diff --git a/src/devices/cpu/i386/i386.cpp b/src/devices/cpu/i386/i386.cpp index 1778084b8a6..d6efcb3a35f 100644 --- a/src/devices/cpu/i386/i386.cpp +++ b/src/devices/cpu/i386/i386.cpp @@ -1777,7 +1777,7 @@ uint32_t i386_device::i386_get_debug_desc(I386_SREG *seg) return seg->valid; } -uint64_t i386_device::debug_segbase(symbol_table &table, int params, const uint64_t *param) +uint64_t i386_device::debug_segbase(int params, const uint64_t *param) { uint32_t result; I386_SREG seg; @@ -1800,7 +1800,7 @@ uint64_t i386_device::debug_segbase(symbol_table &table, int params, const uint6 return result; } -uint64_t i386_device::debug_seglimit(symbol_table &table, int params, const uint64_t *param) +uint64_t i386_device::debug_seglimit(int params, const uint64_t *param) { uint32_t result = 0; I386_SREG seg; @@ -1816,7 +1816,7 @@ uint64_t i386_device::debug_seglimit(symbol_table &table, int params, const uint return result; } -uint64_t i386_device::debug_segofftovirt(symbol_table &table, int params, const uint64_t *param) +uint64_t i386_device::debug_segofftovirt(int params, const uint64_t *param) { uint32_t result; I386_SREG seg; @@ -1854,7 +1854,7 @@ uint64_t i386_device::debug_segofftovirt(symbol_table &table, int params, const return result; } -uint64_t i386_device::debug_virttophys(symbol_table &table, int params, const uint64_t *param) +uint64_t i386_device::debug_virttophys(int params, const uint64_t *param) { uint32_t result = param[0]; @@ -1863,7 +1863,7 @@ uint64_t i386_device::debug_virttophys(symbol_table &table, int params, const ui return result; } -uint64_t i386_device::debug_cacheflush(symbol_table &table, int params, const uint64_t *param) +uint64_t i386_device::debug_cacheflush(int params, const uint64_t *param) { uint32_t option; bool invalidate; @@ -1886,11 +1886,11 @@ uint64_t i386_device::debug_cacheflush(symbol_table &table, int params, const ui void i386_device::device_debug_setup() { using namespace std::placeholders; - debug()->symtable().add("segbase", 1, 1, std::bind(&i386_device::debug_segbase, this, _1, _2, _3)); - debug()->symtable().add("seglimit", 1, 1, std::bind(&i386_device::debug_seglimit, this, _1, _2, _3)); - debug()->symtable().add("segofftovirt", 2, 2, std::bind(&i386_device::debug_segofftovirt, this, _1, _2, _3)); - debug()->symtable().add("virttophys", 1, 1, std::bind(&i386_device::debug_virttophys, this, _1, _2, _3)); - debug()->symtable().add("cacheflush", 0, 1, std::bind(&i386_device::debug_cacheflush, this, _1, _2, _3)); + debug()->symtable().add("segbase", 1, 1, std::bind(&i386_device::debug_segbase, this, _1, _2)); + debug()->symtable().add("seglimit", 1, 1, std::bind(&i386_device::debug_seglimit, this, _1, _2)); + debug()->symtable().add("segofftovirt", 2, 2, std::bind(&i386_device::debug_segofftovirt, this, _1, _2)); + debug()->symtable().add("virttophys", 1, 1, std::bind(&i386_device::debug_virttophys, this, _1, _2)); + debug()->symtable().add("cacheflush", 0, 1, std::bind(&i386_device::debug_cacheflush, this, _1, _2)); } /*************************************************************************/ diff --git a/src/devices/cpu/i386/i386.h b/src/devices/cpu/i386/i386.h index e6fda6278bc..d40c542adcd 100644 --- a/src/devices/cpu/i386/i386.h +++ b/src/devices/cpu/i386/i386.h @@ -36,11 +36,11 @@ public: auto smiact() { return m_smiact.bind(); } auto ferr() { return m_ferr_handler.bind(); } - uint64_t debug_segbase(symbol_table &table, int params, const uint64_t *param); - uint64_t debug_seglimit(symbol_table &table, int params, const uint64_t *param); - uint64_t debug_segofftovirt(symbol_table &table, int params, const uint64_t *param); - uint64_t debug_virttophys(symbol_table &table, int params, const uint64_t *param); - uint64_t debug_cacheflush(symbol_table &table, int params, const uint64_t *param); + uint64_t debug_segbase(int params, const uint64_t *param); + uint64_t debug_seglimit(int params, const uint64_t *param); + uint64_t debug_segofftovirt(int params, const uint64_t *param); + uint64_t debug_virttophys(int params, const uint64_t *param); + uint64_t debug_cacheflush(int params, const uint64_t *param); protected: i386_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int program_data_width, int program_addr_width, int io_data_width); diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index c8559ee1fae..5af1288ddb8 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -103,13 +103,13 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu { m_global_array = std::make_unique<global_entry []>(MAX_GLOBALS); - symbol_table *symtable = m_cpu.get_global_symtable(); + symbol_table &symtable = m_cpu.global_symtable(); /* add a few simple global functions */ using namespace std::placeholders; - symtable->add("min", 2, 2, std::bind(&debugger_commands::execute_min, this, _1, _2, _3)); - symtable->add("max", 2, 2, std::bind(&debugger_commands::execute_max, this, _1, _2, _3)); - symtable->add("if", 3, 3, std::bind(&debugger_commands::execute_if, this, _1, _2, _3)); + symtable.add("min", 2, 2, std::bind(&debugger_commands::execute_min, this, _1, _2)); + symtable.add("max", 2, 2, std::bind(&debugger_commands::execute_max, this, _1, _2)); + symtable.add("if", 3, 3, std::bind(&debugger_commands::execute_if, this, _1, _2)); /* add all single-entry save state globals */ for (int itemnum = 0; itemnum < MAX_GLOBALS; itemnum++) @@ -129,10 +129,10 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu sprintf(symname, ".%s", strrchr(name, '/') + 1); m_global_array[itemnum].base = base; m_global_array[itemnum].size = valsize; - symtable->add( + symtable.add( symname, - std::bind(&debugger_commands::global_get, this, _1, &m_global_array[itemnum]), - std::bind(&debugger_commands::global_set, this, _1, &m_global_array[itemnum], _2)); + std::bind(&debugger_commands::global_get, this, &m_global_array[itemnum]), + std::bind(&debugger_commands::global_set, this, &m_global_array[itemnum], _1)); } } @@ -306,7 +306,7 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu execute_min - return the minimum of two values -------------------------------------------------*/ -u64 debugger_commands::execute_min(symbol_table &table, int params, const u64 *param) +u64 debugger_commands::execute_min(int params, const u64 *param) { return (param[0] < param[1]) ? param[0] : param[1]; } @@ -316,7 +316,7 @@ u64 debugger_commands::execute_min(symbol_table &table, int params, const u64 *p execute_max - return the maximum of two values -------------------------------------------------*/ -u64 debugger_commands::execute_max(symbol_table &table, int params, const u64 *param) +u64 debugger_commands::execute_max(int params, const u64 *param) { return (param[0] > param[1]) ? param[0] : param[1]; } @@ -326,7 +326,7 @@ u64 debugger_commands::execute_max(symbol_table &table, int params, const u64 *p execute_if - if (a) return b; else return c; -------------------------------------------------*/ -u64 debugger_commands::execute_if(symbol_table &table, int params, const u64 *param) +u64 debugger_commands::execute_if(int params, const u64 *param) { return param[0] ? param[1] : param[2]; } @@ -341,7 +341,7 @@ u64 debugger_commands::execute_if(symbol_table &table, int params, const u64 *pa global_get - symbol table getter for globals -------------------------------------------------*/ -u64 debugger_commands::global_get(symbol_table &table, global_entry *global) +u64 debugger_commands::global_get(global_entry *global) { switch (global->size) { @@ -358,7 +358,7 @@ u64 debugger_commands::global_get(symbol_table &table, global_entry *global) global_set - symbol table setter for globals -------------------------------------------------*/ -void debugger_commands::global_set(symbol_table &table, global_entry *global, u64 value) +void debugger_commands::global_set(global_entry *global, u64 value) { switch (global->size) { @@ -385,7 +385,7 @@ bool debugger_commands::validate_number_parameter(const std::string ¶m, u64 /* evaluate the expression; success if no error */ try { - parsed_expression expression(m_cpu.get_visible_symtable(), param.c_str(), &result); + result = parsed_expression(m_cpu.visible_symtable(), param.c_str()).execute(); return true; } catch (expression_error &error) @@ -454,7 +454,7 @@ bool debugger_commands::validate_cpu_parameter(const char *param, device_t *&res u64 cpunum; try { - parsed_expression expression(m_cpu.get_visible_symtable(), param, &cpunum); + cpunum = parsed_expression(m_cpu.visible_symtable(), param).execute(); } catch (expression_error &) { @@ -759,7 +759,7 @@ void debugger_commands::execute_tracesym(int ref, const std::vector<std::string> for (int i = 0; i < params.size(); i++) { // find this symbol - symbol_entry *sym = m_cpu.get_visible_symtable()->find(params[i].c_str()); + symbol_entry *sym = m_cpu.visible_symtable().find(params[i].c_str()); if (!sym) { m_console.printf("Unknown symbol: %s\n", params[i].c_str()); @@ -925,7 +925,7 @@ void debugger_commands::execute_go_time(int ref, const std::vector<std::string> -------------------------------------------------*/ void debugger_commands::execute_go_privilege(int ref, const std::vector<std::string> ¶ms) { - parsed_expression condition(&m_cpu.get_visible_cpu()->debug()->symtable()); + parsed_expression condition(m_cpu.get_visible_cpu()->debug()->symtable()); if (params.size() > 0 && !debug_command_parameter_expression(params[0], condition)) return; @@ -1319,7 +1319,7 @@ void debugger_commands::execute_bpset(int ref, const std::vector<std::string> &p return; /* param 2 is the condition */ - parsed_expression condition(&cpu->debug()->symtable()); + parsed_expression condition(cpu->debug()->symtable()); if (params.size() > 1 && !debug_command_parameter_expression(params[1], condition)) return; @@ -1477,7 +1477,7 @@ void debugger_commands::execute_wpset(int ref, const std::vector<std::string> &p } /* param 4 is the condition */ - parsed_expression condition(&space->device().debug()->symtable()); + parsed_expression condition(space->device().debug()->symtable()); if (params.size() > 3 && !debug_command_parameter_expression(params[3], condition)) return; @@ -1619,7 +1619,7 @@ void debugger_commands::execute_rpset(int ref, const std::vector<std::string> &p return; /* param 1 is the condition */ - parsed_expression condition(&cpu->debug()->symtable()); + parsed_expression condition(cpu->debug()->symtable()); if (params.size() > 0 && !debug_command_parameter_expression(params[0], condition)) return; @@ -2708,7 +2708,7 @@ void debugger_commands::execute_find(int ref, const std::vector<std::string> &pa for (u64 i = offset; i <= endoffset; i += data_size[0]) { int suboffset = 0; - int match = 1; + bool match = true; /* find the entire string */ for (j = 0; j < data_count && match; j++) @@ -3257,7 +3257,7 @@ void debugger_commands::execute_symlist(int ref, const std::vector<std::string> } else { - symtable = m_cpu.get_global_symtable(); + symtable = &m_cpu.global_symtable(); m_console.printf("Global symbols:\n"); } diff --git a/src/emu/debug/debugcmd.h b/src/emu/debug/debugcmd.h index 74da262bfdd..62e8008c322 100644 --- a/src/emu/debug/debugcmd.h +++ b/src/emu/debug/debugcmd.h @@ -81,12 +81,12 @@ private: u64 cheat_byte_swap(const cheat_system *cheatsys, u64 value); u64 cheat_read_extended(const cheat_system *cheatsys, address_space &space, offs_t address); - u64 execute_min(symbol_table &table, int params, const u64 *param); - u64 execute_max(symbol_table &table, int params, const u64 *param); - u64 execute_if(symbol_table &table, int params, const u64 *param); + u64 execute_min(int params, const u64 *param); + u64 execute_max(int params, const u64 *param); + u64 execute_if(int params, const u64 *param); - u64 global_get(symbol_table &table, global_entry *global); - void global_set(symbol_table &table, global_entry *global, u64 value); + u64 global_get(global_entry *global); + void global_set(global_entry *global, u64 value); int mini_printf(char *buffer, const char *format, int params, u64 *param); diff --git a/src/emu/debug/debugcon.cpp b/src/emu/debug/debugcon.cpp index 9219df2f0ca..2c5989a8faa 100644 --- a/src/emu/debug/debugcon.cpp +++ b/src/emu/debug/debugcon.cpp @@ -334,8 +334,7 @@ CMDERR debugger_console::internal_parse_command(const std::string &original_comm { try { - u64 expresult; - parsed_expression expression(m_machine.debugger().cpu().get_visible_symtable(), command_start, &expresult); + parsed_expression(m_machine.debugger().cpu().visible_symtable(), command_start).execute(); } catch (expression_error &err) { diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index f5fcce1f88b..35b142d1fa2 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -53,7 +53,7 @@ debugger_cpu::debugger_cpu(running_machine &machine) m_tempvar = make_unique_clear<u64[]>(NUM_TEMP_VARIABLES); /* create a global symbol table */ - m_symtable = std::make_unique<symbol_table>(&m_machine); + m_symtable = std::make_unique<symbol_table>(); // configure our base memory accessors configure_memory(*m_symtable); @@ -62,8 +62,7 @@ debugger_cpu::debugger_cpu(running_machine &machine) m_symtable->add("wpaddr", symbol_table::READ_ONLY, &m_wpaddr); m_symtable->add("wpdata", symbol_table::READ_ONLY, &m_wpdata); - using namespace std::placeholders; - m_symtable->add("cpunum", std::bind(&debugger_cpu::get_cpunum, this, _1)); + m_symtable->add("cpunum", std::bind(&debugger_cpu::get_cpunum, this)); screen_device_iterator screen_iterator = screen_device_iterator(m_machine.root_device()); screen_device_iterator::auto_iterator iter = screen_iterator.begin(); @@ -71,18 +70,20 @@ debugger_cpu::debugger_cpu(running_machine &machine) if (count == 1) { - m_symtable->add("beamx", std::bind(&debugger_cpu::get_beamx, this, _1, iter.current())); - m_symtable->add("beamy", std::bind(&debugger_cpu::get_beamy, this, _1, iter.current())); - m_symtable->add("frame", std::bind(&debugger_cpu::get_frame, this, _1, iter.current())); + screen_device &screen = *iter.current(); + m_symtable->add("beamx", [&screen]() { return screen.hpos(); }); + m_symtable->add("beamy", [&screen]() { return screen.vpos(); }); + m_symtable->add("frame", [&screen]() { return screen.frame_number(); }); iter.current()->register_vblank_callback(vblank_state_delegate(&debugger_cpu::on_vblank, this)); } else if (count > 1) { for (uint32_t i = 0; i < count; i++, iter++) { - m_symtable->add(string_format("beamx%d", i).c_str(), std::bind(&debugger_cpu::get_beamx, this, _1, iter.current())); - m_symtable->add(string_format("beamy%d", i).c_str(), std::bind(&debugger_cpu::get_beamy, this, _1, iter.current())); - m_symtable->add(string_format("frame%d", i).c_str(), std::bind(&debugger_cpu::get_frame, this, _1, iter.current())); + screen_device &screen = *iter.current(); + m_symtable->add(string_format("beamx%d", i).c_str(), [&screen]() { return screen.hpos(); }); + m_symtable->add(string_format("beamy%d", i).c_str(), [&screen]() { return screen.vpos(); }); + m_symtable->add(string_format("frame%d", i).c_str(), [&screen]() { return screen.frame_number(); }); iter.current()->register_vblank_callback(vblank_state_delegate(&debugger_cpu::on_vblank, this)); } } @@ -111,10 +112,9 @@ void debugger_cpu::configure_memory(symbol_table &table) { using namespace std::placeholders; table.configure_memory( - &m_machine, - std::bind(&debugger_cpu::expression_validate, this, _1, _2, _3), - std::bind(&debugger_cpu::expression_read_memory, this, _1, _2, _3, _4, _5, _6), - std::bind(&debugger_cpu::expression_write_memory, this, _1, _2, _3, _4, _5, _6, _7)); + std::bind(&debugger_cpu::expression_validate, this, _1, _2), + std::bind(&debugger_cpu::expression_read_memory, this, _1, _2, _3, _4, _5), + std::bind(&debugger_cpu::expression_write_memory, this, _1, _2, _3, _4, _5, _6)); } /*------------------------------------------------- @@ -134,18 +134,18 @@ void debugger_cpu::flush_traces() -/*************************************************************************** - SYMBOL TABLE INTERFACES -***************************************************************************/ +//************************************************************************** +// SYMBOL TABLE INTERFACES +//************************************************************************** -/*------------------------------------------------- - get_visible_symtable - return the - locally-visible symbol table --------------------------------------------------*/ +//------------------------------------------------- +// visible_symtable - return the locally-visible +// symbol table +//------------------------------------------------- -symbol_table* debugger_cpu::get_visible_symtable() +symbol_table &debugger_cpu::visible_symtable() { - return &m_visiblecpu->debug()->symtable(); + return m_visiblecpu->debug()->symtable(); } @@ -630,7 +630,7 @@ device_t* debugger_cpu::expression_get_device(const char *tag) space -------------------------------------------------*/ -u64 debugger_cpu::expression_read_memory(void *param, const char *name, expression_space spacenum, u32 address, int size, bool disable_se) +u64 debugger_cpu::expression_read_memory(const char *name, expression_space spacenum, u32 address, int size, bool disable_se) { switch (spacenum) { @@ -836,7 +836,7 @@ u64 debugger_cpu::expression_read_memory_region(const char *rgntag, offs_t addre space -------------------------------------------------*/ -void debugger_cpu::expression_write_memory(void *param, const char *name, expression_space spacenum, u32 address, int size, u64 data, bool disable_se) +void debugger_cpu::expression_write_memory(const char *name, expression_space spacenum, u32 address, int size, u64 data, bool disable_se) { device_t *device = nullptr; device_memory_interface *memory; @@ -1040,7 +1040,7 @@ void debugger_cpu::expression_write_memory_region(const char *rgntag, offs_t add appropriate name -------------------------------------------------*/ -expression_error::error_code debugger_cpu::expression_validate(void *param, const char *name, expression_space space) +expression_error::error_code debugger_cpu::expression_validate(const char *name, expression_space space) { device_t *device = nullptr; device_memory_interface *memory; @@ -1120,52 +1120,26 @@ expression_error::error_code debugger_cpu::expression_validate(void *param, cons -/*************************************************************************** - VARIABLE GETTERS/SETTERS -***************************************************************************/ - -/*------------------------------------------------- - get_beamx - get beam horizontal position --------------------------------------------------*/ - -u64 debugger_cpu::get_beamx(symbol_table &table, screen_device *screen) -{ - return (screen != nullptr) ? screen->hpos() : 0; -} - - -/*------------------------------------------------- - get_beamy - get beam vertical position --------------------------------------------------*/ - -u64 debugger_cpu::get_beamy(symbol_table &table, screen_device *screen) -{ - return (screen != nullptr) ? screen->vpos() : 0; -} - - -/*------------------------------------------------- - get_frame - get current frame number --------------------------------------------------*/ - -u64 debugger_cpu::get_frame(symbol_table &table, screen_device *screen) -{ - return (screen != nullptr) ? screen->frame_number() : 0; -} - +//************************************************************************** +// VARIABLE GETTERS/SETTERS +//************************************************************************** -/*------------------------------------------------- - get_cpunum - getter callback for the - 'cpunum' symbol --------------------------------------------------*/ +//------------------------------------------------- +// get_cpunum - getter callback for the +// 'cpunum' symbol +//------------------------------------------------- -u64 debugger_cpu::get_cpunum(symbol_table &table) +u64 debugger_cpu::get_cpunum() { execute_interface_iterator iter(m_machine.root_device()); return iter.indexof(m_visiblecpu->execute()); } +//************************************************************************** +// EXECUTION HOOKS +//************************************************************************** + void debugger_cpu::start_hook(device_t *device, bool stop_on_vblank) { // stash a pointer to the current live CPU @@ -1285,7 +1259,7 @@ device_debug::device_debug(device_t &device) , m_state(nullptr) , m_disasm(nullptr) , m_flags(0) - , m_symtable(&device, device.machine().debugger().cpu().get_global_symtable()) + , m_symtable(&device.machine().debugger().cpu().global_symtable()) , m_instrhook(nullptr) , m_stepaddr(0) , m_stepsleft(0) @@ -1338,9 +1312,9 @@ device_debug::device_debug(device_t &device) // add global symbol for cycles and totalcycles if (m_exec != nullptr) { - m_symtable.add("cycles", get_cycles); - m_symtable.add("totalcycles", get_totalcycles); - m_symtable.add("lastinstructioncycles", get_lastinstructioncycles); + m_symtable.add("cycles", [this]() { return m_exec->cycles_remaining(); }); + m_symtable.add("totalcycles", symbol_table::READ_ONLY, &m_total_cycles); + m_symtable.add("lastinstructioncycles", [this]() { return m_total_cycles - m_last_total_cycles; }); } // add entries to enable/disable unmap reporting for each space @@ -1349,23 +1323,23 @@ device_debug::device_debug(device_t &device) if (m_memory->has_space(AS_PROGRAM)) m_symtable.add( "logunmap", - [&space = m_memory->space(AS_PROGRAM)] (symbol_table &table) { return space.log_unmap(); }, - [&space = m_memory->space(AS_PROGRAM)] (symbol_table &table, u64 value) { return space.set_log_unmap(bool(value)); }); + [&space = m_memory->space(AS_PROGRAM)] () { return space.log_unmap(); }, + [&space = m_memory->space(AS_PROGRAM)] (u64 value) { return space.set_log_unmap(bool(value)); }); if (m_memory->has_space(AS_DATA)) m_symtable.add( "logunmap", - [&space = m_memory->space(AS_DATA)] (symbol_table &table) { return space.log_unmap(); }, - [&space = m_memory->space(AS_DATA)] (symbol_table &table, u64 value) { return space.set_log_unmap(bool(value)); }); + [&space = m_memory->space(AS_DATA)] () { return space.log_unmap(); }, + [&space = m_memory->space(AS_DATA)] (u64 value) { return space.set_log_unmap(bool(value)); }); if (m_memory->has_space(AS_IO)) m_symtable.add( "logunmap", - [&space = m_memory->space(AS_IO)] (symbol_table &table) { return space.log_unmap(); }, - [&space = m_memory->space(AS_IO)] (symbol_table &table, u64 value) { return space.set_log_unmap(bool(value)); }); + [&space = m_memory->space(AS_IO)] () { return space.log_unmap(); }, + [&space = m_memory->space(AS_IO)] (u64 value) { return space.set_log_unmap(bool(value)); }); if (m_memory->has_space(AS_OPCODES)) m_symtable.add( "logunmap", - [&space = m_memory->space(AS_OPCODES)] (symbol_table &table) { return space.log_unmap(); }, - [&space = m_memory->space(AS_OPCODES)] (symbol_table &table, u64 value) { return space.set_log_unmap(bool(value)); }); + [&space = m_memory->space(AS_OPCODES)] () { return space.log_unmap(); }, + [&space = m_memory->space(AS_OPCODES)] (u64 value) { return space.set_log_unmap(bool(value)); }); } // add all registers into it @@ -1379,8 +1353,8 @@ device_debug::device_debug(device_t &device) strmakelower(tempstr.assign(entry->symbol())); m_symtable.add( tempstr.c_str(), - std::bind(&device_debug::get_state, _1, entry->index()), - entry->writeable() ? std::bind(&device_debug::set_state, _1, entry->index(), _2) : symbol_table::setter_func(nullptr), + std::bind(&device_state_interface::state_int, m_state, entry->index()), + entry->writeable() ? std::bind(&device_state_interface::set_state_int, m_state, entry->index(), _1) : symbol_table::setter_func(nullptr), entry->format_string()); } } @@ -1393,7 +1367,7 @@ device_debug::device_debug(device_t &device) // if no curpc, add one if (m_state && !m_symtable.find("curpc")) - m_symtable.add("curpc", get_current_pc); + m_symtable.add("curpc", std::bind(&device_state_interface::pcbase, m_state)); } // set up trace @@ -1902,7 +1876,7 @@ void device_debug::go_privilege(const char *condition) { assert(m_exec != nullptr); m_device.machine().rewind_invalidate(); - m_privilege_condition = std::make_unique<parsed_expression>(&m_symtable, condition); + m_privilege_condition = std::make_unique<parsed_expression>(m_symtable, condition); m_flags |= DEBUG_FLAG_STOP_PRIVILEGE; m_device.machine().debugger().cpu().set_execution_running(); } @@ -2636,79 +2610,6 @@ void device_debug::hotspot_check(address_space &space, offs_t address) } } -//------------------------------------------------- -// get_current_pc - getter callback for a device's -// current instruction pointer -//------------------------------------------------- - -u64 device_debug::get_current_pc(symbol_table &table) -{ - device_t *device = reinterpret_cast<device_t *>(table.globalref()); - return device->state().pcbase(); -} - - -//------------------------------------------------- -// get_cycles - getter callback for the -// 'cycles' symbol -//------------------------------------------------- - -u64 device_debug::get_cycles(symbol_table &table) -{ - device_t *device = reinterpret_cast<device_t *>(table.globalref()); - return device->debug()->m_exec->cycles_remaining(); -} - - -//------------------------------------------------- -// get_totalcycles - getter callback for the -// 'totalcycles' symbol -//------------------------------------------------- - -u64 device_debug::get_totalcycles(symbol_table &table) -{ - device_t *device = reinterpret_cast<device_t *>(table.globalref()); - return device->debug()->m_total_cycles; -} - - -//------------------------------------------------- -// get_lastinstructioncycles - getter callback for the -// 'lastinstructioncycles' symbol -//------------------------------------------------- - -u64 device_debug::get_lastinstructioncycles(symbol_table &table) -{ - device_t *device = reinterpret_cast<device_t *>(table.globalref()); - device_debug *debug = device->debug(); - return debug->m_total_cycles - debug->m_last_total_cycles; -} - - -//------------------------------------------------- -// get_state - getter callback for a device's -// state symbols -//------------------------------------------------- - -u64 device_debug::get_state(symbol_table &table, int index) -{ - device_t *device = reinterpret_cast<device_t *>(table.globalref()); - return device->debug()->m_state->state_int(index); -} - - -//------------------------------------------------- -// set_state - setter callback for a device's -// state symbols -//------------------------------------------------- - -void device_debug::set_state(symbol_table &table, int index, u64 value) -{ - device_t *device = reinterpret_cast<device_t *>(table.globalref()); - device->debug()->m_state->set_state_int(index, value); -} - - //************************************************************************** // DEBUG BREAKPOINT @@ -2728,7 +2629,7 @@ device_debug::breakpoint::breakpoint(device_debug* debugInterface, m_index(index), m_enabled(true), m_address(address), - m_condition(&symbols, (condition != nullptr) ? condition : "1"), + m_condition(symbols, (condition != nullptr) ? condition : "1"), m_action((action != nullptr) ? action : "") { } @@ -2792,7 +2693,7 @@ device_debug::watchpoint::watchpoint(device_debug* debugInterface, m_type(type), m_address(address & space.addrmask()), m_length(length), - m_condition(&symbols, (condition != nullptr) ? condition : "1"), + m_condition(symbols, (condition != nullptr) ? condition : "1"), m_action((action != nullptr) ? action : ""), m_installing(false) { @@ -3094,7 +2995,7 @@ void device_debug::watchpoint::triggered(read_or_write type, offs_t address, u64 device_debug::registerpoint::registerpoint(symbol_table &symbols, int index, const char *condition, const char *action) : m_index(index), m_enabled(true), - m_condition(&symbols, (condition != nullptr) ? condition : "1"), + m_condition(symbols, (condition != nullptr) ? condition : "1"), m_action((action != nullptr) ? action : "") { } diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h index 26653eb2baa..8c8a5cc1cbb 100644 --- a/src/emu/debug/debugcpu.h +++ b/src/emu/debug/debugcpu.h @@ -298,14 +298,6 @@ private: void reinstall(address_space &space, read_or_write mode); void write_tracking(address_space &space, offs_t address, u64 data); - // symbol get/set callbacks - static u64 get_current_pc(symbol_table &table); - static u64 get_cycles(symbol_table &table); - static u64 get_totalcycles(symbol_table &table); - static u64 get_lastinstructioncycles(symbol_table &table); - static u64 get_state(symbol_table &table, int index); - static void set_state(symbol_table &table, int index, u64 value); - // basic device information device_t & m_device; // device we are attached to device_execute_interface * m_exec; // execute interface, if present @@ -507,10 +499,10 @@ public: /* ----- symbol table interfaces ----- */ /* return the global symbol table */ - symbol_table *get_global_symtable() { return m_symtable.get(); } + symbol_table &global_symtable() { return *m_symtable; } /* return the locally-visible symbol table */ - symbol_table *get_visible_symtable(); + symbol_table &visible_symtable(); /* ----- debugger comment helpers ----- */ @@ -589,22 +581,19 @@ private: static const size_t NUM_TEMP_VARIABLES; /* expression handlers */ - u64 expression_read_memory(void *param, const char *name, expression_space space, u32 address, int size, bool disable_se); + u64 expression_read_memory(const char *name, expression_space space, u32 address, int size, bool disable_se); u64 expression_read_program_direct(address_space &space, int opcode, offs_t address, int size); u64 expression_read_memory_region(const char *rgntag, offs_t address, int size); - void expression_write_memory(void *param, const char *name, expression_space space, u32 address, int size, u64 data, bool disable_se); + void expression_write_memory(const char *name, expression_space space, u32 address, int size, u64 data, bool disable_se); void expression_write_program_direct(address_space &space, int opcode, offs_t address, int size, u64 data); void expression_write_memory_region(const char *rgntag, offs_t address, int size, u64 data); - expression_error::error_code expression_validate(void *param, const char *name, expression_space space); + expression_error::error_code expression_validate(const char *name, expression_space space); device_t* expression_get_device(const char *tag); - /* variable getters/setters */ - u64 get_cpunum(symbol_table &table); - u64 get_beamx(symbol_table &table, screen_device *screen); - u64 get_beamy(symbol_table &table, screen_device *screen); - u64 get_frame(symbol_table &table, screen_device *screen); + // variable getters/setters + u64 get_cpunum(); - /* internal helpers */ + // internal helpers void on_vblank(screen_device &device, bool vblank_state); running_machine& m_machine; diff --git a/src/emu/debug/debugvw.cpp b/src/emu/debug/debugvw.cpp index de7fcd95b0b..d0d1375cf12 100644 --- a/src/emu/debug/debugvw.cpp +++ b/src/emu/debug/debugvw.cpp @@ -449,7 +449,7 @@ debug_view_expression::debug_view_expression(running_machine &machine) : m_machine(machine) , m_dirty(true) , m_result(0) - , m_parsed(machine.debugger().cpu().get_global_symtable()) + , m_parsed(machine.debugger().cpu().global_symtable()) , m_string("0") { } @@ -471,7 +471,10 @@ debug_view_expression::~debug_view_expression() void debug_view_expression::set_context(symbol_table *context) { - m_parsed.set_symbols((context != nullptr) ? context : m_machine.debugger().cpu().get_global_symtable()); + if (context != nullptr) + m_parsed.set_symbols(*context); + else + m_parsed.set_symbols(m_machine.debugger().cpu().global_symtable()); m_dirty = true; } diff --git a/src/emu/debug/debugvw.h b/src/emu/debug/debugvw.h index e4ae810de45..91c080bf07f 100644 --- a/src/emu/debug/debugvw.h +++ b/src/emu/debug/debugvw.h @@ -267,12 +267,13 @@ public: u64 last_value() const { return m_result; } u64 value() { recompute(); return m_result; } const char *string() const { return m_string.c_str(); } - symbol_table *context() const { return m_parsed.symbols(); } + symbol_table &context() const { return m_parsed.symbols(); } // setters void mark_dirty() { m_dirty = true; } template <typename... Params> void set_string(Params &&... args) { m_string.assign(std::forward<Params>(args)...); m_dirty = true; } void set_context(symbol_table *context); + void set_default_base(int base) { m_parsed.set_default_base(base); } private: // internal helpers diff --git a/src/emu/debug/dvdisasm.cpp b/src/emu/debug/dvdisasm.cpp index 84d228ce3ef..95d72e5cda8 100644 --- a/src/emu/debug/dvdisasm.cpp +++ b/src/emu/debug/dvdisasm.cpp @@ -117,7 +117,11 @@ void debug_view_disasm::view_notify(debug_view_notification type) adjust_visible_y_for_cursor(); else if(type == VIEW_NOTIFY_SOURCE_CHANGED) - m_expression.set_context(&downcast<const debug_view_disasm_source *>(m_source)->device()->debug()->symtable()); + { + const debug_view_disasm_source &source = downcast<const debug_view_disasm_source &>(*m_source); + m_expression.set_context(&source.device()->debug()->symtable()); + m_expression.set_default_base(source.space().is_octal() ? 8 : 16); + } } diff --git a/src/emu/debug/express.cpp b/src/emu/debug/express.cpp index 114ec589951..bb1f17e05f3 100644 --- a/src/emu/debug/express.cpp +++ b/src/emu/debug/express.cpp @@ -47,11 +47,6 @@ CONSTANTS ***************************************************************************/ -#ifndef DEFAULT_BASE -#define DEFAULT_BASE 16 // hex unless otherwise specified -#endif - - // token.value values if token.is_operator() enum { @@ -229,13 +224,13 @@ symbol_entry::~symbol_entry() integer_symbol_entry::integer_symbol_entry(symbol_table &table, const char *name, symbol_table::read_write rw, u64 *ptr) : symbol_entry(table, SMT_INTEGER, name, ""), m_getter(ptr - ? symbol_table::getter_func([ptr] (symbol_table &table) { return *ptr; }) - : symbol_table::getter_func([this] (symbol_table &table) { return m_value; })), + ? symbol_table::getter_func([ptr] () { return *ptr; }) + : symbol_table::getter_func([this] () { return m_value; })), m_setter((rw == symbol_table::READ_ONLY) ? symbol_table::setter_func(nullptr) : ptr - ? symbol_table::setter_func([ptr] (symbol_table &table, u64 value) { *ptr = value; }) - : symbol_table::setter_func([this] (symbol_table &table, u64 value) { m_value = value; })), + ? symbol_table::setter_func([ptr] (u64 value) { *ptr = value; }) + : symbol_table::setter_func([this] (u64 value) { m_value = value; })), m_value(0) { } @@ -243,7 +238,7 @@ integer_symbol_entry::integer_symbol_entry(symbol_table &table, const char *name integer_symbol_entry::integer_symbol_entry(symbol_table &table, const char *name, u64 constval) : symbol_entry(table, SMT_INTEGER, name, ""), - m_getter([this] (symbol_table &table) { return m_value; }), + m_getter([this] () { return m_value; }), m_setter(nullptr), m_value(constval) { @@ -275,7 +270,7 @@ bool integer_symbol_entry::is_lval() const u64 integer_symbol_entry::value() const { - return m_getter(m_table); + return m_getter(); } @@ -286,7 +281,7 @@ u64 integer_symbol_entry::value() const void integer_symbol_entry::set_value(u64 newvalue) { if (m_setter != nullptr) - m_setter(m_table, newvalue); + m_setter(newvalue); else throw emu_fatalerror("Symbol '%s' is read-only", m_name.c_str()); } @@ -350,7 +345,7 @@ u64 function_symbol_entry::execute(int numparams, const u64 *paramlist) throw emu_fatalerror("Function '%s' requires at least %d parameters", m_name.c_str(), m_minparams); if (numparams > m_maxparams) throw emu_fatalerror("Function '%s' accepts no more than %d parameters", m_name.c_str(), m_maxparams); - return m_execute(m_table, numparams, paramlist); + return m_execute(numparams, paramlist); } @@ -363,10 +358,8 @@ u64 function_symbol_entry::execute(int numparams, const u64 *paramlist) // symbol_table - constructor //------------------------------------------------- -symbol_table::symbol_table(void *globalref, symbol_table *parent) +symbol_table::symbol_table(symbol_table *parent) : m_parent(parent), - m_globalref(globalref), - m_memory_param(nullptr), m_memory_valid(nullptr), m_memory_read(nullptr), m_memory_write(nullptr) @@ -378,9 +371,8 @@ symbol_table::symbol_table(void *globalref, symbol_table *parent) // add - add a new u64 pointer symbol //------------------------------------------------- -void symbol_table::configure_memory(void *param, valid_func valid, read_func read, write_func write) +void symbol_table::configure_memory(valid_func valid, read_func read, write_func write) { - m_memory_param = param; m_memory_valid = std::move(valid); m_memory_read = std::move(read); m_memory_write = std::move(write); @@ -483,7 +475,7 @@ expression_error::error_code symbol_table::memory_valid(const char *name, expres for (symbol_table *symtable = this; symtable != nullptr; symtable = symtable->m_parent) if (symtable->m_memory_valid != nullptr) { - expression_error::error_code err = symtable->m_memory_valid(symtable->m_memory_param, name, space); + expression_error::error_code err = symtable->m_memory_valid(name, space); if (err != expression_error::NO_SUCH_MEMORY_SPACE) return err; } @@ -501,9 +493,9 @@ u64 symbol_table::memory_value(const char *name, expression_space space, u32 off for (symbol_table *symtable = this; symtable != nullptr; symtable = symtable->m_parent) if (symtable->m_memory_valid != nullptr) { - expression_error::error_code err = symtable->m_memory_valid(symtable->m_memory_param, name, space); + expression_error::error_code err = symtable->m_memory_valid(name, space); if (err != expression_error::NO_SUCH_MEMORY_SPACE && symtable->m_memory_read != nullptr) - return symtable->m_memory_read(symtable->m_memory_param, name, space, offset, size, disable_se); + return symtable->m_memory_read(name, space, offset, size, disable_se); return 0; } return 0; @@ -520,9 +512,9 @@ void symbol_table::set_memory_value(const char *name, expression_space space, u3 for (symbol_table *symtable = this; symtable != nullptr; symtable = symtable->m_parent) if (symtable->m_memory_valid != nullptr) { - expression_error::error_code err = symtable->m_memory_valid(symtable->m_memory_param, name, space); + expression_error::error_code err = symtable->m_memory_valid(name, space); if (err != expression_error::NO_SUCH_MEMORY_SPACE && symtable->m_memory_write != nullptr) - symtable->m_memory_write(symtable->m_memory_param, name, space, offset, size, value, disable_se); + symtable->m_memory_write(name, space, offset, size, value, disable_se); return; } } @@ -537,16 +529,29 @@ void symbol_table::set_memory_value(const char *name, expression_space space, u3 // parsed_expression - constructor //------------------------------------------------- -parsed_expression::parsed_expression(symbol_table *symtable, const char *expression, u64 *result) +parsed_expression::parsed_expression(symbol_table &symtable, const char *expression, int default_base) : m_symtable(symtable) + , m_default_base(default_base) { + assert(default_base == 8 || default_base == 10 || default_base == 16); + // if we got an expression parse it if (expression != nullptr) parse(expression); +} + - // if we get a result pointer, execute it - if (result != nullptr) - *result = execute(); +//------------------------------------------------- +// parsed_expression - copy constructor +//------------------------------------------------- + +parsed_expression::parsed_expression(const parsed_expression &src) + : m_symtable(src.m_symtable) + , m_default_base(src.m_default_base) + , m_original_string(src.m_original_string) +{ + if (!m_original_string.empty()) + parse_string_into_tokens(); } @@ -576,6 +581,7 @@ void parsed_expression::parse(const char *expression) void parsed_expression::copy(const parsed_expression &src) { m_symtable = src.m_symtable; + m_default_base = src.m_default_base; m_original_string.assign(src.m_original_string); if (!m_original_string.empty()) parse_string_into_tokens(); @@ -942,13 +948,12 @@ void parsed_expression::parse_symbol_or_number(parse_token &token, const char *& catch (expression_error const &err) { // this is really a hack, but 0B1234 could also hex depending on default base - if (expression_error::INVALID_NUMBER == err) - return parse_number(token, buffer.c_str(), DEFAULT_BASE, expression_error::INVALID_NUMBER); + if (expression_error::INVALID_NUMBER == err && m_default_base == 16) + return parse_number(token, buffer.c_str(), m_default_base, expression_error::INVALID_NUMBER); else throw; } - // TODO: for octal address spaces, treat 0123 as octal default: ; // fall through } @@ -956,7 +961,7 @@ void parsed_expression::parse_symbol_or_number(parse_token &token, const char *& default: // check for a symbol match - symbol_entry *symbol = m_symtable->find_deep(buffer.c_str()); + symbol_entry *symbol = m_symtable.get().find_deep(buffer.c_str()); if (symbol != nullptr) { token.configure_symbol(*symbol); @@ -971,7 +976,7 @@ void parsed_expression::parse_symbol_or_number(parse_token &token, const char *& } // attempt to parse as a number in the default base - parse_number(token, buffer.c_str(), DEFAULT_BASE, expression_error::UNKNOWN_SYMBOL); + parse_number(token, buffer.c_str(), m_default_base, expression_error::UNKNOWN_SYMBOL); } } @@ -1149,12 +1154,9 @@ void parsed_expression::parse_memory_operator(parse_token &token, const char *st } // validate the name - if (m_symtable != nullptr) - { - expression_error::error_code err = m_symtable->memory_valid(namestring, memspace); - if (err != expression_error::NONE) - throw expression_error(err, token.offset() + (string - startstring)); - } + expression_error::error_code err = m_symtable.get().memory_valid(namestring, memspace); + if (err != expression_error::NONE) + throw expression_error(err, token.offset() + (string - startstring)); // configure the token token.configure_operator(TVL_MEMORYAT, 2).set_memory_size(memsize).set_memory_space(memspace).set_memory_source(namestring).set_memory_side_effects(disable_se); @@ -1679,16 +1681,15 @@ parsed_expression::parse_token::parse_token(int offset) // for a SYMBOL token //------------------------------------------------- -u64 parsed_expression::parse_token::get_lval_value(symbol_table *table) +u64 parsed_expression::parse_token::get_lval_value(symbol_table &table) { // get the value of a symbol if (is_symbol()) return m_symbol->value(); // or get the value from the memory callbacks - else if (is_memory() && table != nullptr) { - return table->memory_value(m_string, memory_space(), address(), 1 << memory_size(), memory_side_effects()); - } + else if (is_memory()) + return table.memory_value(m_string, memory_space(), address(), 1 << memory_size(), memory_side_effects()); return 0; } @@ -1699,15 +1700,15 @@ u64 parsed_expression::parse_token::get_lval_value(symbol_table *table) // for a SYMBOL token //------------------------------------------------- -inline void parsed_expression::parse_token::set_lval_value(symbol_table *table, u64 value) +inline void parsed_expression::parse_token::set_lval_value(symbol_table &table, u64 value) { // set the value of a symbol if (is_symbol()) m_symbol->set_value(value); // or set the value via the memory callbacks - else if (is_memory() && table != nullptr) - table->set_memory_value(m_string, memory_space(), address(), 1 << memory_size(), value, memory_side_effects()); + else if (is_memory()) + table.set_memory_value(m_string, memory_space(), address(), 1 << memory_size(), value, memory_side_effects()); } diff --git a/src/emu/debug/express.h b/src/emu/debug/express.h index a7147b5dd0f..6b3ac6afa84 100644 --- a/src/emu/debug/express.h +++ b/src/emu/debug/express.h @@ -147,16 +147,16 @@ class symbol_table { public: // callback functions for getting/setting a symbol value - typedef std::function<u64(symbol_table &table)> getter_func; - typedef std::function<void(symbol_table &table, u64 value)> setter_func; + typedef std::function<u64()> getter_func; + typedef std::function<void(u64 value)> setter_func; // callback functions for function execution - typedef std::function<u64(symbol_table &table, int numparams, const u64 *paramlist)> execute_func; + typedef std::function<u64(int numparams, const u64 *paramlist)> execute_func; // callback functions for memory reads/writes - typedef std::function<expression_error::error_code(void *cbparam, const char *name, expression_space space)> valid_func; - typedef std::function<u64(void *cbparam, const char *name, expression_space space, u32 offset, int size, bool disable_se)> read_func; - typedef std::function<void(void *cbparam, const char *name, expression_space space, u32 offset, int size, u64 value, bool disable_se)> write_func; + typedef std::function<expression_error::error_code(const char *name, expression_space space)> valid_func; + typedef std::function<u64(const char *name, expression_space space, u32 offset, int size, bool disable_se)> read_func; + typedef std::function<void(const char *name, expression_space space, u32 offset, int size, u64 value, bool disable_se)> write_func; enum read_write { @@ -165,15 +165,14 @@ public: }; // construction/destruction - symbol_table(void *globalref, symbol_table *parent = nullptr); + symbol_table(symbol_table *parent = nullptr); // getters const std::unordered_map<std::string, std::unique_ptr<symbol_entry>> &entries() const { return m_symlist; } symbol_table *parent() const { return m_parent; } - void *globalref() const { return m_globalref; } // setters - void configure_memory(void *param, valid_func valid, read_func read, write_func write); + void configure_memory(valid_func valid, read_func read, write_func write); // symbol access void add(const char *name, read_write rw, u64 *ptr = nullptr); @@ -195,9 +194,7 @@ public: private: // internal state symbol_table * m_parent; // pointer to the parent symbol table - void * m_globalref; // global reference parameter std::unordered_map<std::string,std::unique_ptr<symbol_entry>> m_symlist; // list of symbols - void * m_memory_param; // callback parameter for memory valid_func m_memory_valid; // validation callback read_func m_memory_read; // read callback write_func m_memory_write; // write callback @@ -212,19 +209,22 @@ class parsed_expression { public: // construction/destruction - parsed_expression(const parsed_expression &src) { copy(src); } - parsed_expression(symbol_table *symtable = nullptr, const char *expression = nullptr, u64 *result = nullptr); + parsed_expression(symbol_table &symtable, const char *expression = nullptr, int default_base = 16); + parsed_expression(const parsed_expression &src); + parsed_expression(parsed_expression &&src) = default; // operators parsed_expression &operator=(const parsed_expression &src) { copy(src); return *this; } + parsed_expression &operator=(parsed_expression &&src) = default; // getters bool is_empty() const { return (m_tokenlist.count() == 0); } const char *original_string() const { return m_original_string.c_str(); } - symbol_table *symbols() const { return m_symtable; } + symbol_table &symbols() const { return m_symtable.get(); } // setters - void set_symbols(symbol_table *symtable) { m_symtable = symtable; } + void set_symbols(symbol_table &symtable) { m_symtable = std::reference_wrapper<symbol_table>(symtable); } + void set_default_base(int base) { assert(base == 8 || base == 10 || base == 16); m_default_base = base; } // execution void parse(const char *string); @@ -312,8 +312,8 @@ private: parse_token &set_memory_source(const char *string) { assert(m_type == OPERATOR || m_type == MEMORY); m_string = string; return *this; } // access - u64 get_lval_value(symbol_table *symtable); - void set_lval_value(symbol_table *symtable, u64 value); + u64 get_lval_value(symbol_table &symtable); + void set_lval_value(symbol_table &symtable, u64 value); private: // internal state @@ -352,7 +352,8 @@ private: static const int MAX_FUNCTION_PARAMS = 16; // internal state - symbol_table * m_symtable; // symbol table + std::reference_wrapper<symbol_table> m_symtable; // symbol table + int m_default_base; // default base std::string m_original_string; // original string (prior to parsing) simple_list<parse_token> m_tokenlist; // token list std::list<std::string> m_stringlist; // string list diff --git a/src/frontend/mame/cheat.cpp b/src/frontend/mame/cheat.cpp index e007f0d8372..00f8c9d67fd 100644 --- a/src/frontend/mame/cheat.cpp +++ b/src/frontend/mame/cheat.cpp @@ -401,8 +401,8 @@ cheat_script::script_entry::script_entry( std::string const &filename, util::xml::data_node const &entrynode, bool isaction) - : m_condition(&symbols) - , m_expression(&symbols) + : m_condition(symbols) + , m_expression(symbols) { char const *expression(nullptr); try @@ -610,7 +610,7 @@ cheat_script::script_entry::output_argument::output_argument( symbol_table &symbols, std::string const &filename, util::xml::data_node const &argnode) - : m_expression(&symbols) + : m_expression(symbols) , m_count(0) { // first extract attributes @@ -679,7 +679,7 @@ void cheat_script::script_entry::output_argument::save(emu_file &cheatfile) cons cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, std::string const &filename, util::xml::data_node const &cheatnode) : m_manager(manager) - , m_symbols(&manager.machine(), &globaltable) + , m_symbols(&globaltable) , m_state(SCRIPT_STATE_OFF) , m_numtemp(DEFAULT_TEMP_VARIABLES) , m_argindex(0) @@ -1058,7 +1058,7 @@ constexpr int cheat_manager::CHEAT_VERSION; cheat_manager::cheat_manager(running_machine &machine) : m_machine(machine) , m_disabled(true) - , m_symtable(&machine) + , m_symtable() { // if the cheat engine is disabled, we're done if (!machine.options().cheat()) @@ -1329,7 +1329,7 @@ std::string cheat_manager::quote_expression(const parsed_expression &expression) // execute_frombcd - convert a value from BCD //------------------------------------------------- -uint64_t cheat_manager::execute_frombcd(symbol_table &table, int params, const uint64_t *param) +uint64_t cheat_manager::execute_frombcd(int params, const uint64_t *param) { uint64_t value(param[0]); uint64_t multiplier(1); @@ -1349,7 +1349,7 @@ uint64_t cheat_manager::execute_frombcd(symbol_table &table, int params, const u // execute_tobcd - convert a value to BCD //------------------------------------------------- -uint64_t cheat_manager::execute_tobcd(symbol_table &table, int params, const uint64_t *param) +uint64_t cheat_manager::execute_tobcd(int params, const uint64_t *param) { uint64_t value(param[0]); uint64_t result(0); diff --git a/src/frontend/mame/cheat.h b/src/frontend/mame/cheat.h index b6faaa85e80..b81225faf15 100644 --- a/src/frontend/mame/cheat.h +++ b/src/frontend/mame/cheat.h @@ -327,8 +327,8 @@ public: // global helpers static std::string quote_expression(parsed_expression const &expression); - static uint64_t execute_frombcd(symbol_table &table, int params, uint64_t const *param); - static uint64_t execute_tobcd(symbol_table &table, int params, uint64_t const *param); + static uint64_t execute_frombcd(int params, uint64_t const *param); + static uint64_t execute_tobcd(int params, uint64_t const *param); private: // internal helpers |