xref: /llvm-project/lldb/scripts/generate-sbapi-dwarf-enum.py (revision b8c301f6e22a6a5ebec4b8870327237eb94c5b15)
1#!/usr/bin/env python3
2
3import argparse
4import re
5
6HEADER = """\
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.
20enum SBSourceLanguageName : uint16_t {
21"""
22
23FOOTER = """\
24};
25
26#endif
27"""
28
29REGEX = re.compile(
30    r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<name>.*), "(?P<comment>[^"]+)",.*\)'
31)
32
33
34def 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
57def 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
66if __name__ == "__main__":
67    main()
68