| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 print t | 91 print t |
| 92 | 92 |
| 93 if __name__ == '__main__': | 93 if __name__ == '__main__': |
| 94 | 94 |
| 95 parser = argparse.ArgumentParser() | 95 parser = argparse.ArgumentParser() |
| 96 parser.add_argument('--html') | 96 parser.add_argument('--html') |
| 97 parser.add_argument('--re', default='src/lexer/lexer_py.re') | 97 parser.add_argument('--re', default='src/lexer/lexer_py.re') |
| 98 parser.add_argument('--input') | 98 parser.add_argument('--input') |
| 99 parser.add_argument('--code') | 99 parser.add_argument('--code') |
| 100 parser.add_argument('--encoding', default='latin1') | 100 parser.add_argument('--encoding', default='latin1') |
| 101 parser.add_argument('--optimize-default', action='store_true') | 101 parser.add_argument('--no-optimize-default', action='store_true') |
| 102 parser.add_argument('--no-minimize-default', action='store_true') | 102 parser.add_argument('--no-minimize-default', action='store_true') |
| 103 parser.add_argument('--no-verify-default', action='store_true') | 103 parser.add_argument('--no-verify-default', action='store_true') |
| 104 parser.add_argument('--no-inline', action='store_true') | 104 parser.add_argument('--no-inline', action='store_true') |
| 105 parser.add_argument('--verbose', action='store_true') | 105 parser.add_argument('--verbose', action='store_true') |
| 106 parser.add_argument('--debug-code', action='store_true') | 106 parser.add_argument('--debug-code', action='store_true') |
| 107 args = parser.parse_args() | 107 args = parser.parse_args() |
| 108 | 108 |
| 109 minimize_default = not args.no_minimize_default | 109 minimize_default = not args.no_minimize_default |
| 110 verbose = args.verbose | 110 verbose = args.verbose |
| 111 | 111 |
| 112 re_file = args.re | 112 re_file = args.re |
| 113 if verbose: | 113 if verbose: |
| 114 print "parsing %s" % re_file | 114 print "parsing %s" % re_file |
| 115 with open(re_file, 'r') as f: | 115 with open(re_file, 'r') as f: |
| 116 rule_processor = RuleProcessor.parse(f.read(), args.encoding) | 116 rule_processor = RuleProcessor.parse(f.read(), args.encoding) |
| 117 | 117 |
| 118 if args.optimize_default: | 118 if not args.no_optimize_default: |
| 119 rule_processor.default_automata().optimize_dfa(log = args.verbose) | 119 rule_processor.default_automata().optimize_dfa(log = args.verbose) |
| 120 | 120 |
| 121 if minimize_default: | 121 if minimize_default: |
| 122 if args.no_verify_default: | 122 if args.no_verify_default: |
| 123 DfaMinimizer.set_verify(False) | 123 DfaMinimizer.set_verify(False) |
| 124 dfa = rule_processor.default_automata().dfa() | 124 dfa = rule_processor.default_automata().dfa() |
| 125 mdfa = rule_processor.default_automata().minimal_dfa() | 125 mdfa = rule_processor.default_automata().minimal_dfa() |
| 126 if verbose: | 126 if verbose: |
| 127 print "nodes reduced from %s to %s" % ( | 127 print "nodes reduced from %s to %s" % ( |
| 128 dfa.node_count(), mdfa.node_count()) | 128 dfa.node_count(), mdfa.node_count()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 146 code = code_generator.process() | 146 code = code_generator.process() |
| 147 with open(code_file, 'w') as f: | 147 with open(code_file, 'w') as f: |
| 148 f.write(code) | 148 f.write(code) |
| 149 if verbose: | 149 if verbose: |
| 150 print "wrote code to %s" % code_file | 150 print "wrote code to %s" % code_file |
| 151 | 151 |
| 152 input_file = args.input | 152 input_file = args.input |
| 153 if input_file: | 153 if input_file: |
| 154 with open(input_file, 'r') as f: | 154 with open(input_file, 'r') as f: |
| 155 lex(rule_processor, f.read()) | 155 lex(rule_processor, f.read()) |
| OLD | NEW |