[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -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( JDevlieghere wrote: https://github.com/llvm/llvm-project/pull/91254 https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -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( labath wrote: I believe this should be using `add_custom_command`. Per the [cmake docs](https://cmake.org/cmake/help/latest/command/add_custom_target.html), `add_custom_target` "... has no output file and is always considered out of date even if the commands try to create a file with the name of the target". This causes an incremental clean build to always run this command and also rebuild anything that depends on it. https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -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[^,]+), (?P[^"]+), "(?P.*)",.*\)' kastiglione wrote: to combine my feedback with Adrian's: ```python r'^ *HANDLE_DW_LNAME *\( *(?P[^,]+), (?P[^,]+), "(?P[^"]*)",.*\)' ``` https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/adrian-prantl approved this pull request. https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/90753 >From 5f66f7b0bf2add28eebdfefd2ae9459f8548a1b4 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 1 May 2024 10:36:51 -0700 Subject: [PATCH 1/3] [lldb] Use Python script to generate SBLanguages.h Use a Python script to generate SBLanguages.h instead of piggybacking on LLDB TableGen. This addresses Nico Weber's post-commit feedback. --- lldb/scripts/generate-sbapi-dwarf-enum.py | 65 + lldb/source/API/CMakeLists.txt | 18 -- lldb/utils/TableGen/CMakeLists.txt | 1 - lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp | 67 -- lldb/utils/TableGen/LLDBTableGen.cpp | 8 --- 5 files changed, 79 insertions(+), 80 deletions(-) create mode 100755 lldb/scripts/generate-sbapi-dwarf-enum.py delete mode 100644 lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp diff --git a/lldb/scripts/generate-sbapi-dwarf-enum.py b/lldb/scripts/generate-sbapi-dwarf-enum.py new file mode 100755 index 00..c4252223430ed6 --- /dev/null +++ b/lldb/scripts/generate-sbapi-dwarf-enum.py @@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') + + +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.search(line) +if not match: +continue +f.write(f" /// {match.group(4)}.\n") +f.write(f" eLanguageName{match.group(3)} = {match.group(2)},\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() diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index ad960403ae70bf..a64c0d4a333425 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -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( + 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 diff --git a/lldb/utils/TableGen/CMakeLists.txt b/lldb/utils/TableGen/CMakeLists.txt index 68547fe13e1aeb..47a6400b4287e2 100644 --- a/lldb/utils/TableGen/CMakeLists.txt +++ b/lldb/utils/TableGen/CMakeLists.txt @@ -10,7 +10,6 @@ if (NOT DEFINED LLDB_TABLEGEN_EXE) add_tablegen(lldb-tblgen LLDB LLDBOptionDefEmitter.cpp LLDBPropertyDefEmitter.cpp - LLDBSBAPIDWARFEnum.cpp LLDBTableGen.cpp LLDBTableGenUtils.cpp ) diff --git a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp b/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp deleted file mode 100644 index 084284ed6aa82a..00 --- a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===- LLDBPropertyDefEmitter.cpp -===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -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[^,]+), (?P[^,]+), "(?P.*)",.*\)' adrian-prantl wrote: Also is it possible to make the third one `P[^"]`? That would be safer. https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/adrian-prantl requested changes to this pull request. https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/adrian-prantl edited https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/adrian-prantl approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -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[^,]+), (?P[^,]+), "(?P.*)",.*\)' kastiglione wrote: looks like you have comment and name swapped https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/90753 >From 5f66f7b0bf2add28eebdfefd2ae9459f8548a1b4 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 1 May 2024 10:36:51 -0700 Subject: [PATCH 1/2] [lldb] Use Python script to generate SBLanguages.h Use a Python script to generate SBLanguages.h instead of piggybacking on LLDB TableGen. This addresses Nico Weber's post-commit feedback. --- lldb/scripts/generate-sbapi-dwarf-enum.py | 65 + lldb/source/API/CMakeLists.txt | 18 -- lldb/utils/TableGen/CMakeLists.txt | 1 - lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp | 67 -- lldb/utils/TableGen/LLDBTableGen.cpp | 8 --- 5 files changed, 79 insertions(+), 80 deletions(-) create mode 100755 lldb/scripts/generate-sbapi-dwarf-enum.py delete mode 100644 lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp diff --git a/lldb/scripts/generate-sbapi-dwarf-enum.py b/lldb/scripts/generate-sbapi-dwarf-enum.py new file mode 100755 index 00..c4252223430ed6 --- /dev/null +++ b/lldb/scripts/generate-sbapi-dwarf-enum.py @@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') + + +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.search(line) +if not match: +continue +f.write(f" /// {match.group(4)}.\n") +f.write(f" eLanguageName{match.group(3)} = {match.group(2)},\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() diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index ad960403ae70bf..a64c0d4a333425 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -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( + 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 diff --git a/lldb/utils/TableGen/CMakeLists.txt b/lldb/utils/TableGen/CMakeLists.txt index 68547fe13e1aeb..47a6400b4287e2 100644 --- a/lldb/utils/TableGen/CMakeLists.txt +++ b/lldb/utils/TableGen/CMakeLists.txt @@ -10,7 +10,6 @@ if (NOT DEFINED LLDB_TABLEGEN_EXE) add_tablegen(lldb-tblgen LLDB LLDBOptionDefEmitter.cpp LLDBPropertyDefEmitter.cpp - LLDBSBAPIDWARFEnum.cpp LLDBTableGen.cpp LLDBTableGenUtils.cpp ) diff --git a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp b/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp deleted file mode 100644 index 084284ed6aa82a..00 --- a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===- LLDBPropertyDefEmitter.cpp -===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/kastiglione edited https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') kastiglione wrote: ```suggestion REGEX = re.compile(r'^ *HANDLE_DW_LNAME *\( *(?P[^,]+), (?P[^,]+), "(?P.*)",.*\)') ``` https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') + + +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.search(line) +if not match: +continue +f.write(f" /// {match.group(4)}.\n") +f.write(f" eLanguageName{match.group(3)} = {match.group(2)},\n") kastiglione wrote: these would benefit from using named captures, ex: ```suggestion f.write(f" /// {match.group("whatever_group_4_is")}.\n") f.write(f" eLanguageName{match.group("name")} = {match.group("value")},\n") ``` https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
@@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') + + +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.search(line) kastiglione wrote: since the regex is anchored to the start (`^`), this should probably be match (in which case you can remove the `^` if you want) https://github.com/llvm/llvm-project/pull/90753 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes Use a Python script to generate SBLanguages.h instead of piggybacking on LLDB TableGen. This addresses Nico Weber's post-commit feedback. --- Full diff: https://github.com/llvm/llvm-project/pull/90753.diff 5 Files Affected: - (added) lldb/scripts/generate-sbapi-dwarf-enum.py (+65) - (modified) lldb/source/API/CMakeLists.txt (+14-4) - (modified) lldb/utils/TableGen/CMakeLists.txt (-1) - (removed) lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp (-67) - (modified) lldb/utils/TableGen/LLDBTableGen.cpp (-8) ``diff diff --git a/lldb/scripts/generate-sbapi-dwarf-enum.py b/lldb/scripts/generate-sbapi-dwarf-enum.py new file mode 100755 index 00..c4252223430ed6 --- /dev/null +++ b/lldb/scripts/generate-sbapi-dwarf-enum.py @@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') + + +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.search(line) +if not match: +continue +f.write(f" /// {match.group(4)}.\n") +f.write(f" eLanguageName{match.group(3)} = {match.group(2)},\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() diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index ad960403ae70bf..a64c0d4a333425 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -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( + 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 diff --git a/lldb/utils/TableGen/CMakeLists.txt b/lldb/utils/TableGen/CMakeLists.txt index 68547fe13e1aeb..47a6400b4287e2 100644 --- a/lldb/utils/TableGen/CMakeLists.txt +++ b/lldb/utils/TableGen/CMakeLists.txt @@ -10,7 +10,6 @@ if (NOT DEFINED LLDB_TABLEGEN_EXE) add_tablegen(lldb-tblgen LLDB LLDBOptionDefEmitter.cpp LLDBPropertyDefEmitter.cpp - LLDBSBAPIDWARFEnum.cpp LLDBTableGen.cpp LLDBTableGenUtils.cpp ) diff --git a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp b/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp deleted file mode 100644 index 084284ed6aa82a..00 --- a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===- LLDBPropertyDefEmitter.cpp -===// -// -// 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 -// -//===--===// -// -// Produce the list of source languages header file fragment for the SBAPI. -//
[Lldb-commits] [lldb] [lldb] Use Python script to generate SBLanguages.h (PR #90753)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/90753 Use a Python script to generate SBLanguages.h instead of piggybacking on LLDB TableGen. This addresses Nico Weber's post-commit feedback. >From 5f66f7b0bf2add28eebdfefd2ae9459f8548a1b4 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 1 May 2024 10:36:51 -0700 Subject: [PATCH] [lldb] Use Python script to generate SBLanguages.h Use a Python script to generate SBLanguages.h instead of piggybacking on LLDB TableGen. This addresses Nico Weber's post-commit feedback. --- lldb/scripts/generate-sbapi-dwarf-enum.py | 65 + lldb/source/API/CMakeLists.txt | 18 -- lldb/utils/TableGen/CMakeLists.txt | 1 - lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp | 67 -- lldb/utils/TableGen/LLDBTableGen.cpp | 8 --- 5 files changed, 79 insertions(+), 80 deletions(-) create mode 100755 lldb/scripts/generate-sbapi-dwarf-enum.py delete mode 100644 lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp diff --git a/lldb/scripts/generate-sbapi-dwarf-enum.py b/lldb/scripts/generate-sbapi-dwarf-enum.py new file mode 100755 index 00..c4252223430ed6 --- /dev/null +++ b/lldb/scripts/generate-sbapi-dwarf-enum.py @@ -0,0 +1,65 @@ +#!/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 *\( *([^,]+), ([^,]+), )"(.*)",.*\).*') + + +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.search(line) +if not match: +continue +f.write(f" /// {match.group(4)}.\n") +f.write(f" eLanguageName{match.group(3)} = {match.group(2)},\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() diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index ad960403ae70bf..a64c0d4a333425 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -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( + 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 diff --git a/lldb/utils/TableGen/CMakeLists.txt b/lldb/utils/TableGen/CMakeLists.txt index 68547fe13e1aeb..47a6400b4287e2 100644 --- a/lldb/utils/TableGen/CMakeLists.txt +++ b/lldb/utils/TableGen/CMakeLists.txt @@ -10,7 +10,6 @@ if (NOT DEFINED LLDB_TABLEGEN_EXE) add_tablegen(lldb-tblgen LLDB LLDBOptionDefEmitter.cpp LLDBPropertyDefEmitter.cpp - LLDBSBAPIDWARFEnum.cpp LLDBTableGen.cpp LLDBTableGenUtils.cpp ) diff --git a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp b/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp deleted file mode 100644 index 084284ed6aa82a..00 --- a/lldb/utils/TableGen/LLDBSBAPIDWARFEnum.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===- LLDBPropertyDefEmitter.cpp