Merge pull request #1561 from npwoods/dasmstream_i386

Changed the x86 disassembler to use 'std::ostream &' internally
This commit is contained in:
R. Belmont 2016-10-27 23:17:37 -04:00 committed by GitHub
commit bd964a7db3
5 changed files with 340 additions and 316 deletions

View File

@ -3993,7 +3993,11 @@ bool i386_device::memory_translate(address_spacenum spacenum, int intention, off
offs_t i386_device::disasm_disassemble(char *buffer, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options)
{
return i386_dasm_one(buffer, pc, oprom, m_sreg[CS].d ? 32 : 16);
std::ostringstream stream;
offs_t result = i386_dasm_one(stream, pc, oprom, m_sreg[CS].d ? 32 : 16);
std::string stream_str = stream.str();
strcpy(buffer, stream_str.c_str());
return result;
}

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
#define MMXOP(XX) mmx_##XX
#define SSEOP(XX) sse_##XX
extern int i386_dasm_one(char *buffer, uint32_t pc, const uint8_t *oprom, int mode);
extern int i386_dasm_one(std::ostream &stream, uint32_t pc, const uint8_t *oprom, int mode);
enum SREGS { ES, CS, SS, DS, FS, GS };

View File

@ -510,8 +510,12 @@ void i8086_common_cpu_device::execute_set_input( int inptnum, int state )
offs_t i8086_common_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const uint8_t *oprom, const uint8_t *opram, uint32_t options)
{
extern int i386_dasm_one(char *buffer, offs_t eip, const uint8_t *oprom, int mode);
return i386_dasm_one(buffer, pc, oprom, 1);
extern int i386_dasm_one(std::ostream &stream, offs_t eip, const uint8_t *oprom, int mode);
std::ostringstream stream;
offs_t result = i386_dasm_one(stream, pc, oprom, 1);
std::string stream_str = stream.str();
strcpy(buffer, stream_str.c_str());
return result;
}
uint8_t i8086_common_cpu_device::read_port_byte(uint16_t port)

View File

@ -20,7 +20,7 @@
***************************************************************************/
static void reset_log(x86log_context *log) noexcept;
extern int i386_dasm_one_ex(char *buffer, uint64_t eip, const uint8_t *oprom, int mode);
extern int i386_dasm_one_ex(std::ostream &stream, uint64_t eip, const uint8_t *oprom, int mode);
@ -111,7 +111,7 @@ void x86log_disasm_code_range(x86log_context *log, const char *label, x86code *s
/* loop from the start until the cache top */
while (cur < stop)
{
char buffer[100];
std::string buffer;
int bytes;
/* skip past any past data ranges */
@ -129,10 +129,10 @@ void x86log_disasm_code_range(x86log_context *log, const char *label, x86code *s
switch (curdata->size)
{
default:
case 1: sprintf(buffer, "db %02X", *cur); break;
case 2: sprintf(buffer, "dw %04X", *(uint16_t *)cur); break;
case 4: sprintf(buffer, "dd %08X", *(uint32_t *)cur); break;
case 8: sprintf(buffer, "dq %08X%08X", ((uint32_t *)cur)[1], ((uint32_t *)cur)[0]); break;
case 1: buffer = string_format("db %02X", *cur); break;
case 2: buffer = string_format("dw %04X", *(uint16_t *)cur); break;
case 4: buffer = string_format("dd %08X", *(uint32_t *)cur); break;
case 8: buffer = string_format("dq %08X%08X", ((uint32_t *)cur)[1], ((uint32_t *)cur)[0]); break;
}
}
@ -146,7 +146,9 @@ void x86log_disasm_code_range(x86log_context *log, const char *label, x86code *s
/* otherwise, do a disassembly of the current instruction */
else
{
bytes = i386_dasm_one_ex(buffer, (uintptr_t)cur, cur, sizeof(void *) * 8) & DASMFLAG_LENGTHMASK;
std::stringstream strbuffer;
bytes = i386_dasm_one_ex(strbuffer, (uintptr_t)cur, cur, sizeof(void *) * 8) & DASMFLAG_LENGTHMASK;
buffer = strbuffer.str();
}
/* if we have a matching comment, output it */
@ -155,12 +157,12 @@ void x86log_disasm_code_range(x86log_context *log, const char *label, x86code *s
/* if we have additional matching comments at the same address, output them first */
for ( ; curcomment + 1 < lastcomment && cur == curcomment[1].base; curcomment++)
x86log_printf(log, "%p: %-50s; %s\n", cur, "", curcomment->string);
x86log_printf(log, "%p: %-50s; %s\n", cur, buffer, curcomment->string);
x86log_printf(log, "%p: %-50s; %s\n", cur, buffer.c_str(), curcomment->string);
}
/* if we don't, just print the disassembly and move on */
else
x86log_printf(log, "%p: %s\n", cur, buffer);
x86log_printf(log, "%p: %s\n", cur, buffer.c_str());
/* advance past this instruction */
cur += bytes;