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/Config/llvm-config.h" 13 #include "llvm/Support/TargetRegistry.h" 14 #include "llvm/Support/TargetSelect.h" 15 16 using namespace llvm; 17 initLLVMIfNeeded()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 getHostTripleForAddrSize(uint8_t AddrSize)29Triple llvm::dwarf::utils::getHostTripleForAddrSize(uint8_t AddrSize) { 30 Triple T(Triple::normalize(LLVM_HOST_TRIPLE)); 31 32 if (AddrSize == 8 && T.isArch32Bit()) 33 return T.get64BitArchVariant(); 34 if (AddrSize == 4 && T.isArch64Bit()) 35 return T.get32BitArchVariant(); 36 return T; 37 } 38 isConfigurationSupported(Triple & T)39bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) { 40 initLLVMIfNeeded(); 41 std::string Err; 42 return TargetRegistry::lookupTarget(T.getTriple(), Err); 43 } 44