diff options
author | Adrian Prantl <aprantl@apple.com> | 2024-04-26 12:25:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-26 12:25:39 -0700 |
commit | 300340f656d762afa8bde5fc398757d2951560bf (patch) | |
tree | e1aa30b686d0ff61f577019404449641f480958c | |
parent | 5dd46d93fb9d7e7f8c9774433d60fd16dc659eb6 (diff) | |
download | llvm-300340f656d762afa8bde5fc398757d2951560bf.zip llvm-300340f656d762afa8bde5fc398757d2951560bf.tar.gz llvm-300340f656d762afa8bde5fc398757d2951560bf.tar.bz2 |
Implement the DWARF 6 language and version attributes. (#89980)
This patch adds DWARF constants for DW_AT_language_name and
DW_AT_language_version to Dwarf.def and Dwarf.h.
While the DWARF 6 spec is not finalized, the constants are published on
the DWARF website and considered stable, with idea being that the list
published on dwarfstd.org is the authoritative source that is being
continuously updated between DWARF revisions, as new languages are being
developed.
https://dwarfstd.org/languages-v6.html
My main motivation for adding this is to use in
https://github.com/llvm/llvm-project/pull/89981
-rw-r--r-- | llvm/include/llvm-c/DebugInfo.h | 13 | ||||
-rw-r--r-- | llvm/include/llvm/BinaryFormat/Dwarf.def | 101 | ||||
-rw-r--r-- | llvm/include/llvm/BinaryFormat/Dwarf.h | 314 | ||||
-rw-r--r-- | llvm/lib/BinaryFormat/Dwarf.cpp | 10 | ||||
-rw-r--r-- | llvm/unittests/BinaryFormat/DwarfTest.cpp | 15 |
5 files changed, 440 insertions, 13 deletions
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h index dab1d69..2c3c75e 100644 --- a/llvm/include/llvm-c/DebugInfo.h +++ b/llvm/include/llvm-c/DebugInfo.h @@ -125,7 +125,20 @@ typedef enum { LLVMDWARFSourceLanguageFortran18, LLVMDWARFSourceLanguageAda2005, LLVMDWARFSourceLanguageAda2012, + LLVMDWARFSourceLanguageHIP, + LLVMDWARFSourceLanguageAssembly, + LLVMDWARFSourceLanguageC_sharp, LLVMDWARFSourceLanguageMojo, + LLVMDWARFSourceLanguageGLSL, + LLVMDWARFSourceLanguageGLSL_ES, + LLVMDWARFSourceLanguageHLSL, + LLVMDWARFSourceLanguageOpenCL_CPP, + LLVMDWARFSourceLanguageCPP_for_OpenCL, + LLVMDWARFSourceLanguageSYCL, + LLVMDWARFSourceLanguageRuby, + LLVMDWARFSourceLanguageMove, + LLVMDWARFSourceLanguageHylo, + // Vendor extensions: LLVMDWARFSourceLanguageMips_Assembler, LLVMDWARFSourceLanguageGOOGLE_RenderScript, diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.def b/llvm/include/llvm/BinaryFormat/Dwarf.def index 460a926..adcf24e 100644 --- a/llvm/include/llvm/BinaryFormat/Dwarf.def +++ b/llvm/include/llvm/BinaryFormat/Dwarf.def @@ -11,19 +11,20 @@ //===----------------------------------------------------------------------===// // TODO: Add other DW-based macros. -#if !( \ - defined HANDLE_DW_TAG || defined HANDLE_DW_AT || defined HANDLE_DW_FORM || \ - defined HANDLE_DW_OP || defined HANDLE_DW_OP_LLVM_USEROP || \ - defined HANDLE_DW_LANG || defined HANDLE_DW_ATE || \ - defined HANDLE_DW_VIRTUALITY || defined HANDLE_DW_DEFAULTED || \ - defined HANDLE_DW_CC || defined HANDLE_DW_LNS || defined HANDLE_DW_LNE || \ - defined HANDLE_DW_LNCT || defined HANDLE_DW_MACRO || \ - defined HANDLE_DW_MACRO_GNU || defined HANDLE_MACRO_FLAG || \ - defined HANDLE_DW_RLE || defined HANDLE_DW_LLE || \ - (defined HANDLE_DW_CFA && defined HANDLE_DW_CFA_PRED) || \ - defined HANDLE_DW_APPLE_PROPERTY || defined HANDLE_DW_UT || \ - defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX || \ - defined HANDLE_DW_END || defined HANDLE_DW_SECT) +#if !(defined HANDLE_DW_TAG || defined HANDLE_DW_AT || \ + defined HANDLE_DW_FORM || defined HANDLE_DW_OP || \ + defined HANDLE_DW_OP_LLVM_USEROP || defined HANDLE_DW_LANG || \ + defined HANDLE_DW_LNAME || defined HANDLE_DW_ATE || \ + defined HANDLE_DW_VIRTUALITY || defined HANDLE_DW_DEFAULTED || \ + defined HANDLE_DW_CC || defined HANDLE_DW_LNS || \ + defined HANDLE_DW_LNE || defined HANDLE_DW_LNCT || \ + defined HANDLE_DW_MACRO || defined HANDLE_DW_MACRO_GNU || \ + defined HANDLE_MACRO_FLAG || defined HANDLE_DW_RLE || \ + defined HANDLE_DW_LLE || \ + (defined HANDLE_DW_CFA && defined HANDLE_DW_CFA_PRED) || \ + defined HANDLE_DW_APPLE_PROPERTY || defined HANDLE_DW_UT || \ + defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX || \ + defined HANDLE_DW_END || defined HANDLE_DW_SECT) #error "Missing macro definition of HANDLE_DW*" #endif @@ -61,6 +62,10 @@ #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) #endif +#ifndef HANDLE_DW_LNAME +#define HANDLE_DW_LNAME(ID, NAME, DESC, LOWER_BOUND) +#endif + #ifndef HANDLE_DW_ATE #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) #endif @@ -950,12 +955,81 @@ HANDLE_DW_LANG(0x002c, C17, 0, 0, DWARF) HANDLE_DW_LANG(0x002d, Fortran18, 0, 0, DWARF) HANDLE_DW_LANG(0x002e, Ada2005, 0, 0, DWARF) HANDLE_DW_LANG(0x002f, Ada2012, 0, 0, DWARF) +HANDLE_DW_LANG(0x0030, HIP, 0, 0, DWARF) +HANDLE_DW_LANG(0x0031, Assembly, 0, 0, DWARF) +HANDLE_DW_LANG(0x0032, C_sharp, 0, 0, DWARF) HANDLE_DW_LANG(0x0033, Mojo, 0, 0, DWARF) +HANDLE_DW_LANG(0x0034, GLSL, 0, 0, DWARF) +HANDLE_DW_LANG(0x0035, GLSL_ES, 0, 0, DWARF) +HANDLE_DW_LANG(0x0036, HLSL, 0, 0, DWARF) +HANDLE_DW_LANG(0x0037, OpenCL_CPP, 0, 0, DWARF) +HANDLE_DW_LANG(0x0038, CPP_for_OpenCL, 0, 0, DWARF) +HANDLE_DW_LANG(0x0039, SYCL, 0, 0, DWARF) +HANDLE_DW_LANG(0x0040, Ruby, 0, 0, DWARF) +HANDLE_DW_LANG(0x0041, Move, 0, 0, DWARF) +HANDLE_DW_LANG(0x0042, Hylo, 0, 0, DWARF) + // Vendor extensions: HANDLE_DW_LANG(0x8001, Mips_Assembler, std::nullopt, 0, MIPS) HANDLE_DW_LANG(0x8e57, GOOGLE_RenderScript, 0, 0, GOOGLE) HANDLE_DW_LANG(0xb000, BORLAND_Delphi, 0, 0, BORLAND) +// Tentative DWARF 6 language codes. This list is subject to change. +HANDLE_DW_LNAME(0x0001, Ada, "ISO Ada", 1) // YYYY +HANDLE_DW_LNAME(0x0002, BLISS, "BLISS", 0) +// YYYYMM +// K&R 000000 +// C89 198912 +// C99 199901 +// C11 201112 +// C17 201710 +// C23 202311 +HANDLE_DW_LNAME(0x0003, C, "C (K&R and ISO)", 0) +// YYYYMM +// C++98 199711 +// C++03 200310 +// C++11 201103 +// C++14 201402 +// C++17 201703 +// C++20 202002 +HANDLE_DW_LNAME(0x0004, C_plus_plus, "ISO C++", 0) +HANDLE_DW_LNAME(0x0005, Cobol, "ISO Cobol", 1) // YYYY +HANDLE_DW_LNAME(0x0006, Crystal, "Crystal", 0) +HANDLE_DW_LNAME(0x0007, D, "D", 0) +HANDLE_DW_LNAME(0x0008, Dylan, "Dylan", 0) +HANDLE_DW_LNAME(0x0009, Fortran, "ISO Fortran", 1) // YYYY +HANDLE_DW_LNAME(0x000a, Go, "Go", 0) +HANDLE_DW_LNAME(0x000b, Haskell, "Haskell", 0) +HANDLE_DW_LNAME(0x000c, Java, "Java", 0) +HANDLE_DW_LNAME(0x000d, Julia, "Julia", 1) +HANDLE_DW_LNAME(0x000e, Kotlin, "Kotlin", 0) +HANDLE_DW_LNAME(0x000f, Modula2, "Modula 2", 1) +HANDLE_DW_LNAME(0x0010, Modula3, "Modula 3", 1) +HANDLE_DW_LNAME(0x0011, ObjC, "Objective C", 0) // YYYYMM +HANDLE_DW_LNAME(0x0012, ObjC_plus_plus, "Objective C++", 0) // YYYYMM +HANDLE_DW_LNAME(0x0013, OCaml, "OCaml", 0) +HANDLE_DW_LNAME(0x0014, OpenCL_C, "OpenCL C", 0) +HANDLE_DW_LNAME(0x0015, Pascal, "ISO Pascal", 1) // YYYY +HANDLE_DW_LNAME(0x0016, PLI, "ANSI PL/I", 1) +HANDLE_DW_LNAME(0x0017, Python, "Python", 0) +HANDLE_DW_LNAME(0x0018, RenderScript, "RenderScript Kernel Language", 0) +HANDLE_DW_LNAME(0x0019, Rust, "Rust", 0) +HANDLE_DW_LNAME(0x001a, Swift, "Swift", 0) // VVMM +HANDLE_DW_LNAME(0x001b, UPC, "Unified Parallel C (UPC)", 0) +HANDLE_DW_LNAME(0x001c, Zig, "Zig", 0) +HANDLE_DW_LNAME(0x001d, Assembly, "Assembly", 0) +// Conflict: HANDLE_DW_LNAME(0x001d, HIP, "HIP", 0) +HANDLE_DW_LNAME(0x001e, C_sharp, "C#", 0) +HANDLE_DW_LNAME(0x001f, Mojo, "Mojo", 0) +HANDLE_DW_LNAME(0x0020, GLSL, "OpenGL Shading Language", 0) // VVMMPP +HANDLE_DW_LNAME(0x0021, GLSL_ES, "OpenGL ES Shading Language", 0) // VVMMPP +HANDLE_DW_LNAME(0x0022, HLSL, "High Level Shading Language", 0) // YYYY +HANDLE_DW_LNAME(0x0023, OpenCL_CPP, "OpenCL C++", 0) // VVMM +HANDLE_DW_LNAME(0x0024, CPP_for_OpenCL, "C++ for OpenCL", 0) // VVMM +HANDLE_DW_LNAME(0x0025, SYCL, "SYCL", 0) // YYYYRR +HANDLE_DW_LNAME(0x0026, Ruby, "Ruby", 0) // VVMMPP +HANDLE_DW_LNAME(0x0027, Move, "Move", 0) // YYYYMM +HANDLE_DW_LNAME(0x0028, Hylo, "Hylo", 0) // DWARF attribute type encodings. HANDLE_DW_ATE(0x01, address, 2, DWARF) @@ -1267,6 +1341,7 @@ HANDLE_DW_SECT(8, RNGLISTS) #undef HANDLE_DW_OP #undef HANDLE_DW_OP_LLVM_USEROP #undef HANDLE_DW_LANG +#undef HANDLE_DW_LNAME #undef HANDLE_DW_ATE #undef HANDLE_DW_VIRTUALITY #undef HANDLE_DW_DEFAULTED diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h index 298700c..74c4d6f 100644 --- a/llvm/include/llvm/BinaryFormat/Dwarf.h +++ b/llvm/include/llvm/BinaryFormat/Dwarf.h @@ -209,6 +209,284 @@ enum SourceLanguage { DW_LANG_hi_user = 0xffff }; +enum SourceLanguageName : uint16_t { +#define HANDLE_DW_LNAME(ID, NAME, DESC, LOWER_BOUND) DW_LNAME_##NAME = ID, +#include "llvm/BinaryFormat/Dwarf.def" +}; + +/// Convert a DWARF 6 pair of language name and version to a DWARF 5 DW_LANG. +/// If the version number doesn't exactly match a known version it is +/// rounded up to the next-highest known version number. +inline std::optional<SourceLanguage> toDW_LANG(SourceLanguageName name, + uint32_t version) { + switch (name) { + case DW_LNAME_Ada: // YYYY + if (version <= 1983) + return DW_LANG_Ada83; + if (version <= 1995) + return DW_LANG_Ada95; + if (version <= 2005) + return DW_LANG_Ada2005; + if (version <= 2012) + return DW_LANG_Ada2012; + return {}; + case DW_LNAME_BLISS: + return DW_LANG_BLISS; + case DW_LNAME_C: // YYYYMM, K&R 000000 + if (version == 0) + return DW_LANG_C; + if (version <= 198912) + return DW_LANG_C89; + if (version <= 199901) + return DW_LANG_C99; + if (version <= 201112) + return DW_LANG_C11; + if (version <= 201710) + return DW_LANG_C17; + return {}; + case DW_LNAME_C_plus_plus: // YYYYMM + if (version == 0) + return DW_LANG_C_plus_plus; + if (version <= 199711) + return DW_LANG_C_plus_plus; + if (version <= 200310) + return DW_LANG_C_plus_plus_03; + if (version <= 201103) + return DW_LANG_C_plus_plus_11; + if (version <= 201402) + return DW_LANG_C_plus_plus_14; + if (version <= 201703) + return DW_LANG_C_plus_plus_17; + if (version <= 202002) + return DW_LANG_C_plus_plus_20; + return {}; + case DW_LNAME_Cobol: // YYYY + if (version <= 1974) + return DW_LANG_Cobol74; + if (version <= 1985) + return DW_LANG_Cobol85; + return {}; + case DW_LNAME_Crystal: + return DW_LANG_Crystal; + case DW_LNAME_D: + return DW_LANG_D; + case DW_LNAME_Dylan: + return DW_LANG_Dylan; + case DW_LNAME_Fortran: // YYYY + if (version <= 1977) + return DW_LANG_Fortran77; + if (version <= 1990) + return DW_LANG_Fortran90; + if (version <= 1995) + return DW_LANG_Fortran95; + if (version <= 2003) + return DW_LANG_Fortran03; + if (version <= 2008) + return DW_LANG_Fortran08; + if (version <= 2018) + return DW_LANG_Fortran18; + return {}; + case DW_LNAME_Go: + return DW_LANG_Go; + case DW_LNAME_Haskell: + return DW_LANG_Haskell; + // case DW_LNAME_HIP: + // return DW_LANG_HIP; + case DW_LNAME_Java: + return DW_LANG_Java; + case DW_LNAME_Julia: + return DW_LANG_Julia; + case DW_LNAME_Kotlin: + return DW_LANG_Kotlin; + case DW_LNAME_Modula2: + return DW_LANG_Modula2; + case DW_LNAME_Modula3: + return DW_LANG_Modula3; + case DW_LNAME_ObjC: + return DW_LANG_ObjC; + case DW_LNAME_ObjC_plus_plus: + return DW_LANG_ObjC_plus_plus; + case DW_LNAME_OCaml: + return DW_LANG_OCaml; + case DW_LNAME_OpenCL_C: + return DW_LANG_OpenCL; + case DW_LNAME_Pascal: + return DW_LANG_Pascal83; + case DW_LNAME_PLI: + return DW_LANG_PLI; + case DW_LNAME_Python: + return DW_LANG_Python; + case DW_LNAME_RenderScript: + return DW_LANG_RenderScript; + case DW_LNAME_Rust: + return DW_LANG_Rust; + case DW_LNAME_Swift: + return DW_LANG_Swift; + case DW_LNAME_UPC: + return DW_LANG_UPC; + case DW_LNAME_Zig: + return DW_LANG_Zig; + case DW_LNAME_Assembly: + return DW_LANG_Assembly; + case DW_LNAME_C_sharp: + return DW_LANG_C_sharp; + case DW_LNAME_Mojo: + return DW_LANG_Mojo; + case DW_LNAME_GLSL: + return DW_LANG_GLSL; + case DW_LNAME_GLSL_ES: + return DW_LANG_GLSL_ES; + case DW_LNAME_HLSL: + return DW_LANG_HLSL; + case DW_LNAME_OpenCL_CPP: + return DW_LANG_OpenCL_CPP; + case DW_LNAME_CPP_for_OpenCL: + return {}; + case DW_LNAME_SYCL: + return DW_LANG_SYCL; + case DW_LNAME_Ruby: + return DW_LANG_Ruby; + case DW_LNAME_Move: + return DW_LANG_Move; + case DW_LNAME_Hylo: + return DW_LANG_Hylo; + } + return {}; +} + +/// Convert a DWARF 5 DW_LANG to a DWARF 6 pair of language name and version. +inline std::optional<std::pair<SourceLanguageName, uint32_t>> +toDW_LNAME(SourceLanguage language) { + switch (language) { + case DW_LANG_Ada83: + return {{DW_LNAME_Ada, 1983}}; + case DW_LANG_Ada95: + return {{DW_LNAME_Ada, 1995}}; + case DW_LANG_Ada2005: + return {{DW_LNAME_Ada, 2005}}; + case DW_LANG_Ada2012: + return {{DW_LNAME_Ada, 2012}}; + case DW_LANG_BLISS: + return {{DW_LNAME_BLISS, 0}}; + case DW_LANG_C: + return {{DW_LNAME_C, 0}}; + case DW_LANG_C89: + return {{DW_LNAME_C, 198912}}; + case DW_LANG_C99: + return {{DW_LNAME_C, 199901}}; + case DW_LANG_C11: + return {{DW_LNAME_C, 201112}}; + case DW_LANG_C17: + return {{DW_LNAME_C, 201712}}; + case DW_LANG_C_plus_plus: + return {{DW_LNAME_C_plus_plus, 0}}; + case DW_LANG_C_plus_plus_03: + return {{DW_LNAME_C_plus_plus, 200310}}; + case DW_LANG_C_plus_plus_11: + return {{DW_LNAME_C_plus_plus, 201103}}; + case DW_LANG_C_plus_plus_14: + return {{DW_LNAME_C_plus_plus, 201402}}; + case DW_LANG_C_plus_plus_17: + return {{DW_LNAME_C_plus_plus, 201703}}; + case DW_LANG_C_plus_plus_20: + return {{DW_LNAME_C_plus_plus, 202002}}; + case DW_LANG_Cobol74: + return {{DW_LNAME_Cobol, 1974}}; + case DW_LANG_Cobol85: + return {{DW_LNAME_Cobol, 1985}}; + case DW_LANG_Crystal: + return {{DW_LNAME_Crystal, 0}}; + case DW_LANG_D: + return {{DW_LNAME_D, 0}}; + case DW_LANG_Dylan: + return {{DW_LNAME_Dylan, 0}}; + case DW_LANG_Fortran77: + return {{DW_LNAME_Fortran, 1977}}; + case DW_LANG_Fortran90: + return {{DW_LNAME_Fortran, 1990}}; + case DW_LANG_Fortran95: + return {{DW_LNAME_Fortran, 1995}}; + case DW_LANG_Fortran03: + return {{DW_LNAME_Fortran, 2003}}; + case DW_LANG_Fortran08: + return {{DW_LNAME_Fortran, 2008}}; + case DW_LANG_Fortran18: + return {{DW_LNAME_Fortran, 2018}}; + case DW_LANG_Go: + return {{DW_LNAME_Go, 0}}; + case DW_LANG_Haskell: + return {{DW_LNAME_Haskell, 0}}; + case DW_LANG_HIP: + return {}; // return {{DW_LNAME_HIP, 0}}; + case DW_LANG_Java: + return {{DW_LNAME_Java, 0}}; + case DW_LANG_Julia: + return {{DW_LNAME_Julia, 0}}; + case DW_LANG_Kotlin: + return {{DW_LNAME_Kotlin, 0}}; + case DW_LANG_Modula2: + return {{DW_LNAME_Modula2, 0}}; + case DW_LANG_Modula3: + return {{DW_LNAME_Modula3, 0}}; + case DW_LANG_ObjC: + return {{DW_LNAME_ObjC, 0}}; + case DW_LANG_ObjC_plus_plus: + return {{DW_LNAME_ObjC_plus_plus, 0}}; + case DW_LANG_OCaml: + return {{DW_LNAME_OCaml, 0}}; + case DW_LANG_OpenCL: + return {{DW_LNAME_OpenCL_C, 0}}; + case DW_LANG_Pascal83: + return {{DW_LNAME_Pascal, 1983}}; + case DW_LANG_PLI: + return {{DW_LNAME_PLI, 0}}; + case DW_LANG_Python: + return {{DW_LNAME_Python, 0}}; + case DW_LANG_RenderScript: + case DW_LANG_GOOGLE_RenderScript: + return {{DW_LNAME_RenderScript, 0}}; + case DW_LANG_Rust: + return {{DW_LNAME_Rust, 0}}; + case DW_LANG_Swift: + return {{DW_LNAME_Swift, 0}}; + case DW_LANG_UPC: + return {{DW_LNAME_UPC, 0}}; + case DW_LANG_Zig: + return {{DW_LNAME_Zig, 0}}; + case DW_LANG_Assembly: + case DW_LANG_Mips_Assembler: + return {{DW_LNAME_Assembly, 0}}; + case DW_LANG_C_sharp: + return {{DW_LNAME_C_sharp, 0}}; + case DW_LANG_Mojo: + return {{DW_LNAME_Mojo, 0}}; + case DW_LANG_GLSL: + return {{DW_LNAME_GLSL, 0}}; + case DW_LANG_GLSL_ES: + return {{DW_LNAME_GLSL_ES, 0}}; + case DW_LANG_HLSL: + return {{DW_LNAME_HLSL, 0}}; + case DW_LANG_OpenCL_CPP: + return {{DW_LNAME_OpenCL_CPP, 0}}; + case DW_LANG_SYCL: + return {{DW_LNAME_SYCL, 0}}; + case DW_LANG_Ruby: + return {{DW_LNAME_Ruby, 0}}; + case DW_LANG_Move: + return {{DW_LNAME_Move, 0}}; + case DW_LANG_Hylo: + return {{DW_LNAME_Hylo, 0}}; + case DW_LANG_BORLAND_Delphi: + case DW_LANG_CPP_for_OpenCL: + case DW_LANG_lo_user: + case DW_LANG_hi_user: + return {}; + } + return {}; +} + +llvm::StringRef LanguageDescription(SourceLanguageName name); + inline bool isCPlusPlus(SourceLanguage S) { bool result = false; // Deliberately enumerate all the language options so we get a warning when @@ -268,7 +546,19 @@ inline bool isCPlusPlus(SourceLanguage S) { case DW_LANG_Fortran18: case DW_LANG_Ada2005: case DW_LANG_Ada2012: + case DW_LANG_HIP: + case DW_LANG_Assembly: + case DW_LANG_C_sharp: case DW_LANG_Mojo: + case DW_LANG_GLSL: + case DW_LANG_GLSL_ES: + case DW_LANG_HLSL: + case DW_LANG_OpenCL_CPP: + case DW_LANG_CPP_for_OpenCL: + case DW_LANG_SYCL: + case DW_LANG_Ruby: + case DW_LANG_Move: + case DW_LANG_Hylo: result = false; break; } @@ -335,7 +625,19 @@ inline bool isFortran(SourceLanguage S) { case DW_LANG_C17: case DW_LANG_Ada2005: case DW_LANG_Ada2012: + case DW_LANG_HIP: + case DW_LANG_Assembly: + case DW_LANG_C_sharp: case DW_LANG_Mojo: + case DW_LANG_GLSL: + case DW_LANG_GLSL_ES: + case DW_LANG_HLSL: + case DW_LANG_OpenCL_CPP: + case DW_LANG_CPP_for_OpenCL: + case DW_LANG_SYCL: + case DW_LANG_Ruby: + case DW_LANG_Move: + case DW_LANG_Hylo: result = false; break; } @@ -400,7 +702,19 @@ inline bool isC(SourceLanguage S) { case DW_LANG_Fortran18: case DW_LANG_Ada2005: case DW_LANG_Ada2012: + case DW_LANG_HIP: + case DW_LANG_Assembly: + case DW_LANG_C_sharp: case DW_LANG_Mojo: + case DW_LANG_GLSL: + case DW_LANG_GLSL_ES: + case DW_LANG_HLSL: + case DW_LANG_OpenCL_CPP: + case DW_LANG_CPP_for_OpenCL: + case DW_LANG_SYCL: + case DW_LANG_Ruby: + case DW_LANG_Move: + case DW_LANG_Hylo: return false; } llvm_unreachable("Unknown language kind."); diff --git a/llvm/lib/BinaryFormat/Dwarf.cpp b/llvm/lib/BinaryFormat/Dwarf.cpp index e4e5b5d..7324266 100644 --- a/llvm/lib/BinaryFormat/Dwarf.cpp +++ b/llvm/lib/BinaryFormat/Dwarf.cpp @@ -411,6 +411,16 @@ llvm::dwarf::LanguageLowerBound(dwarf::SourceLanguage Lang) { } } +StringRef llvm::dwarf::LanguageDescription(dwarf::SourceLanguageName lname) { + switch (lname) { +#define HANDLE_DW_LNAME(ID, NAME, DESC, LOWER_BOUND) \ + case DW_LNAME_##NAME: \ + return DESC; +#include "llvm/BinaryFormat/Dwarf.def" + } + return "Unknown"; +} + StringRef llvm::dwarf::CaseString(unsigned Case) { switch (Case) { case DW_ID_case_sensitive: diff --git a/llvm/unittests/BinaryFormat/DwarfTest.cpp b/llvm/unittests/BinaryFormat/DwarfTest.cpp index 2fff865..684e59f 100644 --- a/llvm/unittests/BinaryFormat/DwarfTest.cpp +++ b/llvm/unittests/BinaryFormat/DwarfTest.cpp @@ -204,4 +204,19 @@ TEST(DwarfTest, format_provider) { EXPECT_EQ("DW_OP_lit0", formatv("{0}", DW_OP_lit0).str()); EXPECT_EQ("DW_OP_unknown_ff", formatv("{0}", DW_OP_hi_user).str()); } + +TEST(DwarfTest, lname) { + auto roundtrip = [](llvm::dwarf::SourceLanguage sl) { + auto name_version = toDW_LNAME(sl); + // Ignore ones without a defined mapping. + if (sl == DW_LANG_Mips_Assembler || sl == DW_LANG_GOOGLE_RenderScript || + !name_version.has_value()) + return sl; + return dwarf::toDW_LANG(name_version->first, name_version->second) + .value_or(sl); + }; +#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ + EXPECT_EQ(roundtrip(DW_LANG_##NAME), DW_LANG_##NAME); +#include "llvm/BinaryFormat/Dwarf.def" +} } // end namespace |