Zane Shelley | 8f60a62 | 2021-02-01 14:41:30 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | /** |
| 4 | * @brief Specially utilities that are specific to the analyzer (typically |
| 5 | * stuff that involves libhei). |
| 6 | */ |
| 7 | |
| 8 | #include <hei_main.hpp> |
| 9 | #include <util/bin_stream.hpp> |
| 10 | |
| 11 | namespace util |
| 12 | { |
| 13 | |
| 14 | /** @brief Extracts big-endian data to host RegisterId_t. */ |
| 15 | template <> |
| 16 | inline BinFileReader& BinFileReader::operator>>(libhei::RegisterId_t& r) |
| 17 | { |
| 18 | // A register ID is only 3 bytes, but there isn't a 3-byte integer type. |
| 19 | // So extract 3 bytes to a uint32_t and drop the unused byte. |
| 20 | uint32_t tmp = 0; |
| 21 | read(&tmp, 3); |
| 22 | r = static_cast<libhei::RegisterId_t>(be32toh(tmp) >> 8); |
| 23 | return *this; |
| 24 | } |
| 25 | |
| 26 | /** @brief Inserts host RegisterId_t to big-endian data. */ |
| 27 | template <> |
| 28 | inline BinFileWriter& BinFileWriter::operator<<(libhei::RegisterId_t r) |
| 29 | { |
| 30 | // A register ID is only 3 bytes, but there isn't a 3-byte integer type. |
| 31 | // So extract 3 bytes to a uint32_t and drop the unused byte. |
| 32 | uint32_t tmp = htobe32(static_cast<uint32_t>(r) << 8); |
| 33 | write(&tmp, 3); |
| 34 | return *this; |
| 35 | } |
| 36 | |
| 37 | } // namespace util |