OLD | NEW |
1 #!/usr/bin/env 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 |
11 # copyright notice, this list of conditions and the following disclaimer | 11 # copyright notice, this list of conditions and the following disclaimer |
12 # in the documentation and/or other materials provided with the | 12 # in the documentation and/or other materials provided with the |
13 # distribution. | 13 # distribution. |
14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
15 # contributors may be used to endorse or promote products derived from | 15 # contributors may be used to endorse or promote products derived from |
16 # this software without specific prior written permission. | 16 # this software without specific prior written permission. |
17 # | 17 # |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
| 30 """Dump Blink IR to JSON and pickle |
| 31 |
| 32 This is for testing IDL parser, and generating parsed files so |
| 33 code generator can be developed before parser lands. |
| 34 """ |
| 35 |
| 36 import optparse |
30 import os.path | 37 import os.path |
| 38 # import pickle |
31 import sys | 39 import sys |
32 | 40 |
33 import in_generator | 41 from blink_idl_lexer import BlinkIDLLexer |
34 import make_runtime_features | 42 from blink_idl_parser import BlinkIDLParser |
35 import template_expander | 43 import ast_to_ir |
| 44 import ir |
| 45 |
| 46 # Base parser is in Chromium src/tools/idl_parser |
| 47 module_path, module_name = os.path.split(__file__) |
| 48 tools_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pardir
, os.pardir, 'tools') |
| 49 sys.path.append(tools_dir) |
| 50 |
| 51 from idl_parser.idl_parser import ParseFile |
36 | 52 |
37 | 53 |
38 # We want exactly the same parsing as RuntimeFeatureWriter | 54 def main(): |
39 # but generate different files. | 55 parser = optparse.OptionParser() |
40 class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter): | 56 parser.add_option('--debug', action='store_true') |
41 class_name = "InternalRuntimeFlags" | 57 options, args = parser.parse_args() |
| 58 idl_filename = args[0] |
| 59 idl_basename = os.path.basename(idl_filename) |
| 60 interface_name, _ = os.path.splitext(idl_basename) |
| 61 json_filename = 'JSON/%s.json' % interface_name |
| 62 # pickle_filename = 'PKL/%s.pkl' % interface_name |
42 | 63 |
43 def __init__(self, in_file_path, enabled_conditions): | 64 if idl_basename == 'InspectorInstrumentation.idl': |
44 super(InternalRuntimeFlagsWriter, self).__init__(in_file_path, enabled_c
onditions) | 65 # Non-conformant pseudo-IDL file |
45 self._outputs = {(self.class_name + ".idl"): self.generate_idl, | 66 return |
46 (self.class_name + ".h"): self.generate_header, | |
47 } | |
48 | 67 |
49 @template_expander.use_jinja(class_name + ".idl.tmpl") | 68 parser = BlinkIDLParser(BlinkIDLLexer(), debug=options.debug) |
50 def generate_idl(self): | 69 filenode = ParseFile(parser, idl_filename) |
51 return { | 70 blink_ir = ast_to_ir.web_idl_ast_to_blink_ir(filenode) |
52 'features': self._features, | 71 json_string = ir.ir_to_json(blink_ir, debug=options.debug) |
53 } | 72 with open(json_filename, 'w') as json_file: |
| 73 json_file.write(json_string) |
| 74 # with open(pickle_filename, 'wb') as pickle_file: |
| 75 # pickle.dump(blink_ir, pickle_file) |
54 | 76 |
55 @template_expander.use_jinja(class_name + ".h.tmpl") | 77 if __name__ == '__main__': |
56 def generate_header(self): | 78 sys.exit(main()) |
57 return { | |
58 'features': self._features, | |
59 'feature_sets': self._feature_sets(), | |
60 } | |
61 | |
62 | |
63 if __name__ == "__main__": | |
64 in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv) | |
OLD | NEW |