-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[lldb] Use Python script to generate SBLanguages.h #90753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import re | ||
|
||
HEADER = """\ | ||
//===-- SBLanguages.h -----------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_API_SBLANGUAGE_H | ||
#define LLDB_API_SBLANGUAGE_H | ||
/// Used by \\ref SBExpressionOptions. | ||
/// These enumerations use the same language enumerations as the DWARF | ||
/// specification for ease of use and consistency. | ||
enum SBSourceLanguageName : uint16_t { | ||
""" | ||
|
||
FOOTER = """\ | ||
}; | ||
|
||
#endif | ||
""" | ||
|
||
REGEX = re.compile( | ||
r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<comment>[^"]+), "(?P<name>.*)",.*\)' | ||
) | ||
|
||
|
||
def emit_enum(input, output): | ||
# Read the input and break it up by lines. | ||
lines = [] | ||
with open(input, "r") as f: | ||
lines = f.readlines() | ||
|
||
# Write the output. | ||
with open(output, "w") as f: | ||
# Emit the header. | ||
f.write(HEADER) | ||
|
||
# Emit the enum values. | ||
for line in lines: | ||
match = REGEX.match(line) | ||
if not match: | ||
continue | ||
f.write(f" /// {match.group('comment')}.\n") | ||
f.write(f" eLanguageName{match.group('name')} = {match.group('value')},\n") | ||
|
||
# Emit the footer | ||
f.write(FOOTER) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--output", "-o") | ||
parser.add_argument("input") | ||
args = parser.parse_args() | ||
|
||
emit_enum(args.input, args.output) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,19 @@ if(LLDB_ENABLE_LUA) | |
set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp) | ||
endif() | ||
|
||
lldb_tablegen(../../include/lldb/API/SBLanguages.h -gen-lldb-sbapi-dwarf-enum | ||
SOURCE ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def | ||
TARGET lldb-sbapi-dwarf-enums) | ||
# Target to generate SBLanguages.h from Dwarf.def. | ||
set(sb_languages_file | ||
${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h) | ||
add_custom_target( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
lldb-sbapi-dwarf-enums | ||
"${Python3_EXECUTABLE}" | ||
${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py | ||
${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def | ||
-o ${sb_languages_file} | ||
BYPRODUCTS ${sb_languages_file} | ||
DEPENDS ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def | ||
WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR} | ||
) | ||
|
||
add_lldb_library(liblldb SHARED ${option_framework} | ||
SBAddress.cpp | ||
|
@@ -106,7 +116,7 @@ add_lldb_library(liblldb SHARED ${option_framework} | |
|
||
DEPENDS | ||
lldb-sbapi-dwarf-enums | ||
|
||
LINK_LIBS | ||
lldbBreakpoint | ||
lldbCore | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to combine my feedback with Adrian's:
r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<name>[^,]+), "(?P<comment>[^"]*)",.*\)'