James Henderson | 6670262 | 2018-03-08 10:53:34 +0000 | [diff] [blame] | 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" |
Nico Weber | 432a388 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 12 | #include "llvm/Config/llvm-config.h" |
James Henderson | 6670262 | 2018-03-08 10:53:34 +0000 | [diff] [blame] | 13 | #include "llvm/Support/TargetRegistry.h" |
| 14 | #include "llvm/Support/TargetSelect.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | static void initLLVMIfNeeded() { |
| 19 | static bool gInitialized = false; |
| 20 | if (!gInitialized) { |
| 21 | gInitialized = true; |
| 22 | InitializeAllTargets(); |
| 23 | InitializeAllTargetMCs(); |
| 24 | InitializeAllAsmPrinters(); |
| 25 | InitializeAllAsmParsers(); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | Triple 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 | |
| 39 | bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) { |
| 40 | initLLVMIfNeeded(); |
| 41 | std::string Err; |
| 42 | return TargetRegistry::lookupTarget(T.getTriple(), Err); |
| 43 | } |