Branch: Tag:

2017-01-23

2017-01-23 15:03:26 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler [amd64]: Use string_builder_append_disassembly().

Improved formatting of disassembler output by using the new function.

5105:      void amd64_disassemble_code(PIKE_OPCODE_T *pc, size_t len)   { +  struct string_builder buf;    size_t pos; -  +  +  init_string_builder(&buf, 0);    for (pos = 0; pos < len;) {    size_t op_start = pos;    size_t i;
5119:    struct amd64_opcode *op;    char buffers[4][256];    + #if 0    fprintf(stderr, "%p:\t", pc + pos); -  + #endif       // Handle prefixes.    while(1) {
5178:    }    } else if (op->flags & OP_PCREL) {    INT32 val; -  if (!params[1]) { -  params[1] = buffers[1]; -  buffers[1][0] = 0; +  if (!params[0]) { +  params[0] = buffers[0]; +  buffers[0][0] = 0;    }    if (op->flags & (OP_8|OP_S8)) {    val = ((signed char *)pc)[pos++];
5188:    val = ((INT32 *)(pc + pos))[0];    pos += 4;    } -  sprintf(buffers[1] + strlen(buffers[1]), "%p", pc + (pos + val)); +  sprintf(buffers[0] + strlen(buffers[0]), "%p", pc + (pos + val));    }       if (op->flags & OP_B_RM) {
5198:    params[1] = tmp;    }    + #if 1 +  string_builder_append_disassembly(&buf, pc + op_start, pc + pos, +  opcode, params, NULL); + #else    if (opcode) {    fprintf(stderr, "%s", opcode);   
5221:    fprintf(stderr, " %02x", pc[op_start + i]);    }    fprintf(stderr, "\n"); + #endif    } -  + #if 1 +  string_builder_putchar(&buf, 0); +  fprintf(stderr, "%s", buf.s->str); +  free_string_builder(&buf); + #endif   }