diff options
-rw-r--r-- | lldb/include/lldb/lldb-enumerations.h | 1 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Core/DataExtractor.cpp | 34 | ||||
-rw-r--r-- | lldb/source/DataFormatters/FormatManager.cpp | 1 |
4 files changed, 40 insertions, 0 deletions
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index cfc68f19732..fcca562e977 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -125,6 +125,7 @@ namespace lldb { eFormatAddressInfo, // Describe what an address points to (func + offset with file/line, symbol + offset, data, etc) eFormatHexFloat, // ISO C99 hex float string eFormatInstruction, // Disassemble an opcode + eFormatHalfFloat, // Half-floats (IEEE-754-2008 binary16 interchange format) eFormatVoid, // Do not print this kNumFormats } Format; diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index fe44ad052ab..8bf303e08e8 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -180,12 +180,15 @@ public: case eFormatUnicode32: case eFormatUnsigned: case eFormatHexFloat: + case eFormatHalfFloat: if (!byte_size_option_set) byte_size_value = 4; if (!num_per_line_option_set) m_num_per_line = 1; if (!count_option_set) format_options.GetCountValue() = 8; + if (format_options.GetFormat() == eFormatFloat && byte_size_option_set && byte_size_value == 2) + format_options.GetFormatValue().SetCurrentValue(eFormatHalfFloat); break; case eFormatBytes: @@ -1170,6 +1173,7 @@ protected: case eFormatComplexInteger: case eFormatAddressInfo: case eFormatHexFloat: + case eFormatHalfFloat: case eFormatInstruction: case eFormatVoid: result.AppendError("unsupported format for writing memory"); diff --git a/lldb/source/Core/DataExtractor.cpp b/lldb/source/Core/DataExtractor.cpp index aa567f8f339..64d2929f119 100644 --- a/lldb/source/Core/DataExtractor.cpp +++ b/lldb/source/Core/DataExtractor.cpp @@ -1302,6 +1302,22 @@ DumpAPInt (Stream *s, const DataExtractor &data, lldb::offset_t offset, lldb::of return offset; } +static float half2float (uint16_t half) +{ + union{ float f; uint32_t u;}u; + int32_t v = (int16_t) half; + + if( 0 == (v & 0x7c00)) + { + u.u = v & 0x80007FFFU; + return u.f * 0x1.0p125f; + } + + v <<= 13; + u.u = v | 0x70000000U; + return u.f * 0x1.0p-112f; +} + lldb::offset_t DataExtractor::Dump (Stream *s, offset_t start_offset, @@ -1712,6 +1728,24 @@ DataExtractor::Dump (Stream *s, } break; + case eFormatHalfFloat: + { + std::ostringstream ss; + if (item_byte_size == 2) + { + uint16_t half = this->GetU16(&offset); + float half_converted = half2float(half); + ss << half_converted; + } + else + { + s->Printf("error: unsupported byte size (%zu) for half-float format", item_byte_size); + return offset; + } + ss.flush(); + s->Printf("%s", ss.str().c_str()); + } + break; case eFormatUnicode16: s->Printf("U+%4.4x", GetU16 (&offset)); break; diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 28c3f82e2df..1a3b2ae5f86 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -72,6 +72,7 @@ g_format_infos[] = { eFormatCharArray , 'a' , "character array" }, { eFormatAddressInfo , 'A' , "address" }, { eFormatHexFloat , '\0' , "hex float" }, + { eFormatHalfFloat , '\0' , "half float" }, { eFormatInstruction , 'i' , "instruction" }, { eFormatVoid , 'v' , "void" } }; |