- add sources.
[platform/framework/web/crosswalk.git] / src / mojo / public / bindings / mojo_idl.py
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """The frontend for the Mojo bindings system."""
7
8
9 import sys
10 from optparse import OptionParser
11 from parser import mojo_parser
12 from parser import mojo_translate
13 from generators import mojom_data
14 from generators import mojom_cpp_generator
15
16
17 def Main():
18   parser = OptionParser(usage="usage: %prog [options] filename1 [filename2...]")
19   parser.add_option("-i", "--include_dir", dest="include_dir", default=".",
20                     help="specify directory for #includes")
21   parser.add_option("-o", "--output_dir", dest="output_dir", default=".",
22                     help="specify output directory")
23   (options, args) = parser.parse_args()
24
25   if len(args) < 1:
26     parser.print_help()
27     sys.exit(1)
28
29   for filename in args:
30     # TODO(darin): There's clearly too many layers of translation here!  We can
31     # at least avoid generating the serialized Mojom IR.
32     tree = mojo_parser.Parse(filename)
33     mojom = mojo_translate.Translate(tree)
34     module = mojom_data.ModuleFromData(mojom)
35     cpp = mojom_cpp_generator.CPPGenerator(
36         module, options.include_dir, options.output_dir)
37     cpp.GenerateFiles()
38
39
40 if __name__ == '__main__':
41   Main()