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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 sources_bytes = "".join(sources.modules) | 491 sources_bytes = "".join(sources.modules) |
492 if compression_type == "off": | 492 if compression_type == "off": |
493 return sources_bytes | 493 return sources_bytes |
494 elif compression_type == "bz2": | 494 elif compression_type == "bz2": |
495 return bz2.compress(sources_bytes) | 495 return bz2.compress(sources_bytes) |
496 else: | 496 else: |
497 raise Error("Unknown compression type %s." % compression_type) | 497 raise Error("Unknown compression type %s." % compression_type) |
498 | 498 |
499 | 499 |
500 def PutInt(blob_file, value): | 500 def PutInt(blob_file, value): |
501 assert(value >= 0 and value < (1 << 20)) | 501 assert(value >= 0 and value < (1 << 28)) |
502 size = 1 if (value < 1 << 6) else (2 if (value < 1 << 14) else 3) | 502 if (value < 1 << 6): |
503 value_with_length = (value << 2) | size | 503 size = 1 |
| 504 elif (value < 1 << 14): |
| 505 size = 2 |
| 506 elif (value < 1 << 22): |
| 507 size = 3 |
| 508 else: |
| 509 size = 4 |
| 510 value_with_length = (value << 2) | (size - 1) |
504 | 511 |
505 byte_sequence = bytearray() | 512 byte_sequence = bytearray() |
506 for i in xrange(size): | 513 for i in xrange(size): |
507 byte_sequence.append(value_with_length & 255) | 514 byte_sequence.append(value_with_length & 255) |
508 value_with_length >>= 8; | 515 value_with_length >>= 8; |
509 blob_file.write(byte_sequence) | 516 blob_file.write(byte_sequence) |
510 | 517 |
511 | 518 |
512 def PutStr(blob_file, value): | 519 def PutStr(blob_file, value): |
513 PutInt(blob_file, len(value)); | 520 PutInt(blob_file, len(value)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 type: type parameter for NativesCollection template. | 576 type: type parameter for NativesCollection template. |
570 compression: type of compression used. [off|bz2] | 577 compression: type of compression used. [off|bz2] |
571 sources.js: JS internal sources or macros.py.""") | 578 sources.js: JS internal sources or macros.py.""") |
572 (options, args) = parser.parse_args() | 579 (options, args) = parser.parse_args() |
573 | 580 |
574 JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) | 581 JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob) |
575 | 582 |
576 | 583 |
577 if __name__ == "__main__": | 584 if __name__ == "__main__": |
578 main() | 585 main() |
OLD | NEW |