summaryrefslogtreecommitdiff
path: root/lldb/scripts
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2024-05-01 13:02:47 -0700
committerGitHub <noreply@github.com>2024-05-01 13:02:47 -0700
commitdcbf0fcd0d5572f7001ebdd3bda6062593ec172b (patch)
treed6dfbcf14df3adae62306007f3b1dfc91be0d27b /lldb/scripts
parentc4e8e2c67bbfff2d1b23210c375c173aa05e3848 (diff)
[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.
Diffstat (limited to 'lldb/scripts')
-rwxr-xr-xlldb/scripts/generate-sbapi-dwarf-enum.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/lldb/scripts/generate-sbapi-dwarf-enum.py b/lldb/scripts/generate-sbapi-dwarf-enum.py
new file mode 100755
index 000000000000..5eeb8264a768
--- /dev/null
+++ b/lldb/scripts/generate-sbapi-dwarf-enum.py
@@ -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()