Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/GSYM/FileWriter.cpp
35266 views
//===- FileWriter.cpp -------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/GSYM/FileWriter.h"9#include "llvm/Support/LEB128.h"10#include "llvm/Support/raw_ostream.h"11#include <cassert>1213using namespace llvm;14using namespace gsym;1516FileWriter::~FileWriter() { OS.flush(); }1718void FileWriter::writeSLEB(int64_t S) {19uint8_t Bytes[32];20auto Length = encodeSLEB128(S, Bytes);21assert(Length < sizeof(Bytes));22OS.write(reinterpret_cast<const char *>(Bytes), Length);23}2425void FileWriter::writeULEB(uint64_t U) {26uint8_t Bytes[32];27auto Length = encodeULEB128(U, Bytes);28assert(Length < sizeof(Bytes));29OS.write(reinterpret_cast<const char *>(Bytes), Length);30}3132void FileWriter::writeU8(uint8_t U) {33OS.write(reinterpret_cast<const char *>(&U), sizeof(U));34}3536void FileWriter::writeU16(uint16_t U) {37const uint16_t Swapped = support::endian::byte_swap(U, ByteOrder);38OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));39}4041void FileWriter::writeU32(uint32_t U) {42const uint32_t Swapped = support::endian::byte_swap(U, ByteOrder);43OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));44}4546void FileWriter::writeU64(uint64_t U) {47const uint64_t Swapped = support::endian::byte_swap(U, ByteOrder);48OS.write(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped));49}5051void FileWriter::fixup32(uint32_t U, uint64_t Offset) {52const uint32_t Swapped = support::endian::byte_swap(U, ByteOrder);53OS.pwrite(reinterpret_cast<const char *>(&Swapped), sizeof(Swapped),54Offset);55}5657void FileWriter::writeData(llvm::ArrayRef<uint8_t> Data) {58OS.write(reinterpret_cast<const char *>(Data.data()), Data.size());59}6061void FileWriter::writeNullTerminated(llvm::StringRef Str) {62OS << Str << '\0';63}6465uint64_t FileWriter::tell() {66return OS.tell();67}6869void FileWriter::alignTo(size_t Align) {70off_t Offset = OS.tell();71off_t AlignedOffset = (Offset + Align - 1) / Align * Align;72if (AlignedOffset == Offset)73return;74off_t PadCount = AlignedOffset - Offset;75OS.write_zeros(PadCount);76}777879