From: Andrew Waterman Date: Fri, 24 Aug 2018 19:15:03 +0000 (-0700) Subject: Handle spike-dasm inputs with leading 0x correctly X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=aff796dbf6db66a2df53b0ca270382f0ce02da74;p=riscv-isa-sim.git Handle spike-dasm inputs with leading 0x correctly --- diff --git a/spike_main/spike-dasm.cc b/spike_main/spike-dasm.cc index 2852835..1161825 100644 --- a/spike_main/spike-dasm.cc +++ b/spike_main/spike-dasm.cc @@ -31,22 +31,30 @@ int main(int argc, char** argv) while (getline(cin, s)) { - for (size_t start = 0; (start = s.find("DASM(", start)) != string::npos; ) + for (size_t pos = 0; (pos = s.find("DASM(", pos)) != string::npos; ) { - size_t end = s.find(')', start); - if (end == string::npos) - break; + size_t start = pos; + + pos += strlen("DASM("); + + if (s[pos] == '0' && (s[pos+1] == 'x' || s[pos+1] == 'X')) + pos += 2; + + if (!isxdigit(s[pos])) + continue; char* endp; - size_t numstart = start + strlen("DASM("); - int64_t bits = strtoull(&s[numstart], &endp, 16); - size_t nbits = 4 * (endp - &s[numstart]); + int64_t bits = strtoull(&s[pos], &endp, 16); + if (*endp != ')') + continue; + + size_t nbits = 4 * (endp - &s[pos]); if (nbits < 64) bits = bits << (64 - nbits) >> (64 - nbits); string dis = p.get_disassembler()->disassemble(bits); - s = s.substr(0, start) + dis + s.substr(end+1); - start += dis.length(); + s = s.substr(0, start) + dis + s.substr(endp - &s[0] + 1); + pos = start + dis.length(); } cout << s << '\n';