brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 5921e7c Raw
93 lines · cpp
1//===- tools/dsymutil/RelocationMap.cpp - Relocation map representation---===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "RelocationMap.h"10 11namespace llvm {12 13namespace dsymutil {14 15void RelocationMap::print(raw_ostream &OS) const {16  yaml::Output yout(OS, /* Ctxt = */ nullptr, /* WrapColumn = */ 0);17  yout << const_cast<RelocationMap &>(*this);18}19 20#ifndef NDEBUG21void RelocationMap::dump() const { print(errs()); }22#endif23 24void RelocationMap::addRelocationMapEntry(const ValidReloc &Relocation) {25  Relocations.push_back(Relocation);26}27 28namespace {29 30struct YAMLContext {31  StringRef PrependPath;32  Triple BinaryTriple;33};34 35} // end anonymous namespace36 37ErrorOr<std::unique_ptr<RelocationMap>>38RelocationMap::parseYAMLRelocationMap(StringRef InputFile,39                                      StringRef PrependPath) {40  auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile);41  if (auto Err = ErrOrFile.getError())42    return Err;43 44  YAMLContext Ctxt;45 46  Ctxt.PrependPath = PrependPath;47 48  std::unique_ptr<RelocationMap> Result;49  yaml::Input yin((*ErrOrFile)->getBuffer(), &Ctxt);50  yin >> Result;51 52  if (auto EC = yin.error())53    return EC;54  return std::move(Result);55}56 57} // end namespace dsymutil58 59namespace yaml {60 61void MappingTraits<dsymutil::ValidReloc>::mapping(IO &io,62                                                  dsymutil::ValidReloc &VR) {63  io.mapRequired("offset", VR.Offset);64  io.mapRequired("size", VR.Size);65  io.mapRequired("addend", VR.Addend);66  io.mapRequired("symName", VR.SymbolName);67  io.mapOptional("symObjAddr", VR.SymbolMapping.ObjectAddress);68  io.mapRequired("symBinAddr", VR.SymbolMapping.BinaryAddress);69  io.mapRequired("symSize", VR.SymbolMapping.Size);70}71 72void MappingTraits<dsymutil::RelocationMap>::mapping(73    IO &io, dsymutil::RelocationMap &RM) {74  io.mapRequired("triple", RM.BinaryTriple);75  io.mapRequired("binary-path", RM.BinaryPath);76  if (void *Ctxt = io.getContext())77    reinterpret_cast<YAMLContext *>(Ctxt)->BinaryTriple = RM.BinaryTriple;78  io.mapRequired("relocations", RM.Relocations);79}80 81void MappingTraits<std::unique_ptr<dsymutil::RelocationMap>>::mapping(82    IO &io, std::unique_ptr<dsymutil::RelocationMap> &RM) {83  if (!RM)84    RM.reset(new RelocationMap());85  io.mapRequired("triple", RM->BinaryTriple);86  io.mapRequired("binary-path", RM->BinaryPath);87  if (void *Ctxt = io.getContext())88    reinterpret_cast<YAMLContext *>(Ctxt)->BinaryTriple = RM->BinaryTriple;89  io.mapRequired("relocations", RM->Relocations);90}91} // end namespace yaml92} // end namespace llvm93