| 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/MC/TargetRegistry.h" |
| 13 |
#include "llvm/Support/Host.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::getNormalizedDefaultTargetTriple() { |
| 30 |
Triple T(Triple::normalize(sys::getDefaultTargetTriple())); |
| 31 |
|
| 32 |
return T; |
| 33 |
} |
| 34 |
|
| 35 |
Triple llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize) { |
| 36 |
Triple T = getNormalizedDefaultTargetTriple(); |
| 37 |
|
| 38 |
assert((AddrSize == 4 || AddrSize == 8) && |
| 39 |
"Only 32-bit/64-bit address size variants are supported"); |
| 40 |
|
| 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(); |
| 47 |
return T; |
| 48 |
} |
| 49 |
|
| 50 |
bool llvm::dwarf::utils::isConfigurationSupported(Triple &T) { |
| 51 |
initLLVMIfNeeded(); |
| 52 |
std::string Err; |
| 53 |
const Target *TheTarget = TargetRegistry::lookupTarget(T.getTriple(), Err); |
| 54 |
return TheTarget && TheTarget->hasMCAsmBackend(); |
| 55 |
} |