| OLD | NEW | 
|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # | 2 # | 
| 3 # Copyright 2012 the V8 project authors. All rights reserved. | 3 # Copyright 2012 the V8 project authors. All rights reserved. | 
| 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 14 matching lines...) Expand all  Loading... | 
| 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 # This is a utility for converting JavaScript source code into C-style | 30 # This is a utility for converting JavaScript source code into C-style | 
| 31 # char arrays. It is used for embedded JavaScript code in the V8 | 31 # char arrays. It is used for embedded JavaScript code in the V8 | 
| 32 # library. | 32 # library. | 
| 33 | 33 | 
| 34 import os, re, sys, string | 34 import os, re, sys, string | 
| 35 import argparse | 35 import optparse | 
| 36 import jsmin | 36 import jsmin | 
| 37 import bz2 | 37 import bz2 | 
| 38 import textwrap | 38 import textwrap | 
| 39 | 39 | 
| 40 | 40 | 
| 41 class Error(Exception): | 41 class Error(Exception): | 
| 42   def __init__(self, msg): | 42   def __init__(self, msg): | 
| 43     Exception.__init__(self, msg) | 43     Exception.__init__(self, msg) | 
| 44 | 44 | 
| 45 | 45 | 
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 569   # Emit resulting source file. | 569   # Emit resulting source file. | 
| 570   output = open(target, "w") | 570   output = open(target, "w") | 
| 571   if emit_js: | 571   if emit_js: | 
| 572     output.write(sources_output) | 572     output.write(sources_output) | 
| 573   else: | 573   else: | 
| 574     output.write(HEADER_TEMPLATE % metadata) | 574     output.write(HEADER_TEMPLATE % metadata) | 
| 575   output.close() | 575   output.close() | 
| 576 | 576 | 
| 577 | 577 | 
| 578 def main(): | 578 def main(): | 
| 579   parser = argparse.ArgumentParser() | 579   parser = optparse.OptionParser() | 
| 580   parser.add_argument("out.cc", | 580   parser.add_option("--raw", | 
| 581                       help="output filename") | 581                     help="file to write the processed sources array to.") | 
| 582   parser.add_argument("type", | 582   parser.add_option("--startup_blob", | 
| 583                       help="type parameter for NativesCollection template " + | 583                     help="file to write the startup blob to.") | 
| 584                            "(see NativeType enum)") | 584   parser.add_option("--js", | 
| 585   parser.add_argument("sources.js", | 585                     help="writes a JS file output instead of a C file", | 
| 586                       help="JS internal sources or macros.py.", | 586                     action="store_true") | 
| 587                       nargs="*") | 587   parser.set_usage("""js2c out.cc type sources.js ... | 
| 588   parser.add_argument("--raw", | 588         out.cc: C code to be generated. | 
| 589                       help="file to write the processed sources array to.") | 589         type: type parameter for NativesCollection template. | 
| 590   parser.add_argument("--startup_blob", | 590         sources.js: JS internal sources or macros.py.""") | 
| 591                       help="file to write the startup blob to.") | 591   (options, args) = parser.parse_args() | 
| 592   parser.add_argument("--js", | 592   JS2C(args[2:], | 
| 593                       help="writes a JS file output instead of a C file", | 593        args[0], | 
| 594                       action="store_true") | 594        args[1], | 
| 595 | 595        options.raw, | 
| 596   args = vars(parser.parse_args()) | 596        options.startup_blob, | 
| 597   JS2C(args["sources.js"], args["out.cc"], args["type"], args["raw"], args["star
     tup_blob"], args["js"]) | 597        options.js) | 
| 598 | 598 | 
| 599 | 599 | 
| 600 if __name__ == "__main__": | 600 if __name__ == "__main__": | 
| 601   main() | 601   main() | 
| OLD | NEW | 
|---|