diff --git a/disassembler.cpp b/disassembler.cpp index cf433fc..f33eddb 100644 --- a/disassembler.cpp +++ b/disassembler.cpp @@ -498,13 +498,52 @@ void disassembler::flush() { void disassembler::check_labels() { if ( _next_label >= 0 && _pc + _st >= _next_label) { - //flush(); + //flush(); // -- too recursive. see above. if (_st) dump(); _next_label = next_label(_pc); } } + +void disassembler::space(unsigned size) { + flush(); + + std::string line; + + indent_to(line, kOpcodeTab); + line += "ds"; + indent_to(line, kOperandTab); + + + while (size) { + uint32_t chunk; + if (_next_label == -1) chunk = size; + else { + chunk = _next_label - _pc; + chunk = std::min(chunk, size); + } + + line.resize(kOperandTab); + line += std::to_string(chunk); + indent_to(line, kCommentTab); + line += "; "; + + line += to_x(_pc, 4); + line.push_back(':'); + line.push_back('\n'); + fputs(line.c_str(), stdout); + + + _pc += chunk; + size -= chunk; + if (_next_label == _pc) _next_label = next_label(_pc); + } + + +} + + void disassembler::operator()(const std::string &expr, unsigned size) { // todo -- what if label within size? @@ -565,6 +604,8 @@ void disassembler::operator()(uint8_t byte) { print(); } + + void disassembler::print_prefix() { switch(_mode & 0xf000) { diff --git a/disassembler.h b/disassembler.h index 9ed7c16..e9074f5 100644 --- a/disassembler.h +++ b/disassembler.h @@ -19,6 +19,7 @@ class disassembler { template void operator()(const T &t) { code(std::begin(t), std::end(t)); } + void space(unsigned bytes); bool m() const { return _flags & 0x20; } bool x() const { return _flags & 0x10; } diff --git a/dumpobj.cpp b/dumpobj.cpp index 0198b9a..80636b1 100644 --- a/dumpobj.cpp +++ b/dumpobj.cpp @@ -244,9 +244,7 @@ bool dump_obj(const char *name, int fd) zrdz_disassembler d(read_sections(section_data), read_symbols(symbol_data)); uint8_t op = REC_END; - unsigned section = SECT_CODE; // default section = CODE unsigned line = 0; - std::string file; d.front_matter(std::string(oname.data())); @@ -393,7 +391,7 @@ bool dump_obj(const char *name, int fd) d.emit("", "longi", "off"); break; case D_C_FILE: { - file = read_cstring(iter); + std::string file = read_cstring(iter); line = read_16(iter); std::string tmp = file + ", " + std::to_string(line); d.emit("", ".file", tmp); @@ -539,11 +537,8 @@ bool dump_obj(const char *name, int fd) } case REC_SPACE: { - d.flush(); uint16_t count = read_16(iter); - // todo -- need to coordinate with label printer/disassembler. - d.emit("", "ds", d.to_x(count, 4, '$')); - d.set_pc(d.pc() + count); + d.space(count); break; }