xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSourceLanguage.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- LVSourceLanguage.h --------------------------------------*- 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 // This file defines the LVSourceLanguage struct, a unified representation of
10 // the source language used in a compile unit.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSOURCELANGUAGE_H
15 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSOURCELANGUAGE_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/BinaryFormat/Dwarf.h"
19 #include "llvm/DebugInfo/CodeView/CodeView.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace llvm {
23 namespace logicalview {
24 
25 /// A source language supported by any of the debug info representations.
26 struct LVSourceLanguage {
27   static constexpr unsigned TagDwarf = 0x00;
28   static constexpr unsigned TagCodeView = 0x01;
29 
30   enum TaggedLanguage : uint32_t {
31     Invalid = -1U,
32 
33   // DWARF
34 #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR)                 \
35   DW_LANG_##NAME = (TagDwarf << 16) | ID,
36 #include "llvm/BinaryFormat/Dwarf.def"
37   // CodeView
38 #define CV_LANGUAGE(NAME, ID) CV_LANG_##NAME = (TagCodeView << 16) | ID,
39 #include "llvm/DebugInfo/CodeView/CodeViewLanguages.def"
40   };
41 
42   LVSourceLanguage() = default;
LVSourceLanguageLVSourceLanguage43   LVSourceLanguage(llvm::dwarf::SourceLanguage SL)
44       : LVSourceLanguage(TagDwarf, SL) {}
LVSourceLanguageLVSourceLanguage45   LVSourceLanguage(llvm::codeview::SourceLanguage SL)
46       : LVSourceLanguage(TagCodeView, SL) {}
47   bool operator==(const LVSourceLanguage &SL) const {
48     return get() == SL.get();
49   }
50   bool operator==(const LVSourceLanguage::TaggedLanguage &TL) const {
51     return get() == TL;
52   }
53 
isValidLVSourceLanguage54   bool isValid() const { return Language != Invalid; }
getLVSourceLanguage55   TaggedLanguage get() const { return Language; }
56   LLVM_ABI StringRef getName() const;
57 
58 private:
59   TaggedLanguage Language = Invalid;
60 
LVSourceLanguageLVSourceLanguage61   LVSourceLanguage(unsigned Tag, unsigned Lang)
62       : Language(static_cast<TaggedLanguage>((Tag << 16) | Lang)) {}
getTagLVSourceLanguage63   unsigned getTag() const { return Language >> 16; }
getLangLVSourceLanguage64   unsigned getLang() const { return Language & 0xffff; }
65 };
66 
67 } // end namespace logicalview
68 } // end namespace llvm
69 
70 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSOURCELANGUAGE_H
71