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

Side by Side Diff: tools/lexer_generator/dfa_optimizer.py

Issue 85623003: Experimental parser: enable transition reduction (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | tools/lexer_generator/generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 continue 142 continue
143 # do goto replacement 143 # do goto replacement
144 counters['gotos'] += 1 144 counters['gotos'] += 1
145 match_action = ('goto', name(transition_state)) 145 match_action = ('goto', name(transition_state))
146 new_state['action'] = replacement_action(state.action(), match_action) 146 new_state['action'] = replacement_action(state.action(), match_action)
147 # will need to patch up transition_state 147 # will need to patch up transition_state
148 store_states.add(name(transition_state)) 148 store_states.add(name(transition_state))
149 assert not state_replacements 149 assert not state_replacements
150 self.__dfa.visit_all_states(replace_state) 150 self.__dfa.visit_all_states(replace_state)
151 # now patch up all states with stores 151 # now patch up all states with stores
152 for state in store_states: 152 for state_id in store_states:
153 old_action = states[state]['action'] 153 old_action = states[state_id]['action']
154 match_action = ('do_stored_token', None) 154 match_action = ('do_stored_token', state_id)
155 states[state]['action'] = replacement_action(old_action, match_action) 155 states[state_id]['action'] = replacement_action(old_action, match_action)
156 start_name = name(self.__dfa.start_state()) 156 start_name = name(self.__dfa.start_state())
157 if self.__log: 157 if self.__log:
158 print 'gotos inserted %s' % counters['gotos'] 158 print 'gotos inserted %s' % counters['gotos']
159 print 'transitions removed %s' % counters['removals'] 159 print 'transitions removed %s' % counters['removals']
160 print 'do_stored_token actions added %s' % len(store_states) 160 print 'do_stored_token actions added %s' % len(store_states)
161 self.__dfa = Dfa(self.__dfa.encoding(), start_name, states) 161 self.__dfa = Dfa(self.__dfa.encoding(), start_name, states)
162 162
163 @staticmethod 163 @staticmethod
164 def optimize(dfa, log): 164 def optimize(dfa, log):
165 optimizer = DfaOptimizer(dfa, log) 165 optimizer = DfaOptimizer(dfa, log)
166 optimizer.replace_tokens_with_gotos() 166 optimizer.replace_tokens_with_gotos()
167 return optimizer.__dfa 167 return optimizer.__dfa
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | tools/lexer_generator/generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698