1#!/usr/bin/env python3 2 3import argparse 4import re 5import os 6 7HEADER = """\ 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 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLDB_API_SBLANGUAGE_H 17#define LLDB_API_SBLANGUAGE_H 18/// Used by \\ref SBExpressionOptions. 19/// These enumerations use the same language enumerations as the DWARF 20/// specification for ease of use and consistency. 21enum SBSourceLanguageName : uint16_t { 22""" 23 24FOOTER = """\ 25}; 26 27#endif 28""" 29 30REGEX = re.compile( 31 r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<name>.*), "(?P<comment>[^"]+)",.*\)' 32) 33 34 35def emit_enum(input, output): 36 # Read the input and break it up by lines. 37 lines = [] 38 with open(input, "r") as f: 39 lines = f.readlines() 40 41 # Create output folder if it does not exist 42 os.makedirs(os.path.dirname(output), exist_ok=True) 43 44 # Write the output. 45 with open(output, "w") as f: 46 # Emit the header. 47 f.write(HEADER) 48 49 # Emit the enum values. 50 for line in lines: 51 match = REGEX.match(line) 52 if not match: 53 continue 54 f.write(f" /// {match.group('comment')}.\n") 55 f.write(f" eLanguageName{match.group('name')} = {match.group('value')},\n") 56 57 # Emit the footer 58 f.write(FOOTER) 59 60 61def main(): 62 parser = argparse.ArgumentParser() 63 parser.add_argument("--output", "-o") 64 parser.add_argument("input") 65 args = parser.parse_args() 66 67 emit_enum(args.input, args.output) 68 69 70if __name__ == "__main__": 71 main() 72