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

Side by Side Diff: Source/bindings/scripts/blink_idl_parser.py

Issue 184233005: Pre-cache PLY yacc parse table and use optimized mode (45% build time improvement) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reupload Created 6 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
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 def __dir__(self): 395 def __dir__(self):
396 # Remove REMOVED_RULES from listing so yacc doesn't parse them 396 # Remove REMOVED_RULES from listing so yacc doesn't parse them
397 # FIXME: Upstream 397 # FIXME: Upstream
398 keys = set(self.__dict__.keys() + dir(self.__class__)) 398 keys = set(self.__dict__.keys() + dir(self.__class__))
399 for rule in REMOVED_RULES: 399 for rule in REMOVED_RULES:
400 production_name = 'p_' + rule 400 production_name = 'p_' + rule
401 if production_name in keys: 401 if production_name in keys:
402 keys.remove(production_name) 402 keys.remove(production_name)
403 return list(keys) 403 return list(keys)
404 404
405 def __init__(self, lexer=None, verbose=False, debug=False, mute_error=False, outputdir=''): 405 def __init__(self,
406 # common parameters
407 debug=False,
408 # idl_parser parameters
409 lexer=None, verbose=False, mute_error=False,
410 # yacc parameters
411 outputdir='', optimize=True, write_tables=False,
412 picklefile=None):
413 if debug:
414 # Turn off optimization and caching, and write out tables,
415 # to help debugging
416 optimize = False
417 outputdir = None
418 picklefile = None
419 write_tables = True
420 if outputdir:
421 picklefile = picklefile or os.path.join(outputdir, 'parsetab.pickle' )
422
406 lexer = lexer or BlinkIDLLexer() 423 lexer = lexer or BlinkIDLLexer()
407 self.lexer = lexer 424 self.lexer = lexer
408 self.tokens = lexer.KnownTokens() 425 self.tokens = lexer.KnownTokens()
409 # Using SLR (instead of LALR) generates the table faster, 426 # Using SLR (instead of LALR) generates the table faster,
410 # but produces the same output. This is ok b/c Web IDL (and Blink IDL) 427 # but produces the same output. This is ok b/c Web IDL (and Blink IDL)
411 # is an SLR grammar (as is often the case for simple LL(1) grammars). 428 # is an SLR grammar (as is often the case for simple LL(1) grammars).
412 self.yaccobj = yacc.yacc(module=self, start=STARTING_SYMBOL, method='SLR ', debug=debug, outputdir=outputdir) 429 #
430 # Optimized mode substantially decreases startup time (by disabling
431 # error checking), and also allows use of Python's optimized mode.
432 # See: Using Python's Optimized Mode
433 # http://www.dabeaz.com/ply/ply.html#ply_nn38
434 #
435 # |picklefile| allows simpler importing than |tabmodule| (parsetab.py),
436 # as we don't need to modify sys.path; virtually identical speed.
437 # See: CHANGES, Version 3.2
438 # http://ply.googlecode.com/svn/trunk/CHANGES
439 self.yaccobj = yacc.yacc(module=self,
440 start=STARTING_SYMBOL,
441 method='SLR',
442 debug=debug,
443 optimize=optimize,
444 write_tables=write_tables,
445 picklefile=picklefile)
413 self.parse_debug = debug 446 self.parse_debug = debug
414 self.verbose = verbose 447 self.verbose = verbose
415 self.mute_error = mute_error 448 self.mute_error = mute_error
416 self._parse_errors = 0 449 self._parse_errors = 0
417 self._parse_warnings = 0 450 self._parse_warnings = 0
418 self._last_error_msg = None 451 self._last_error_msg = None
419 self._last_error_lineno = 0 452 self._last_error_lineno = 0
420 self._last_error_pos = 0 453 self._last_error_pos = 0
421 454
422 455
423 # If run by itself, attempt to build the parser 456 ################################################################################
457
458 def main(argv):
459 # If file itself executed, cache parse table
460 try:
461 outputdir = argv[1]
462 except IndexError as err:
463 print 'Usage: %s OUTPUT_DIR' % argv[0]
464 return 1
465 parser = BlinkIDLParser(outputdir=outputdir)
466
467
424 if __name__ == '__main__': 468 if __name__ == '__main__':
425 parser = BlinkIDLParser() 469 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698