| OLD | NEW |
| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 parser.add_argument('--code') | 134 parser.add_argument('--code') |
| 135 parser.add_argument('--encoding', default='latin1') | 135 parser.add_argument('--encoding', default='latin1') |
| 136 parser.add_argument('--no-optimize-default', action='store_true') | 136 parser.add_argument('--no-optimize-default', action='store_true') |
| 137 parser.add_argument('--no-minimize-default', action='store_true') | 137 parser.add_argument('--no-minimize-default', action='store_true') |
| 138 parser.add_argument('--no-verify-default', action='store_true') | 138 parser.add_argument('--no-verify-default', action='store_true') |
| 139 parser.add_argument('--no-inline', action='store_true') | 139 parser.add_argument('--no-inline', action='store_true') |
| 140 parser.add_argument('--verbose', action='store_true') | 140 parser.add_argument('--verbose', action='store_true') |
| 141 parser.add_argument('--debug-code', action='store_true') | 141 parser.add_argument('--debug-code', action='store_true') |
| 142 parser.add_argument('--profile', action='store_true') | 142 parser.add_argument('--profile', action='store_true') |
| 143 parser.add_argument('--rule-html') | 143 parser.add_argument('--rule-html') |
| 144 parser.add_argument('--count-paths', action='store_true') |
| 144 args = parser.parse_args() | 145 args = parser.parse_args() |
| 145 | 146 |
| 146 minimize_default = not args.no_minimize_default | 147 minimize_default = not args.no_minimize_default |
| 147 verbose = args.verbose | 148 verbose = args.verbose |
| 148 | 149 |
| 149 if args.profile: | 150 if args.profile: |
| 150 profiler = start_profiling() | 151 profiler = start_profiling() |
| 151 | 152 |
| 152 re_file = args.re | 153 re_file = args.re |
| 153 if verbose: | 154 if verbose: |
| 154 print "parsing %s" % re_file | 155 print "parsing %s" % re_file |
| 155 with open(re_file, 'r') as f: | 156 with open(re_file, 'r') as f: |
| 156 rule_processor = RuleProcessor(f.read(), args.encoding) | 157 rule_processor = RuleProcessor(f.read(), args.encoding) |
| 157 | 158 |
| 158 if not args.no_optimize_default: | 159 if not args.no_optimize_default: |
| 159 rule_processor.default_automata().optimize_dfa(log = args.verbose) | 160 rule_processor.default_automata().optimize_dfa(log = args.verbose) |
| 160 | 161 |
| 161 if minimize_default: | 162 if minimize_default: |
| 162 if args.no_verify_default: | 163 if args.no_verify_default: |
| 163 DfaMinimizer.set_verify(False) | 164 DfaMinimizer.set_verify(False) |
| 164 dfa = rule_processor.default_automata().dfa() | 165 dfa = rule_processor.default_automata().dfa() |
| 165 mdfa = rule_processor.default_automata().minimal_dfa() | 166 mdfa = rule_processor.default_automata().minimal_dfa() |
| 166 if verbose: | 167 if verbose: |
| 167 print "nodes reduced from %s to %s" % ( | 168 print "nodes reduced from %s to %s" % ( |
| 168 dfa.node_count(), mdfa.node_count()) | 169 dfa.node_count(), mdfa.node_count()) |
| 169 DfaMinimizer.set_verify(True) | 170 DfaMinimizer.set_verify(True) |
| 170 | 171 |
| 172 if args.count_paths: |
| 173 path_count = 0 |
| 174 print 'counting' |
| 175 for path in rule_processor.default_automata().minimal_dfa().path_iter(): |
| 176 path_count += 1 |
| 177 print 'done', path_count |
| 178 |
| 171 html_file = args.html | 179 html_file = args.html |
| 172 if html_file: | 180 if html_file: |
| 173 html = generate_html( | 181 html = generate_html( |
| 174 rule_processor, minimize_default, not args.no_merge_html) | 182 rule_processor, minimize_default, not args.no_merge_html) |
| 175 with open(args.html, 'w') as f: | 183 with open(args.html, 'w') as f: |
| 176 f.write(html) | 184 f.write(html) |
| 177 if verbose: | 185 if verbose: |
| 178 print "wrote html to %s" % html_file | 186 print "wrote html to %s" % html_file |
| 179 | 187 |
| 180 rule_html_file = args.rule_html | 188 rule_html_file = args.rule_html |
| (...skipping 17 matching lines...) Expand all Loading... |
| 198 if verbose: | 206 if verbose: |
| 199 print "wrote code to %s" % code_file | 207 print "wrote code to %s" % code_file |
| 200 | 208 |
| 201 input_file = args.input | 209 input_file = args.input |
| 202 if input_file: | 210 if input_file: |
| 203 with open(input_file, 'r') as f: | 211 with open(input_file, 'r') as f: |
| 204 lex(rule_processor, f.read()) | 212 lex(rule_processor, f.read()) |
| 205 | 213 |
| 206 if args.profile: | 214 if args.profile: |
| 207 stop_profiling(profiler) | 215 stop_profiling(profiler) |
| OLD | NEW |