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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "DwarfUtils.h" 10 #include "llvm/ADT/Triple.h" 11 #include "llvm/Config/llvm-config.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