Add the initializes attribute inference (#117104)
[llvm-project.git] / lldb / scripts / generate-sbapi-dwarf-enum.py
blob689c7f81bfda01894a767f64bdba3ac8de44e93b
1 #!/usr/bin/env python3
3 import argparse
4 import re
5 import os
7 HEADER = """\
8 //===-- SBLanguages.h -----------------------------------------*- C++ -*-===//
9 //
10 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11 // See https://llvm.org/LICENSE.txt for license information.
12 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //===----------------------------------------------------------------------===//
16 #ifndef LLDB_API_SBLANGUAGE_H
17 #define LLDB_API_SBLANGUAGE_H
19 #include <cstdint>
21 namespace lldb {
22 /// Used by \\ref SBExpressionOptions.
23 /// These enumerations use the same language enumerations as the DWARF
24 /// specification for ease of use and consistency.
25 enum SBSourceLanguageName : uint16_t {
26 """
28 FOOTER = """\
31 } // namespace lldb
33 #endif
34 """
36 REGEX = re.compile(
37 r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<name>.*), "(?P<comment>[^"]+)",.*\)'
41 def emit_enum(input, output):
42 # Read the input and break it up by lines.
43 lines = []
44 with open(input, "r") as f:
45 lines = f.readlines()
47 # Create output folder if it does not exist
48 os.makedirs(os.path.dirname(output), exist_ok=True)
50 # Write the output.
51 with open(output, "w") as f:
52 # Emit the header.
53 f.write(HEADER)
55 # Emit the enum values.
56 for line in lines:
57 match = REGEX.match(line)
58 if not match:
59 continue
60 f.write(f" /// {match.group('comment')}.\n")
61 f.write(f" eLanguageName{match.group('name')} = {match.group('value')},\n")
63 # Emit the footer
64 f.write(FOOTER)
67 def main():
68 parser = argparse.ArgumentParser()
69 parser.add_argument("--output", "-o")
70 parser.add_argument("input")
71 args = parser.parse_args()
73 emit_enum(args.input, args.output)
76 if __name__ == "__main__":
77 main()