1 //===--- unittests/DebugInfo/DWARF/DwarfUtils.cpp ---------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
18 static void initLLVMIfNeeded() {
19 static bool gInitialized
= false;
22 InitializeAllTargets();
23 InitializeAllTargetMCs();
24 InitializeAllAsmPrinters();
25 InitializeAllAsmParsers();
29 Triple
llvm::dwarf::utils::getNormalizedDefaultTargetTriple() {
30 Triple
T(Triple::normalize(sys::getDefaultTargetTriple()));
35 Triple
llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize
) {
36 Triple T
= getNormalizedDefaultTargetTriple();
38 assert((AddrSize
== 4 || AddrSize
== 8) &&
39 "Only 32-bit/64-bit address size variants are supported");
41 // If a 32-bit/64-bit address size was specified, try to convert the triple
42 // 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();
50 bool llvm::dwarf::utils::isConfigurationSupported(Triple
&T
) {
53 const Target
*TheTarget
= TargetRegistry::lookupTarget(T
.getTriple(), Err
);
54 return TheTarget
&& TheTarget
->hasMCAsmBackend();