LLVM 23.0.0git
ContiguousBlobAccumulator.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements the ContiguousBlobAccumulator methods declared in
11/// ContiguousBlobAccumulator.h.
12///
13//===----------------------------------------------------------------------===//
14
17#include "llvm/Support/Errc.h"
18#include "llvm/Support/LEB128.h"
19
20using namespace llvm;
21using namespace llvm::yaml;
22
23bool ContiguousBlobAccumulator::checkLimit(uint64_t Size) {
24 if (!ReachedLimitErr && getOffset() + Size <= MaxSize)
25 return true;
26 if (!ReachedLimitErr)
28 "reached the output size limit");
29 return false;
30}
31
33 uint64_t CurrentOffset = getOffset();
34 if (ReachedLimitErr)
35 return CurrentOffset;
36
37 uint64_t AlignedOffset = alignTo(CurrentOffset, Align == 0 ? 1 : Align);
38 uint64_t PaddingSize = AlignedOffset - CurrentOffset;
39 if (!checkLimit(PaddingSize))
40 return CurrentOffset;
41
42 writeZeros(PaddingSize);
43 return AlignedOffset;
44}
45
47 uint64_t N) {
48 if (!checkLimit(Bin.binary_size()))
49 return;
50 Bin.writeAsBinary(OS, N);
51}
52
54 if (!checkLimit(sizeof(uint64_t)))
55 return 0;
56 return encodeULEB128(Val, OS);
57}
58
60 if (!checkLimit(10))
61 return 0;
62 return encodeSLEB128(Val, OS);
63}
64
66 size_t Size) {
67 assert(Pos >= InitialOffset && Pos + Size <= getOffset());
68 memcpy(&Buf[Pos - InitialOffset], Data, Size);
69}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines ContiguousBlobAccumulator, the size-limited output buffer shared by the yaml2obj em...
Specialized YAMLIO scalar type for representing a binary blob.
Definition YAML.h:64
LLVM_ABI uint64_t padToAlignment(unsigned Align)
LLVM_ABI void writeAsBinary(const BinaryRef &Bin, uint64_t N=UINT64_MAX)
LLVM_ABI void updateDataAt(uint64_t Pos, void *Data, size_t Size)
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
@ invalid_argument
Definition Errc.h:56
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition LEB128.h:24
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition LEB128.h:79
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39