[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Stream.cpp --------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-02-17 03:38:21 +08:00
|
|
|
|
2017-02-15 03:06:07 +08:00
|
|
|
#include "lldb/Utility/Endian.h"
|
2017-02-17 03:38:21 +08:00
|
|
|
#include "lldb/Utility/VASPrintf.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2019-12-05 21:41:09 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2018-08-04 04:51:31 +08:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2017-04-07 02:12:24 +08:00
|
|
|
|
|
|
|
#include <string>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cinttypes>
|
|
|
|
#include <cstddef>
|
2012-11-30 05:49:15 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-06-10 01:21:09 +08:00
|
|
|
Stream::Stream(uint32_t flags, uint32_t addr_size, ByteOrder byte_order,
|
|
|
|
bool colors)
|
2010-06-09 00:52:24 +08:00
|
|
|
: m_flags(flags), m_addr_size(addr_size), m_byte_order(byte_order),
|
2022-03-15 04:32:03 +08:00
|
|
|
m_forwarder(*this, colors) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-06-10 01:21:09 +08:00
|
|
|
Stream::Stream(bool colors)
|
2015-11-07 12:40:13 +08:00
|
|
|
: m_flags(0), m_byte_order(endian::InlHostByteOrder()),
|
2020-06-10 01:21:09 +08:00
|
|
|
m_forwarder(*this, colors) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Destructor
|
2021-07-03 02:27:37 +08:00
|
|
|
Stream::~Stream() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
ByteOrder Stream::SetByteOrder(ByteOrder byte_order) {
|
|
|
|
ByteOrder old_byte_order = m_byte_order;
|
|
|
|
m_byte_order = byte_order;
|
|
|
|
return old_byte_order;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Put an offset "uval" out to the stream using the printf format in "format".
|
2010-06-09 00:52:24 +08:00
|
|
|
void Stream::Offset(uint32_t uval, const char *format) { Printf(format, uval); }
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Put an SLEB128 "uval" out to the stream using the printf format in "format".
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutSLEB128(int64_t sval) {
|
2018-08-04 04:51:31 +08:00
|
|
|
if (m_flags.Test(eBinary))
|
|
|
|
return llvm::encodeSLEB128(sval, m_forwarder);
|
|
|
|
else
|
|
|
|
return Printf("0x%" PRIi64, sval);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Put an ULEB128 "uval" out to the stream using the printf format in "format".
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutULEB128(uint64_t uval) {
|
2018-08-04 04:51:31 +08:00
|
|
|
if (m_flags.Test(eBinary))
|
|
|
|
return llvm::encodeULEB128(uval, m_forwarder);
|
|
|
|
else
|
|
|
|
return Printf("0x%" PRIx64, uval);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-01 01:18:40 +08:00
|
|
|
// Print a raw NULL terminated C string to the stream.
|
2016-10-07 05:22:44 +08:00
|
|
|
size_t Stream::PutCString(llvm::StringRef str) {
|
|
|
|
size_t bytes_written = 0;
|
|
|
|
bytes_written = Write(str.data(), str.size());
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// when in binary mode, emit the NULL terminator
|
2010-10-27 11:32:59 +08:00
|
|
|
if (m_flags.Test(eBinary))
|
2016-10-07 05:22:44 +08:00
|
|
|
bytes_written += PutChar('\0');
|
|
|
|
return bytes_written;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Print a double quoted NULL terminated C string to the stream using the
|
|
|
|
// printf format in "format".
|
2010-06-09 00:52:24 +08:00
|
|
|
void Stream::QuotedCString(const char *cstr, const char *format) {
|
|
|
|
Printf(format, cstr);
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Put an address "addr" out to the stream with optional prefix and suffix
|
|
|
|
// strings.
|
2019-12-05 21:41:09 +08:00
|
|
|
void lldb_private::DumpAddress(llvm::raw_ostream &s, uint64_t addr,
|
|
|
|
uint32_t addr_size, const char *prefix,
|
|
|
|
const char *suffix) {
|
2018-12-13 08:15:17 +08:00
|
|
|
if (prefix == nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
prefix = "";
|
2018-12-13 08:15:17 +08:00
|
|
|
if (suffix == nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
suffix = "";
|
2019-12-05 21:41:09 +08:00
|
|
|
s << prefix << llvm::format_hex(addr, 2 + 2 * addr_size) << suffix;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Put an address range out to the stream with optional prefix and suffix
|
|
|
|
// strings.
|
2019-12-05 21:41:09 +08:00
|
|
|
void lldb_private::DumpAddressRange(llvm::raw_ostream &s, uint64_t lo_addr,
|
|
|
|
uint64_t hi_addr, uint32_t addr_size,
|
|
|
|
const char *prefix, const char *suffix) {
|
2011-11-28 08:51:27 +08:00
|
|
|
if (prefix && prefix[0])
|
2019-12-05 21:41:09 +08:00
|
|
|
s << prefix;
|
|
|
|
DumpAddress(s, lo_addr, addr_size, "[");
|
|
|
|
DumpAddress(s, hi_addr, addr_size, "-", ")");
|
2011-11-28 08:51:27 +08:00
|
|
|
if (suffix && suffix[0])
|
2019-12-05 21:41:09 +08:00
|
|
|
s << suffix;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t Stream::PutChar(char ch) { return Write(&ch, 1); }
|
|
|
|
|
|
|
|
// Print some formatted output to the stream.
|
|
|
|
size_t Stream::Printf(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
size_t result = PrintfVarArg(format, args);
|
|
|
|
va_end(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print some formatted output to the stream.
|
|
|
|
size_t Stream::PrintfVarArg(const char *format, va_list args) {
|
2017-02-17 03:38:21 +08:00
|
|
|
llvm::SmallString<1024> buf;
|
|
|
|
VASprintf(buf, format, args);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-02-17 03:38:21 +08:00
|
|
|
// Include the NULL termination byte for binary output
|
|
|
|
size_t length = buf.size();
|
|
|
|
if (m_flags.Test(eBinary))
|
|
|
|
++length;
|
|
|
|
return Write(buf.c_str(), length);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print and End of Line character to the stream
|
|
|
|
size_t Stream::EOL() { return PutChar('\n'); }
|
|
|
|
|
2016-10-06 05:14:38 +08:00
|
|
|
size_t Stream::Indent(llvm::StringRef str) {
|
2020-02-25 13:25:55 +08:00
|
|
|
const size_t ind_length = PutCString(std::string(m_indent_level, ' '));
|
|
|
|
const size_t str_length = PutCString(str);
|
|
|
|
return ind_length + str_length;
|
2016-10-06 05:14:38 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Stream a character "ch" out to this stream.
|
|
|
|
Stream &Stream::operator<<(char ch) {
|
|
|
|
PutChar(ch);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stream the NULL terminated C string out to this stream.
|
|
|
|
Stream &Stream::operator<<(const char *s) {
|
|
|
|
Printf("%s", s);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:12:42 +08:00
|
|
|
Stream &Stream::operator<<(llvm::StringRef str) {
|
|
|
|
Write(str.data(), str.size());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Stream the pointer value out to this stream.
|
2015-07-22 15:58:17 +08:00
|
|
|
Stream &Stream::operator<<(const void *p) {
|
2019-05-23 13:12:11 +08:00
|
|
|
Printf("0x%.*tx", static_cast<int>(sizeof(const void *)) * 2, (ptrdiff_t)p);
|
2010-06-09 00:52:24 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the current indentation level
|
2019-12-02 19:44:55 +08:00
|
|
|
unsigned Stream::GetIndentLevel() const { return m_indent_level; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Set the current indentation level
|
2019-12-02 19:44:55 +08:00
|
|
|
void Stream::SetIndentLevel(unsigned indent_level) {
|
|
|
|
m_indent_level = indent_level;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Increment the current indentation level
|
2019-12-02 19:44:55 +08:00
|
|
|
void Stream::IndentMore(unsigned amount) { m_indent_level += amount; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Decrement the current indentation level
|
2019-12-02 19:44:55 +08:00
|
|
|
void Stream::IndentLess(unsigned amount) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_indent_level >= amount)
|
|
|
|
m_indent_level -= amount;
|
|
|
|
else
|
|
|
|
m_indent_level = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the address size in bytes
|
|
|
|
uint32_t Stream::GetAddressByteSize() const { return m_addr_size; }
|
|
|
|
|
|
|
|
// Set the address size in bytes
|
2013-01-26 02:06:21 +08:00
|
|
|
void Stream::SetAddressByteSize(uint32_t addr_size) { m_addr_size = addr_size; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// The flags get accessor
|
|
|
|
Flags &Stream::GetFlags() { return m_flags; }
|
|
|
|
|
|
|
|
// The flags const get accessor
|
|
|
|
const Flags &Stream::GetFlags() const { return m_flags; }
|
|
|
|
|
2010-07-02 10:43:42 +08:00
|
|
|
// The byte order get accessor
|
|
|
|
|
|
|
|
lldb::ByteOrder Stream::GetByteOrder() const { return m_byte_order; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PrintfAsRawHex8(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-02-17 03:38:21 +08:00
|
|
|
llvm::SmallString<1024> buf;
|
|
|
|
VASprintf(buf, format, args);
|
|
|
|
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
2017-02-17 03:38:21 +08:00
|
|
|
for (char C : buf)
|
2018-09-12 18:20:41 +08:00
|
|
|
_PutHex8(C, false);
|
2017-02-17 03:38:21 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
va_end(args);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutNHex8(size_t n, uint8_t uvalue) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
2010-07-10 04:39:50 +08:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
2018-09-12 18:20:41 +08:00
|
|
|
_PutHex8(uvalue, false);
|
|
|
|
return *delta;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-12 18:20:41 +08:00
|
|
|
void Stream::_PutHex8(uint8_t uvalue, bool add_prefix) {
|
2010-10-27 11:32:59 +08:00
|
|
|
if (m_flags.Test(eBinary)) {
|
2018-09-12 18:20:41 +08:00
|
|
|
Write(&uvalue, 1);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
|
|
|
if (add_prefix)
|
|
|
|
PutCString("0x");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
static char g_hex_to_ascii_hex_char[16] = {'0', '1', '2', '3', '4', '5',
|
|
|
|
'6', '7', '8', '9', 'a', 'b',
|
|
|
|
'c', 'd', 'e', 'f'};
|
|
|
|
char nibble_chars[2];
|
|
|
|
nibble_chars[0] = g_hex_to_ascii_hex_char[(uvalue >> 4) & 0xf];
|
|
|
|
nibble_chars[1] = g_hex_to_ascii_hex_char[(uvalue >> 0) & 0xf];
|
2018-09-12 18:20:41 +08:00
|
|
|
Write(nibble_chars, sizeof(nibble_chars));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-12 18:20:41 +08:00
|
|
|
size_t Stream::PutHex8(uint8_t uvalue) {
|
|
|
|
ByteDelta delta(*this);
|
|
|
|
_PutHex8(uvalue, false);
|
|
|
|
return *delta;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
size_t Stream::PutHex16(uint16_t uvalue, ByteOrder byte_order) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (byte_order == eByteOrderInvalid)
|
|
|
|
byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (byte_order == eByteOrderLittle) {
|
2017-01-13 18:41:59 +08:00
|
|
|
for (size_t byte = 0; byte < sizeof(uvalue); ++byte)
|
2019-05-23 13:12:11 +08:00
|
|
|
_PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2017-01-13 18:41:59 +08:00
|
|
|
for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte)
|
2019-05-23 13:12:11 +08:00
|
|
|
_PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutHex32(uint32_t uvalue, ByteOrder byte_order) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (byte_order == eByteOrderInvalid)
|
|
|
|
byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (byte_order == eByteOrderLittle) {
|
2017-01-13 18:41:59 +08:00
|
|
|
for (size_t byte = 0; byte < sizeof(uvalue); ++byte)
|
2019-05-23 13:12:11 +08:00
|
|
|
_PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2017-01-13 18:41:59 +08:00
|
|
|
for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte)
|
2019-05-23 13:12:11 +08:00
|
|
|
_PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutHex64(uint64_t uvalue, ByteOrder byte_order) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (byte_order == eByteOrderInvalid)
|
|
|
|
byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (byte_order == eByteOrderLittle) {
|
2017-01-13 18:41:59 +08:00
|
|
|
for (size_t byte = 0; byte < sizeof(uvalue); ++byte)
|
2019-05-23 13:12:11 +08:00
|
|
|
_PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2017-01-13 18:41:59 +08:00
|
|
|
for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte)
|
2019-05-23 13:12:11 +08:00
|
|
|
_PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutMaxHex64(uint64_t uvalue, size_t byte_size,
|
|
|
|
lldb::ByteOrder byte_order) {
|
|
|
|
switch (byte_size) {
|
2013-01-26 02:06:21 +08:00
|
|
|
case 1:
|
2019-05-23 13:12:11 +08:00
|
|
|
return PutHex8(static_cast<uint8_t>(uvalue));
|
2013-01-26 02:06:21 +08:00
|
|
|
case 2:
|
2019-05-23 13:12:11 +08:00
|
|
|
return PutHex16(static_cast<uint16_t>(uvalue), byte_order);
|
2013-01-26 02:06:21 +08:00
|
|
|
case 4:
|
2019-05-23 13:12:11 +08:00
|
|
|
return PutHex32(static_cast<uint32_t>(uvalue), byte_order);
|
2010-06-09 00:52:24 +08:00
|
|
|
case 8:
|
2018-08-02 01:12:58 +08:00
|
|
|
return PutHex64(uvalue, byte_order);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutPointer(void *ptr) {
|
2015-11-07 12:40:13 +08:00
|
|
|
return PutRawBytes(&ptr, sizeof(ptr), endian::InlHostByteOrder(),
|
|
|
|
endian::InlHostByteOrder());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutFloat(float f, ByteOrder byte_order) {
|
|
|
|
if (byte_order == eByteOrderInvalid)
|
|
|
|
byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-07 12:40:13 +08:00
|
|
|
return PutRawBytes(&f, sizeof(f), endian::InlHostByteOrder(), byte_order);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutDouble(double d, ByteOrder byte_order) {
|
|
|
|
if (byte_order == eByteOrderInvalid)
|
|
|
|
byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-07 12:40:13 +08:00
|
|
|
return PutRawBytes(&d, sizeof(d), endian::InlHostByteOrder(), byte_order);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutLongDouble(long double ld, ByteOrder byte_order) {
|
|
|
|
if (byte_order == eByteOrderInvalid)
|
|
|
|
byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-07 12:40:13 +08:00
|
|
|
return PutRawBytes(&ld, sizeof(ld), endian::InlHostByteOrder(), byte_order);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutRawBytes(const void *s, size_t src_len,
|
|
|
|
ByteOrder src_byte_order, ByteOrder dst_byte_order) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (src_byte_order == eByteOrderInvalid)
|
|
|
|
src_byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (dst_byte_order == eByteOrderInvalid)
|
|
|
|
dst_byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-05-23 13:12:11 +08:00
|
|
|
const uint8_t *src = static_cast<const uint8_t *>(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
bool binary_was_set = m_flags.Test(eBinary);
|
|
|
|
if (!binary_was_set)
|
|
|
|
m_flags.Set(eBinary);
|
|
|
|
if (src_byte_order == dst_byte_order) {
|
|
|
|
for (size_t i = 0; i < src_len; ++i)
|
2018-09-12 18:20:41 +08:00
|
|
|
_PutHex8(src[i], false);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2022-02-16 12:35:52 +08:00
|
|
|
for (size_t i = src_len; i > 0; --i)
|
|
|
|
_PutHex8(src[i - 1], false);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-27 11:32:59 +08:00
|
|
|
if (!binary_was_set)
|
2010-06-09 00:52:24 +08:00
|
|
|
m_flags.Clear(eBinary);
|
|
|
|
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t Stream::PutBytesAsRawHex8(const void *s, size_t src_len,
|
|
|
|
ByteOrder src_byte_order,
|
|
|
|
ByteOrder dst_byte_order) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
2022-02-16 12:35:52 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (src_byte_order == eByteOrderInvalid)
|
|
|
|
src_byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (dst_byte_order == eByteOrderInvalid)
|
|
|
|
dst_byte_order = m_byte_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-05-23 13:12:11 +08:00
|
|
|
const uint8_t *src = static_cast<const uint8_t *>(s);
|
2010-10-27 11:32:59 +08:00
|
|
|
bool binary_is_set = m_flags.Test(eBinary);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_flags.Clear(eBinary);
|
|
|
|
if (src_byte_order == dst_byte_order) {
|
2010-07-10 04:39:50 +08:00
|
|
|
for (size_t i = 0; i < src_len; ++i)
|
2018-09-12 18:20:41 +08:00
|
|
|
_PutHex8(src[i], false);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2022-02-16 12:35:52 +08:00
|
|
|
for (size_t i = src_len; i > 0; --i)
|
|
|
|
_PutHex8(src[i - 1], false);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
if (binary_is_set)
|
|
|
|
m_flags.Set(eBinary);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-12 22:28:55 +08:00
|
|
|
size_t Stream::PutStringAsRawHex8(llvm::StringRef s) {
|
2018-09-12 18:20:41 +08:00
|
|
|
ByteDelta delta(*this);
|
2010-10-27 11:32:59 +08:00
|
|
|
bool binary_is_set = m_flags.Test(eBinary);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_flags.Clear(eBinary);
|
2019-02-12 22:28:55 +08:00
|
|
|
for (char c : s)
|
|
|
|
_PutHex8(c, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (binary_is_set)
|
|
|
|
m_flags.Set(eBinary);
|
2018-09-12 18:20:41 +08:00
|
|
|
return *delta;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|