| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 #include "src/v8.h" | 249 #include "src/v8.h" |
| 250 #include "src/natives.h" | 250 #include "src/natives.h" |
| 251 #include "src/utils.h" | 251 #include "src/utils.h" |
| 252 | 252 |
| 253 namespace v8 { | 253 namespace v8 { |
| 254 namespace internal { | 254 namespace internal { |
| 255 | 255 |
| 256 %(sources_declaration)s\ | 256 %(sources_declaration)s\ |
| 257 | 257 |
| 258 %(raw_sources_declaration)s\ | |
| 259 | |
| 260 template <> | 258 template <> |
| 261 int NativesCollection<%(type)s>::GetBuiltinsCount() { | 259 int NativesCollection<%(type)s>::GetBuiltinsCount() { |
| 262 return %(builtin_count)i; | 260 return %(builtin_count)i; |
| 263 } | 261 } |
| 264 | 262 |
| 265 template <> | 263 template <> |
| 266 int NativesCollection<%(type)s>::GetDebuggerCount() { | 264 int NativesCollection<%(type)s>::GetDebuggerCount() { |
| 267 return %(debugger_count)i; | 265 return %(debugger_count)i; |
| 268 } | 266 } |
| 269 | 267 |
| 270 template <> | 268 template <> |
| 271 int NativesCollection<%(type)s>::GetIndex(const char* name) { | 269 int NativesCollection<%(type)s>::GetIndex(const char* name) { |
| 272 %(get_index_cases)s\ | 270 %(get_index_cases)s\ |
| 273 return -1; | 271 return -1; |
| 274 } | 272 } |
| 275 | 273 |
| 276 template <> | 274 template <> |
| 277 int NativesCollection<%(type)s>::GetRawScriptsSize() { | 275 Vector<const char> NativesCollection<%(type)s>::GetScriptSource(int index) { |
| 278 return %(raw_total_length)i; | 276 %(get_script_source_cases)s\ |
| 279 } | |
| 280 | |
| 281 template <> | |
| 282 Vector<const char> NativesCollection<%(type)s>::GetRawScriptSource(int index)
{ | |
| 283 %(get_raw_script_source_cases)s\ | |
| 284 return Vector<const char>("", 0); | 277 return Vector<const char>("", 0); |
| 285 } | 278 } |
| 286 | 279 |
| 287 template <> | 280 template <> |
| 288 Vector<const char> NativesCollection<%(type)s>::GetScriptName(int index) { | 281 Vector<const char> NativesCollection<%(type)s>::GetScriptName(int index) { |
| 289 %(get_script_name_cases)s\ | 282 %(get_script_name_cases)s\ |
| 290 return Vector<const char>("", 0); | 283 return Vector<const char>("", 0); |
| 291 } | 284 } |
| 292 | 285 |
| 293 template <> | 286 template <> |
| 294 Vector<const byte> NativesCollection<%(type)s>::GetScriptsSource() { | 287 Vector<const char> NativesCollection<%(type)s>::GetScriptsSource() { |
| 295 return Vector<const byte>(sources, %(total_length)i); | 288 return Vector<const char>(sources, %(total_length)i); |
| 296 } | 289 } |
| 297 | |
| 298 template <> | |
| 299 void NativesCollection<%(type)s>::SetRawScriptsSource(Vector<const char> raw_s
ource) { | |
| 300 DCHECK(%(raw_total_length)i == raw_source.length()); | |
| 301 raw_sources = raw_source.start(); | |
| 302 } | |
| 303 | |
| 304 } // internal | 290 } // internal |
| 305 } // v8 | 291 } // v8 |
| 306 """ | 292 """ |
| 307 | 293 |
| 308 SOURCES_DECLARATION = """\ | 294 SOURCES_DECLARATION = """\ |
| 309 static const byte sources[] = { %s }; | 295 static const char sources[] = { %s }; |
| 310 """ | 296 """ |
| 311 | 297 |
| 312 | 298 |
| 313 RAW_SOURCES_COMPRESSION_DECLARATION = """\ | |
| 314 static const char* raw_sources = NULL; | |
| 315 """ | |
| 316 | |
| 317 | |
| 318 RAW_SOURCES_DECLARATION = """\ | |
| 319 static const char* raw_sources = reinterpret_cast<const char*>(sources); | |
| 320 """ | |
| 321 | |
| 322 | |
| 323 GET_INDEX_CASE = """\ | 299 GET_INDEX_CASE = """\ |
| 324 if (strcmp(name, "%(id)s") == 0) return %(i)i; | 300 if (strcmp(name, "%(id)s") == 0) return %(i)i; |
| 325 """ | 301 """ |
| 326 | 302 |
| 327 | 303 |
| 328 GET_RAW_SCRIPT_SOURCE_CASE = """\ | 304 GET_SCRIPT_SOURCE_CASE = """\ |
| 329 if (index == %(i)i) return Vector<const char>(raw_sources + %(offset)i, %(ra
w_length)i); | 305 if (index == %(i)i) return Vector<const char>(sources + %(offset)i, %(source
_length)i); |
| 330 """ | 306 """ |
| 331 | 307 |
| 332 | 308 |
| 333 GET_SCRIPT_NAME_CASE = """\ | 309 GET_SCRIPT_NAME_CASE = """\ |
| 334 if (index == %(i)i) return Vector<const char>("%(name)s", %(length)i); | 310 if (index == %(i)i) return Vector<const char>("%(name)s", %(length)i); |
| 335 """ | 311 """ |
| 336 | 312 |
| 337 | 313 |
| 338 def BuildFilterChain(macro_filename): | 314 def BuildFilterChain(macro_filename): |
| 339 """Build the chain of filter functions to be applied to the sources. | 315 """Build the chain of filter functions to be applied to the sources. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 """ | 409 """ |
| 434 total_length = len(source_bytes) | 410 total_length = len(source_bytes) |
| 435 raw_sources = "".join(sources.modules) | 411 raw_sources = "".join(sources.modules) |
| 436 | 412 |
| 437 # The sources are expected to be ASCII-only. | 413 # The sources are expected to be ASCII-only. |
| 438 assert not filter(lambda value: ord(value) >= 128, raw_sources) | 414 assert not filter(lambda value: ord(value) >= 128, raw_sources) |
| 439 | 415 |
| 440 # Loop over modules and build up indices into the source blob: | 416 # Loop over modules and build up indices into the source blob: |
| 441 get_index_cases = [] | 417 get_index_cases = [] |
| 442 get_script_name_cases = [] | 418 get_script_name_cases = [] |
| 443 get_raw_script_source_cases = [] | 419 get_script_source_cases = [] |
| 444 offset = 0 | 420 offset = 0 |
| 445 for i in xrange(len(sources.modules)): | 421 for i in xrange(len(sources.modules)): |
| 446 native_name = "native %s.js" % sources.names[i] | 422 native_name = "native %s.js" % sources.names[i] |
| 447 d = { | 423 d = { |
| 448 "i": i, | 424 "i": i, |
| 449 "id": sources.names[i], | 425 "id": sources.names[i], |
| 450 "name": native_name, | 426 "name": native_name, |
| 451 "length": len(native_name), | 427 "length": len(native_name), |
| 452 "offset": offset, | 428 "offset": offset, |
| 453 "raw_length": len(sources.modules[i]), | 429 "source_length": len(sources.modules[i]), |
| 454 } | 430 } |
| 455 get_index_cases.append(GET_INDEX_CASE % d) | 431 get_index_cases.append(GET_INDEX_CASE % d) |
| 456 get_script_name_cases.append(GET_SCRIPT_NAME_CASE % d) | 432 get_script_name_cases.append(GET_SCRIPT_NAME_CASE % d) |
| 457 get_raw_script_source_cases.append(GET_RAW_SCRIPT_SOURCE_CASE % d) | 433 get_script_source_cases.append(GET_SCRIPT_SOURCE_CASE % d) |
| 458 offset += len(sources.modules[i]) | 434 offset += len(sources.modules[i]) |
| 459 assert offset == len(raw_sources) | 435 assert offset == len(raw_sources) |
| 460 | 436 |
| 461 # If we have the raw sources we can declare them accordingly. | |
| 462 have_raw_sources = source_bytes == raw_sources | |
| 463 raw_sources_declaration = (RAW_SOURCES_DECLARATION | |
| 464 if have_raw_sources else RAW_SOURCES_COMPRESSION_DECLARATION) | |
| 465 | |
| 466 metadata = { | 437 metadata = { |
| 467 "builtin_count": len(sources.modules), | 438 "builtin_count": len(sources.modules), |
| 468 "debugger_count": sum(sources.is_debugger_id), | 439 "debugger_count": sum(sources.is_debugger_id), |
| 469 "sources_declaration": SOURCES_DECLARATION % ToCArray(source_bytes), | 440 "sources_declaration": SOURCES_DECLARATION % ToCArray(source_bytes), |
| 470 "raw_sources_declaration": raw_sources_declaration, | |
| 471 "raw_total_length": sum(map(len, sources.modules)), | |
| 472 "total_length": total_length, | 441 "total_length": total_length, |
| 473 "get_index_cases": "".join(get_index_cases), | 442 "get_index_cases": "".join(get_index_cases), |
| 474 "get_raw_script_source_cases": "".join(get_raw_script_source_cases), | 443 "get_script_source_cases": "".join(get_script_source_cases), |
| 475 "get_script_name_cases": "".join(get_script_name_cases), | 444 "get_script_name_cases": "".join(get_script_name_cases), |
| 476 "type": native_type, | 445 "type": native_type, |
| 477 } | 446 } |
| 478 return metadata | 447 return metadata |
| 479 | 448 |
| 480 | 449 |
| 481 def PutInt(blob_file, value): | 450 def PutInt(blob_file, value): |
| 482 assert(value >= 0 and value < (1 << 28)) | 451 assert(value >= 0 and value < (1 << 28)) |
| 483 if (value < 1 << 6): | 452 if (value < 1 << 6): |
| 484 size = 1 | 453 size = 1 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 out.cc: C code to be generated. | 525 out.cc: C code to be generated. |
| 557 type: type parameter for NativesCollection template. | 526 type: type parameter for NativesCollection template. |
| 558 sources.js: JS internal sources or macros.py.""") | 527 sources.js: JS internal sources or macros.py.""") |
| 559 (options, args) = parser.parse_args() | 528 (options, args) = parser.parse_args() |
| 560 | 529 |
| 561 JS2C(args[2:], args[0], args[1], options.raw, options.startup_blob) | 530 JS2C(args[2:], args[0], args[1], options.raw, options.startup_blob) |
| 562 | 531 |
| 563 | 532 |
| 564 if __name__ == "__main__": | 533 if __name__ == "__main__": |
| 565 main() | 534 main() |
| OLD | NEW |