Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22e90ef

Browse filesBrowse files
committed
[llvm-debuginfo-analyzer] LVSourceLanguage: use enum instead of std::variant
1 parent 1194ebf commit 22e90ef
Copy full SHA for 22e90ef

File tree

Expand file treeCollapse file tree

6 files changed

+89
-49
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+89
-49
lines changed

‎llvm/include/llvm/DebugInfo/CodeView/CodeView.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/DebugInfo/CodeView/CodeView.h
+2-30Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -144,36 +144,8 @@ enum class CPUType : uint16_t {
144144
/// Debug Interface Access SDK, and are documented here:
145145
/// https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/cv-cfl-lang
146146
enum SourceLanguage : uint8_t {
147-
C = 0x00,
148-
Cpp = 0x01,
149-
Fortran = 0x02,
150-
Masm = 0x03,
151-
Pascal = 0x04,
152-
Basic = 0x05,
153-
Cobol = 0x06,
154-
Link = 0x07,
155-
Cvtres = 0x08,
156-
Cvtpgd = 0x09,
157-
CSharp = 0x0a,
158-
VB = 0x0b,
159-
ILAsm = 0x0c,
160-
Java = 0x0d,
161-
JScript = 0x0e,
162-
MSIL = 0x0f,
163-
HLSL = 0x10,
164-
ObjC = 0x11,
165-
ObjCpp = 0x12,
166-
Swift = 0x13,
167-
AliasObj = 0x14,
168-
Rust = 0x15,
169-
Go = 0x16,
170-
171-
/// The DMD compiler emits 'D' for the CV source language. Microsoft does not
172-
/// have an enumerator for it yet.
173-
D = 'D',
174-
/// The Swift compiler used to emit 'S' for the CV source language, but
175-
/// current versions emit the enumerator defined above.
176-
OldSwift = 'S',
147+
#define CV_LANGUAGE(NAME, ID) NAME = ID,
148+
#include "CodeViewLanguages.def"
177149
};
178150

179151
/// These values correspond to the CV_call_e enumeration, and are documented
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===-- CodeViewLanguages.def - All CodeView languages ----------*- 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+
// These values correspond to the CV_CFL_LANG enumeration in the Microsoft
10+
// Debug Interface Access SDK, and are documented here:
11+
// https://learn.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/cv-cfl-lang
12+
// This should match the constants there.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#ifndef CV_LANGUAGE
17+
#define CV_LANGUAGE(NAME, ID)
18+
#endif
19+
20+
CV_LANGUAGE(C, 0x00)
21+
CV_LANGUAGE(Cpp, 0x01)
22+
CV_LANGUAGE(Fortran, 0x02)
23+
CV_LANGUAGE(Masm, 0x03)
24+
CV_LANGUAGE(Pascal, 0x04)
25+
CV_LANGUAGE(Basic, 0x05)
26+
CV_LANGUAGE(Cobol, 0x06)
27+
CV_LANGUAGE(Link, 0x07)
28+
CV_LANGUAGE(Cvtres, 0x08)
29+
CV_LANGUAGE(Cvtpgd, 0x09)
30+
CV_LANGUAGE(CSharp, 0x0a)
31+
CV_LANGUAGE(VB, 0x0b)
32+
CV_LANGUAGE(ILAsm, 0x0c)
33+
CV_LANGUAGE(Java, 0x0d)
34+
CV_LANGUAGE(JScript, 0x0e)
35+
CV_LANGUAGE(MSIL, 0x0f)
36+
CV_LANGUAGE(HLSL, 0x10)
37+
CV_LANGUAGE(ObjC, 0x11)
38+
CV_LANGUAGE(ObjCpp, 0x12)
39+
CV_LANGUAGE(Swift, 0x13)
40+
CV_LANGUAGE(AliasObj, 0x14)
41+
CV_LANGUAGE(Rust, 0x15)
42+
CV_LANGUAGE(Go, 0x16)
43+
44+
// The DMD compiler emits 'D' for the CV source language. Microsoft does not
45+
// have an enumerator for it yet.
46+
CV_LANGUAGE(D, 'D')
47+
/// The Swift compiler used to emit 'S' for the CV source language, but
48+
// current versions emit the enumerator defined above.
49+
CV_LANGUAGE(OldSwift, 'S')
50+
51+
#undef CV_LANGUAGE

‎llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h
+28-8Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/Support/MathExtras.h"
2020
#include <map>
2121
#include <set>
22-
#include <variant>
2322
#include <vector>
2423

2524
namespace llvm {
@@ -73,18 +72,39 @@ constexpr unsigned int DWARF_CHAR_BIT = 8u;
7372

7473
/// A source language supported by any of the debug info representations.
7574
struct LVSourceLanguage {
75+
static constexpr unsigned TagDwarf = 0x00;
76+
static constexpr unsigned TagCodeView = 0x01;
77+
78+
enum TaggedLanguage : uint32_t {
79+
// DWARF
80+
#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
81+
DW_LANG_##NAME = (TagDwarf << 16) | ID,
82+
#include "llvm/BinaryFormat/Dwarf.def"
83+
// CodeView
84+
#define CV_LANGUAGE(NAME, ID) CV_LANG_##NAME = (TagCodeView << 16) | ID,
85+
#include "llvm/DebugInfo/CodeView/CodeViewLanguages.def"
86+
87+
Invalid = -1U
88+
};
89+
7690
LVSourceLanguage() = default;
77-
LVSourceLanguage(llvm::dwarf::SourceLanguage SL) : Language(SL) {}
78-
LVSourceLanguage(llvm::codeview::SourceLanguage SL) : Language(SL) {}
91+
LVSourceLanguage(llvm::dwarf::SourceLanguage SL)
92+
: Language(static_cast<TaggedLanguage>((TagDwarf << 16) | SL)) {}
93+
LVSourceLanguage(llvm::codeview::SourceLanguage SL)
94+
: Language(static_cast<TaggedLanguage>((TagCodeView << 16) | SL)) {}
95+
bool operator==(const LVSourceLanguage &SL) const {
96+
return get() == SL.get();
97+
}
98+
bool operator==(const LVSourceLanguage::TaggedLanguage &TL) const {
99+
return get() == TL;
100+
}
79101

80-
bool isValid() const { return Language.index() != 0; }
81-
template <typename T> T getAs() { return std::get<T>(Language); }
102+
bool isValid() const { return Language != Invalid; }
103+
TaggedLanguage get() const { return Language; }
82104
StringRef getName() const;
83105

84106
private:
85-
std::variant<std::monostate, llvm::dwarf::SourceLanguage,
86-
llvm::codeview::SourceLanguage>
87-
Language;
107+
TaggedLanguage Language = Invalid;
88108
};
89109

90110
class LVElement : public LVObject {

‎llvm/lib/DebugInfo/LogicalView/Core/LVElement.cpp

Copy file name to clipboardExpand all lines: llvm/lib/DebugInfo/LogicalView/Core/LVElement.cpp
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ using namespace llvm::logicalview;
2323
StringRef LVSourceLanguage::getName() const {
2424
if (!isValid())
2525
return {};
26-
switch (Language.index()) {
27-
case 1: // DWARF
28-
return llvm::dwarf::LanguageString(
29-
std::get<llvm::dwarf::SourceLanguage>(Language));
30-
case 2: // CodeView
31-
{
26+
const unsigned Tag = (Language >> 16);
27+
switch (Tag) {
28+
case LVSourceLanguage::TagDwarf:
29+
return llvm::dwarf::LanguageString(Language & 0xffff);
30+
case LVSourceLanguage::TagCodeView: {
3231
static auto LangNames = llvm::codeview::getSourceLanguageNames();
33-
return LangNames[std::get<llvm::codeview::SourceLanguage>(Language)].Name;
32+
return LangNames[Language & 0xffff].Name;
3433
}
3534
default:
3635
llvm_unreachable("Unsupported language");

‎llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp

Copy file name to clipboardExpand all lines: llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ void checkElementPropertiesClangCodeview(LVReader *Reader) {
8181
EXPECT_EQ(CompileUnit->getName(), "test.cpp");
8282
LVSourceLanguage Language = CompileUnit->getSourceLanguage();
8383
EXPECT_TRUE(Language.isValid());
84-
ASSERT_EQ(Language.getAs<llvm::codeview::SourceLanguage>(),
85-
llvm::codeview::SourceLanguage::Cpp);
84+
ASSERT_EQ(Language, LVSourceLanguage::CV_LANG_Cpp);
8685
ASSERT_EQ(Language.getName(), "Cpp");
8786

8887
EXPECT_EQ(Function->lineCount(), 16u);

‎llvm/unittests/DebugInfo/LogicalView/DWARFReaderTest.cpp

Copy file name to clipboardExpand all lines: llvm/unittests/DebugInfo/LogicalView/DWARFReaderTest.cpp
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ void checkElementProperties(LVReader *Reader) {
7878
EXPECT_EQ(CompileUnit->getName(), "test.cpp");
7979
LVSourceLanguage Language = CompileUnit->getSourceLanguage();
8080
EXPECT_TRUE(Language.isValid());
81-
EXPECT_EQ(Language.getAs<llvm::dwarf::SourceLanguage>(),
82-
llvm::dwarf::DW_LANG_C_plus_plus_14);
81+
EXPECT_EQ(Language, LVSourceLanguage::DW_LANG_C_plus_plus_14);
8382
EXPECT_EQ(Language.getName(), "DW_LANG_C_plus_plus_14");
8483

8584
EXPECT_EQ(CompileUnit->lineCount(), 0u);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.