Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: tools/js2c.py

Issue 1094014: Merge the partial_snapshots branch back into bleeding_edge. For... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/x64/stub-cache-x64.cc ('K') | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2006-2008 the V8 project authors. All rights reserved. 3 # Copyright 2006-2008 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 namespace internal { 213 namespace internal {
214 214
215 %(source_lines)s\ 215 %(source_lines)s\
216 216
217 template <> 217 template <>
218 int NativesCollection<%(type)s>::GetBuiltinsCount() { 218 int NativesCollection<%(type)s>::GetBuiltinsCount() {
219 return %(builtin_count)i; 219 return %(builtin_count)i;
220 } 220 }
221 221
222 template <> 222 template <>
223 int NativesCollection<%(type)s>::GetDelayCount() { 223 int NativesCollection<%(type)s>::GetDebuggerCount() {
224 return %(delay_count)i; 224 return %(debugger_count)i;
225 } 225 }
226 226
227 template <> 227 template <>
228 int NativesCollection<%(type)s>::GetIndex(const char* name) { 228 int NativesCollection<%(type)s>::GetIndex(const char* name) {
229 %(get_index_cases)s\ 229 %(get_index_cases)s\
230 return -1; 230 return -1;
231 } 231 }
232 232
233 template <> 233 template <>
234 Vector<const char> NativesCollection<%(type)s>::GetScriptSource(int index) { 234 Vector<const char> NativesCollection<%(type)s>::GetScriptSource(int index) {
(...skipping 10 matching lines...) Expand all
245 } // internal 245 } // internal
246 } // v8 246 } // v8
247 """ 247 """
248 248
249 249
250 SOURCE_DECLARATION = """\ 250 SOURCE_DECLARATION = """\
251 static const char %(id)s[] = { %(data)s }; 251 static const char %(id)s[] = { %(data)s };
252 """ 252 """
253 253
254 254
255 GET_DELAY_INDEX_CASE = """\ 255 GET_DEBUGGER_INDEX_CASE = """\
256 if (strcmp(name, "%(id)s") == 0) return %(i)i; 256 if (strcmp(name, "%(id)s") == 0) return %(i)i;
257 """ 257 """
258 258
259 259
260 GET_DELAY_SCRIPT_SOURCE_CASE = """\ 260 GET_DEBUGGER_SCRIPT_SOURCE_CASE = """\
261 if (index == %(i)i) return Vector<const char>(%(id)s, %(length)i); 261 if (index == %(i)i) return Vector<const char>(%(id)s, %(length)i);
262 """ 262 """
263 263
264 264
265 GET_DELAY_SCRIPT_NAME_CASE = """\ 265 GET_DEBUGGER_SCRIPT_NAME_CASE = """\
266 if (index == %(i)i) return Vector<const char>("%(name)s", %(length)i); 266 if (index == %(i)i) return Vector<const char>("%(name)s", %(length)i);
267 """ 267 """
268 268
269 def JS2C(source, target, env): 269 def JS2C(source, target, env):
270 ids = [] 270 ids = []
271 delay_ids = [] 271 debugger_ids = []
272 modules = [] 272 modules = []
273 # Locate the macros file name. 273 # Locate the macros file name.
274 consts = {} 274 consts = {}
275 macros = {} 275 macros = {}
276 for s in source: 276 for s in source:
277 if 'macros.py' == (os.path.split(str(s))[1]): 277 if 'macros.py' == (os.path.split(str(s))[1]):
278 (consts, macros) = ReadMacros(ReadLines(str(s))) 278 (consts, macros) = ReadMacros(ReadLines(str(s)))
279 else: 279 else:
280 modules.append(s) 280 modules.append(s)
281 281
282 # Build source code lines 282 # Build source code lines
283 source_lines = [ ] 283 source_lines = [ ]
284 284
285 minifier = jsmin.JavaScriptMinifier() 285 minifier = jsmin.JavaScriptMinifier()
286 286
287 source_lines_empty = [] 287 source_lines_empty = []
288 for module in modules: 288 for module in modules:
289 filename = str(module) 289 filename = str(module)
290 delay = filename.endswith('-delay.js') 290 debugger = filename.endswith('-debugger.js')
291 lines = ReadFile(filename) 291 lines = ReadFile(filename)
292 lines = ExpandConstants(lines, consts) 292 lines = ExpandConstants(lines, consts)
293 lines = ExpandMacros(lines, macros) 293 lines = ExpandMacros(lines, macros)
294 Validate(lines, filename) 294 Validate(lines, filename)
295 lines = minifier.JSMinify(lines) 295 lines = minifier.JSMinify(lines)
296 data = ToCArray(lines) 296 data = ToCArray(lines)
297 id = (os.path.split(filename)[1])[:-3] 297 id = (os.path.split(filename)[1])[:-3]
298 if delay: id = id[:-6] 298 if debugger: id = id[:-9]
299 if delay: 299 if debugger:
300 delay_ids.append((id, len(lines))) 300 debugger_ids.append((id, len(lines)))
301 else: 301 else:
302 ids.append((id, len(lines))) 302 ids.append((id, len(lines)))
303 source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data }) 303 source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
304 source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': data }) 304 source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
305 305
306 # Build delay support functions 306 # Build debugger support functions
307 get_index_cases = [ ] 307 get_index_cases = [ ]
308 get_script_source_cases = [ ] 308 get_script_source_cases = [ ]
309 get_script_name_cases = [ ] 309 get_script_name_cases = [ ]
310 310
311 i = 0 311 i = 0
312 for (id, length) in delay_ids: 312 for (id, length) in debugger_ids:
313 native_name = "native %s.js" % id 313 native_name = "native %s.js" % id
314 get_index_cases.append(GET_DELAY_INDEX_CASE % { 'id': id, 'i': i }) 314 get_index_cases.append(GET_DEBUGGER_INDEX_CASE % { 'id': id, 'i': i })
315 get_script_source_cases.append(GET_DELAY_SCRIPT_SOURCE_CASE % { 315 get_script_source_cases.append(GET_DEBUGGER_SCRIPT_SOURCE_CASE % {
316 'id': id, 316 'id': id,
317 'length': length, 317 'length': length,
318 'i': i 318 'i': i
319 }) 319 })
320 get_script_name_cases.append(GET_DELAY_SCRIPT_NAME_CASE % { 320 get_script_name_cases.append(GET_DEBUGGER_SCRIPT_NAME_CASE % {
321 'name': native_name, 321 'name': native_name,
322 'length': len(native_name), 322 'length': len(native_name),
323 'i': i 323 'i': i
324 }); 324 });
325 i = i + 1 325 i = i + 1
326 326
327 for (id, length) in ids: 327 for (id, length) in ids:
328 native_name = "native %s.js" % id 328 native_name = "native %s.js" % id
329 get_index_cases.append(GET_DELAY_INDEX_CASE % { 'id': id, 'i': i }) 329 get_index_cases.append(GET_DEBUGGER_INDEX_CASE % { 'id': id, 'i': i })
330 get_script_source_cases.append(GET_DELAY_SCRIPT_SOURCE_CASE % { 330 get_script_source_cases.append(GET_DEBUGGER_SCRIPT_SOURCE_CASE % {
331 'id': id, 331 'id': id,
332 'length': length, 332 'length': length,
333 'i': i 333 'i': i
334 }) 334 })
335 get_script_name_cases.append(GET_DELAY_SCRIPT_NAME_CASE % { 335 get_script_name_cases.append(GET_DEBUGGER_SCRIPT_NAME_CASE % {
336 'name': native_name, 336 'name': native_name,
337 'length': len(native_name), 337 'length': len(native_name),
338 'i': i 338 'i': i
339 }); 339 });
340 i = i + 1 340 i = i + 1
341 341
342 # Emit result 342 # Emit result
343 output = open(str(target[0]), "w") 343 output = open(str(target[0]), "w")
344 output.write(HEADER_TEMPLATE % { 344 output.write(HEADER_TEMPLATE % {
345 'builtin_count': len(ids) + len(delay_ids), 345 'builtin_count': len(ids) + len(debugger_ids),
346 'delay_count': len(delay_ids), 346 'debugger_count': len(debugger_ids),
347 'source_lines': "\n".join(source_lines), 347 'source_lines': "\n".join(source_lines),
348 'get_index_cases': "".join(get_index_cases), 348 'get_index_cases': "".join(get_index_cases),
349 'get_script_source_cases': "".join(get_script_source_cases), 349 'get_script_source_cases': "".join(get_script_source_cases),
350 'get_script_name_cases': "".join(get_script_name_cases), 350 'get_script_name_cases': "".join(get_script_name_cases),
351 'type': env['TYPE'] 351 'type': env['TYPE']
352 }) 352 })
353 output.close() 353 output.close()
354 354
355 if len(target) > 1: 355 if len(target) > 1:
356 output = open(str(target[1]), "w") 356 output = open(str(target[1]), "w")
357 output.write(HEADER_TEMPLATE % { 357 output.write(HEADER_TEMPLATE % {
358 'builtin_count': len(ids) + len(delay_ids), 358 'builtin_count': len(ids) + len(debugger_ids),
359 'delay_count': len(delay_ids), 359 'debugger_count': len(debugger_ids),
360 'source_lines': "\n".join(source_lines_empty), 360 'source_lines': "\n".join(source_lines_empty),
361 'get_index_cases': "".join(get_index_cases), 361 'get_index_cases': "".join(get_index_cases),
362 'get_script_source_cases': "".join(get_script_source_cases), 362 'get_script_source_cases': "".join(get_script_source_cases),
363 'get_script_name_cases': "".join(get_script_name_cases), 363 'get_script_name_cases': "".join(get_script_name_cases),
364 'type': env['TYPE'] 364 'type': env['TYPE']
365 }) 365 })
366 output.close() 366 output.close()
367 367
368 def main(): 368 def main():
369 natives = sys.argv[1] 369 natives = sys.argv[1]
370 natives_empty = sys.argv[2] 370 natives_empty = sys.argv[2]
371 type = sys.argv[3] 371 type = sys.argv[3]
372 source_files = sys.argv[4:] 372 source_files = sys.argv[4:]
373 JS2C(source_files, [natives, natives_empty], { 'TYPE': type }) 373 JS2C(source_files, [natives, natives_empty], { 'TYPE': type })
374 374
375 if __name__ == "__main__": 375 if __name__ == "__main__":
376 main() 376 main()
OLDNEW
« src/x64/stub-cache-x64.cc ('K') | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698