target/arm/vfp_helper: Extract vfp_set_fpscr_to_host()
[qemu/ar7.git] / scripts / modules / module_block.py
blob08646af92c13676d18c3d800bf93e40af34d002e
1 #!/usr/bin/python
3 # Module information generator
5 # Copyright Red Hat, Inc. 2015 - 2016
7 # Authors:
8 # Marc Mari <markmb@redhat.com>
10 # This work is licensed under the terms of the GNU GPL, version 2.
11 # See the COPYING file in the top-level directory.
13 from __future__ import print_function
14 import sys
15 import os
17 def get_string_struct(line):
18 data = line.split()
20 # data[0] -> struct element name
21 # data[1] -> =
22 # data[2] -> value
24 return data[2].replace('"', '')[:-1]
26 def add_module(fheader, library, format_name, protocol_name):
27 lines = []
28 lines.append('.library_name = "' + library + '",')
29 if format_name != "":
30 lines.append('.format_name = "' + format_name + '",')
31 if protocol_name != "":
32 lines.append('.protocol_name = "' + protocol_name + '",')
34 text = '\n '.join(lines)
35 fheader.write('\n {\n ' + text + '\n },')
37 def process_file(fheader, filename):
38 # This parser assumes the coding style rules are being followed
39 with open(filename, "r") as cfile:
40 found_start = False
41 library, _ = os.path.splitext(os.path.basename(filename))
42 for line in cfile:
43 if found_start:
44 line = line.replace('\n', '')
45 if line.find(".format_name") != -1:
46 format_name = get_string_struct(line)
47 elif line.find(".protocol_name") != -1:
48 protocol_name = get_string_struct(line)
49 elif line == "};":
50 add_module(fheader, library, format_name, protocol_name)
51 found_start = False
52 elif line.find("static BlockDriver") != -1:
53 found_start = True
54 format_name = ""
55 protocol_name = ""
57 def print_top(fheader):
58 fheader.write('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
60 * QEMU Block Module Infrastructure
62 * Authors:
63 * Marc Mari <markmb@redhat.com>
66 ''')
68 fheader.write('''#ifndef QEMU_MODULE_BLOCK_H
69 #define QEMU_MODULE_BLOCK_H
71 static const struct {
72 const char *format_name;
73 const char *protocol_name;
74 const char *library_name;
75 } block_driver_modules[] = {''')
77 def print_bottom(fheader):
78 fheader.write('''
81 #endif
82 ''')
84 # First argument: output file
85 # All other arguments: modules source files (.c)
86 output_file = sys.argv[1]
87 with open(output_file, 'w') as fheader:
88 print_top(fheader)
90 for filename in sys.argv[2:]:
91 if os.path.isfile(filename):
92 process_file(fheader, filename)
93 else:
94 print("File " + filename + " does not exist.", file=sys.stderr)
95 sys.exit(1)
97 print_bottom(fheader)
99 sys.exit(0)