Skip to content

Commit 8b5b1f9

Browse files
committed
unboxed float and int printing
1 parent e61c2f5 commit 8b5b1f9

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,17 @@ void PrintAPIntAsFloat(Stream *s, llvm::APInt apint,
433433
else
434434
apfloat.toPossiblyShortString(sv);
435435

436-
s->AsRawOstream() << prefix;
437-
s->AsRawOstream() << sv;
438436
// OCaml Specific:
437+
// Handle negative sign placement for OCaml format
438+
if (sv.size() > 0 && sv[0] == '-') {
439+
s->AsRawOstream() << "-";
440+
s->AsRawOstream() << prefix;
441+
s->AsRawOstream() << llvm::StringRef(sv.data() + 1, sv.size() - 1);
442+
} else {
443+
s->AsRawOstream() << prefix;
444+
s->AsRawOstream() << sv;
445+
}
446+
439447
// Following OCaml conventions, print the trailing ".0" to
440448
// identify that the integer is in fact a float, but don't
441449
// print any trailing zeros beyond that.
@@ -963,11 +971,26 @@ lldb::offset_t lldb_private::DumpDataExtractor(
963971
case eFormatEnum: // Print enum value as a signed integer when we don't get
964972
// the enum type
965973
case eFormatDecimal:
966-
if (item_byte_size <= 8)
967-
s->Printf("%" PRId64,
968-
DE.GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size,
969-
item_bit_offset));
970-
else {
974+
if (item_byte_size <= 8) {
975+
int64_t value = DE.GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size,
976+
item_bit_offset);
977+
// CR sspies: This is special cases for OCaml values. Consider wrapping
978+
// it in a guard.
979+
// Format as unboxed OCaml integer
980+
std::string suffix = "";
981+
if (item_byte_size == 4) suffix = "l";
982+
else if (item_byte_size == 8) suffix = "L";
983+
else if (item_byte_size == 2) suffix = ""; // int16 - no specific suffix
984+
else if (item_byte_size == 1) suffix = ""; // int8 - no specific suffix
985+
// Add "n" suffix for nativeint when it's pointer-sized (could be 4 or 8 bytes)
986+
987+
988+
if (value < 0) {
989+
s->Printf("-#%" PRId64 "%s", -value, suffix.c_str());
990+
} else {
991+
s->Printf("#%" PRId64 "%s", value, suffix.c_str());
992+
}
993+
} else {
971994
const bool is_signed = true;
972995
const unsigned radix = 10;
973996
offset = DumpAPInt(s, DE, offset, item_byte_size, is_signed, radix);

0 commit comments

Comments
 (0)