OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 """Compile an .idl file to Blink V8 bindings (.h and .cpp files). | 30 """Compile an .idl file to Blink V8 bindings (.h and .cpp files). |
31 | 31 |
32 FIXME: Not currently used in build. | 32 FIXME: Not currently used in build. |
33 This is a rewrite of the Perl IDL compiler in Python, but is not complete. | 33 This is a rewrite of the Perl IDL compiler in Python, but is not complete. |
34 Once it is complete, we will switch all IDL files over to Python at once. | 34 Once it is complete, we will switch all IDL files over to Python at once. |
35 Until then, please work on the Perl IDL compiler. | 35 Until then, please work on the Perl IDL compiler. |
36 For details, see bug http://crbug.com/239771 | 36 For details, see bug http://crbug.com/239771 |
37 """ | 37 """ |
38 | 38 |
39 import optparse | 39 from optparse import OptionParser |
40 import os | 40 import os |
41 import cPickle as pickle | 41 import cPickle as pickle |
42 import sys | 42 import sys |
43 | 43 |
44 import code_generator_v8 | 44 from code_generator_v8 import CodeGeneratorV8 |
45 import idl_reader | 45 from idl_reader import IdlReader |
46 # from utilities import write_file # FIXME: import once in same directory | 46 # from utilities import write_file # FIXME: import once in same directory |
47 | 47 |
48 def parse_options(): | 48 def parse_options(): |
49 parser = optparse.OptionParser() | 49 parser = OptionParser() |
50 parser.add_option('--idl-attributes-file') | 50 parser.add_option('--idl-attributes-file') |
51 parser.add_option('--output-directory') | 51 parser.add_option('--output-directory') |
52 parser.add_option('--interfaces-info-file') | 52 parser.add_option('--interfaces-info-file') |
53 parser.add_option('--write-file-only-if-changed', type='int') | 53 parser.add_option('--write-file-only-if-changed', type='int') |
54 # ensure output comes last, so command line easy to parse via regexes | 54 # ensure output comes last, so command line easy to parse via regexes |
55 parser.disable_interspersed_args() | 55 parser.disable_interspersed_args() |
56 | 56 |
57 options, args = parser.parse_args() | 57 options, args = parser.parse_args() |
58 if options.output_directory is None: | 58 if options.output_directory is None: |
59 parser.error('Must specify output directory using --output-directory.') | 59 parser.error('Must specify output directory using --output-directory.') |
(...skipping 21 matching lines...) Expand all Loading... |
81 output_directory = options.output_directory | 81 output_directory = options.output_directory |
82 only_if_changed = options.write_file_only_if_changed | 82 only_if_changed = options.write_file_only_if_changed |
83 | 83 |
84 interfaces_info_filename = options.interfaces_info_file | 84 interfaces_info_filename = options.interfaces_info_file |
85 if interfaces_info_filename: | 85 if interfaces_info_filename: |
86 with open(interfaces_info_filename) as interfaces_info_file: | 86 with open(interfaces_info_filename) as interfaces_info_file: |
87 interfaces_info = pickle.load(interfaces_info_file) | 87 interfaces_info = pickle.load(interfaces_info_file) |
88 else: | 88 else: |
89 interfaces_info = None | 89 interfaces_info = None |
90 | 90 |
91 reader = idl_reader.IdlReader(interfaces_info, options.idl_attributes_file,
output_directory) | 91 reader = IdlReader(interfaces_info, options.idl_attributes_file, output_dire
ctory) |
92 definitions = reader.read_idl_definitions(idl_filename) | 92 definitions = reader.read_idl_definitions(idl_filename) |
93 header_text, cpp_text = code_generator_v8.generate_header_and_cpp(definition
s, interface_name, interfaces_info, output_directory) | 93 |
| 94 code_generator = CodeGeneratorV8(interfaces_info, output_directory) |
| 95 header_text, cpp_text = code_generator.generate_code(definitions, interface_
name) |
94 | 96 |
95 header_filename = output_directory + 'V8%s.h' % interface_name | 97 header_filename = output_directory + 'V8%s.h' % interface_name |
96 cpp_filename = output_directory + 'V8%s.cpp' % interface_name | 98 cpp_filename = output_directory + 'V8%s.cpp' % interface_name |
97 write_file(header_text, header_filename, only_if_changed) | 99 write_file(header_text, header_filename, only_if_changed) |
98 write_file(cpp_text, cpp_filename, only_if_changed) | 100 write_file(cpp_text, cpp_filename, only_if_changed) |
99 | 101 |
100 | 102 |
101 if __name__ == '__main__': | 103 if __name__ == '__main__': |
102 sys.exit(main()) | 104 sys.exit(main()) |
OLD | NEW |