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 19#include <cstdint> 20 21namespace 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. 25enum SBSourceLanguageName : uint16_t { 26""" 27 28FOOTER = """\ 29}; 30 31} // namespace lldb 32 33#endif 34""" 35 36REGEX = re.compile( 37 r'^ *HANDLE_DW_LNAME *\( *(?P<value>[^,]+), (?P<name>.*), "(?P<comment>[^"]+)",.*\)' 38) 39 40 41def 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() 46 47 # Create output folder if it does not exist 48 os.makedirs(os.path.dirname(output), exist_ok=True) 49 50 # Write the output. 51 with open(output, "w") as f: 52 # Emit the header. 53 f.write(HEADER) 54 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") 62 63 # Emit the footer 64 f.write(FOOTER) 65 66 67def main(): 68 parser = argparse.ArgumentParser() 69 parser.add_argument("--output", "-o") 70 parser.add_argument("input") 71 args = parser.parse_args() 72 73 emit_enum(args.input, args.output) 74 75 76if __name__ == "__main__": 77 main() 78