9#include "llvm/ADT/STLExtras.h"
15static inline bool bitof(
const std::byte *B,
Bits BitIndex) {
22 for (
unsigned It = 0; It != BitWidth.
getQuantity(); ++It) {
29 DstBit = BitOffset +
Bits(It);
31 DstBit =
size() - BitOffset - BitWidth +
Bits(It);
38std::unique_ptr<std::byte[]>
40 Endian TargetEndianness)
const {
43 auto Out = std::make_unique<std::byte[]>(FullBitWidth.
roundToBytes());
45 for (
unsigned It = 0; It != BitWidth.
getQuantity(); ++It) {
48 BitIndex = BitOffset +
Bits(It);
50 BitIndex =
size() - BitWidth - BitOffset +
Bits(It);
52 bool BitValue =
bitof(
Data.get(), BitIndex);
85 if (End == (Offset -
Bits(1))) {
104 assert(Prev.End.N < Cur.Start.N);
115 bool FoundStart =
false;
118 if (BR.contains(
Range.End)) {
126 if (BR.contains(
Range.Start)) {
134 return Sum >=
Range.size();
139 static std::string hex(
T t) {
140 std::stringstream stream;
141 stream << std::hex << (
int)t;
142 return std::string(stream.str());
146 void BitcastBuffer::dump(
bool AsHex =
true)
const {
147 llvm::errs() <<
"LSB\n ";
148 unsigned LineLength = 0;
150 std::byte B =
Data[I];
152 std::stringstream stream;
153 stream << std::hex << (
int)B;
154 llvm::errs() << stream.str();
155 LineLength += stream.str().size() + 1;
157 llvm::errs() << std::bitset<8>((
int)B).to_string();
163 llvm::errs() <<
'\n';
165 for (
unsigned I = 0; I != LineLength; ++I)
167 llvm::errs() <<
"MSB\n";
static bool bitof(const std::byte *B, Bits BitIndex)
Returns the value of the bit in the given sequence of bytes.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
A bit range. Both Start and End are inclusive.
std::unique_ptr< std::byte[]> copyBits(Bits BitOffset, Bits BitWidth, Bits FullBitWidth, Endian TargetEndianness) const
Copy BitWidth bits at offset BitOffset from the buffer.
void markInitialized(Bits Start, Bits Length)
Marks the bits in the given range as initialized.
llvm::SmallVector< BitRange > InitializedBits
bool allInitialized() const
Returns true if all bits in the buffer have been initialized.
bool rangeInitialized(Bits Offset, Bits Length) const
Bits size() const
Returns the buffer size in bits.
void pushData(const std::byte *In, Bits BitOffset, Bits BitWidth, Endian TargetEndianness)
Push BitWidth bits at BitOffset from In into the buffer.
std::unique_ptr< std::byte[]> Data
size_t roundToBytes() const
size_t getOffsetInByte() const
size_t getQuantity() const