brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · d7bbecb Raw
56 lines · cpp
1//===--- unittests/DebugInfo/DWARF/DwarfUtils.cpp ---------------*- C++ -*-===//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 "DwarfUtils.h"10#include "llvm/Config/llvm-config.h"11#include "llvm/MC/TargetRegistry.h"12#include "llvm/Support/TargetSelect.h"13#include "llvm/TargetParser/Host.h"14#include "llvm/TargetParser/Triple.h"15 16using namespace llvm;17 18static void initLLVMIfNeeded() {19  static bool gInitialized = false;20  if (!gInitialized) {21    gInitialized = true;22    InitializeAllTargets();23    InitializeAllTargetMCs();24    InitializeAllAsmPrinters();25    InitializeAllAsmParsers();26  }27}28 29Triple llvm::dwarf::utils::getNormalizedDefaultTargetTriple() {30  Triple T(Triple::normalize(sys::getDefaultTargetTriple()));31 32  return T;33}34 35Triple llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize) {36  Triple T = getNormalizedDefaultTargetTriple();37 38  assert((AddrSize == 4 || AddrSize == 8) &&39         "Only 32-bit/64-bit address size variants are supported");40 41  // If a 32-bit/64-bit address size was specified, try to convert the triple42  // if it is for the wrong variant.43  if (AddrSize == 8 && T.isArch32Bit())44    return T.get64BitArchVariant();45  if (AddrSize == 4 && T.isArch64Bit())46    return T.get32BitArchVariant();47  return T;48}49 50bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) {51  initLLVMIfNeeded();52  std::string Err;53  const Target *TheTarget = TargetRegistry::lookupTarget(T, Err);54  return TheTarget && TheTarget->hasMCAsmBackend();55}56