xref: /llvm-project/llvm/unittests/DebugInfo/DWARF/DwarfUtils.cpp (revision 667026297da3f188ca78f4c6b0d767000b4c5d90)
1 //===--- unittests/DebugInfo/DWARF/DwarfUtils.cpp ---------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "DwarfUtils.h"
11 #include "llvm/ADT/Triple.h"
12 #include "llvm/Support/TargetRegistry.h"
13 #include "llvm/Support/TargetSelect.h"
14 
15 using namespace llvm;
16 
17 static void initLLVMIfNeeded() {
18   static bool gInitialized = false;
19   if (!gInitialized) {
20     gInitialized = true;
21     InitializeAllTargets();
22     InitializeAllTargetMCs();
23     InitializeAllAsmPrinters();
24     InitializeAllAsmParsers();
25   }
26 }
27 
28 Triple llvm::dwarf::utils::getHostTripleForAddrSize(uint8_t AddrSize) {
29   Triple T(Triple::normalize(LLVM_HOST_TRIPLE));
30 
31   if (AddrSize == 8 && T.isArch32Bit())
32     return T.get64BitArchVariant();
33   if (AddrSize == 4 && T.isArch64Bit())
34     return T.get32BitArchVariant();
35   return T;
36 }
37 
38 bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) {
39   initLLVMIfNeeded();
40   std::string Err;
41   return TargetRegistry::lookupTarget(T.getTriple(), Err);
42 }
43