Skip to content

Commit dcbf0fc

Browse files
authored
[lldb] Use Python script to generate SBLanguages.h (#90753)
Use a Python script to generate SBLanguages.h instead of piggybacking on LLDB TableGen. This addresses Nico Weber's post-commit feedback.
1 parent c4e8e2c commit dcbf0fc

File tree

5 files changed

+81
-80
lines changed

5 files changed

+81
-80
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import re
5+
6+
HEADER = """\
7+
//===-- SBLanguages.h -----------------------------------------*- C++ -*-===//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLDB_API_SBLANGUAGE_H
16+
#define LLDB_API_SBLANGUAGE_H
17+
/// Used by \\ref SBExpressionOptions.
18+
/// These enumerations use the same language enumerations as the DWARF
19+
/// specification for ease of use and consistency.
20+
enum SBSourceLanguageName : uint16_t {
21+
"""
22+
23+
FOOTER = """\
24+
};
25+
26+
#endif
27+
"""
28+
29+
REGEX = re.compile(
30+
r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<comment>[^"]+), "(?P<name>.*)",.*\)'
31+
)
32+
33+
34+
def emit_enum(input, output):
35+
# Read the input and break it up by lines.
36+
lines = []
37+
with open(input, "r") as f:
38+
lines = f.readlines()
39+
40+
# Write the output.
41+
with open(output, "w") as f:
42+
# Emit the header.
43+
f.write(HEADER)
44+
45+
# Emit the enum values.
46+
for line in lines:
47+
match = REGEX.match(line)
48+
if not match:
49+
continue
50+
f.write(f" /// {match.group('comment')}.\n")
51+
f.write(f" eLanguageName{match.group('name')} = {match.group('value')},\n")
52+
53+
# Emit the footer
54+
f.write(FOOTER)
55+
56+
57+
def main():
58+
parser = argparse.ArgumentParser()
59+
parser.add_argument("--output", "-o")
60+
parser.add_argument("input")
61+
args = parser.parse_args()
62+
63+
emit_enum(args.input, args.output)
64+
65+
66+
if __name__ == "__main__":
67+
main()

lldb/source/API/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ if(LLDB_ENABLE_LUA)
2020
set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp)
2121
endif()
2222

23-
lldb_tablegen(../../include/lldb/API/SBLanguages.h -gen-lldb-sbapi-dwarf-enum
24-
SOURCE ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
25-
TARGET lldb-sbapi-dwarf-enums)
23+
# Target to generate SBLanguages.h from Dwarf.def.
24+
set(sb_languages_file
25+
${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h)
26+
add_custom_target(
27+
lldb-sbapi-dwarf-enums
28+
"${Python3_EXECUTABLE}"
29+
${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py
30+
${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
31+
-o ${sb_languages_file}
32+
BYPRODUCTS ${sb_languages_file}
33+
DEPENDS ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
34+
WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
35+
)
2636

2737
add_lldb_library(liblldb SHARED ${option_framework}
2838
SBAddress.cpp
@@ -106,7 +116,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
106116

107117
DEPENDS
108118
lldb-sbapi-dwarf-enums
109-
119+
110120
LINK_LIBS
111121
lldbBreakpoint
112122
lldbCore

lldb/utils/TableGen/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ if (NOT DEFINED LLDB_TABLEGEN_EXE)
1010
add_tablegen(lldb-tblgen LLDB
1111
LLDBOptionDefEmitter.cpp
1212
LLDBPropertyDefEmitter.cpp
13-
LLDBSBAPIDWARFEnum.cpp
1413
LLDBTableGen.cpp
1514
LLDBTableGenUtils.cpp
1615
)

lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

lldb/utils/TableGen/LLDBTableGen.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ enum ActionType {
2727
GenOptionDefs,
2828
GenPropertyDefs,
2929
GenPropertyEnumDefs,
30-
GenSBAPIDWARFEnum
3130
};
3231

3332
static cl::opt<ActionType> Action(
@@ -41,8 +40,6 @@ static cl::opt<ActionType> Action(
4140
clEnumValN(GenPropertyDefs, "gen-lldb-property-defs",
4241
"Generate lldb property definitions"),
4342
clEnumValN(GenPropertyEnumDefs, "gen-lldb-property-enum-defs",
44-
"Generate lldb property enum definitions"),
45-
clEnumValN(GenSBAPIDWARFEnum, "gen-lldb-sbapi-dwarf-enum",
4643
"Generate lldb property enum definitions")));
4744

4845
static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
@@ -62,8 +59,6 @@ static bool LLDBTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
6259
case GenPropertyEnumDefs:
6360
EmitPropertyEnumDefs(Records, OS);
6461
break;
65-
case GenSBAPIDWARFEnum:
66-
llvm_unreachable("already handled");
6762
}
6863
return false;
6964
}
@@ -74,9 +69,6 @@ int main(int argc, char **argv) {
7469
cl::ParseCommandLineOptions(argc, argv);
7570
llvm_shutdown_obj Y;
7671

77-
if (Action == GenSBAPIDWARFEnum)
78-
return EmitSBAPIDWARFEnum(argc, argv);
79-
8072
return TableGenMain(argv[0], &LLDBTableGenMain);
8173
}
8274

0 commit comments

Comments
 (0)