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

Side by Side Diff: src/trusted/validator_arm/generate_decoder.py

Issue 10191011: Moving dgen_ scripts out of validator_arm into a common directory. (Closed)
Patch Set: Updates per code review. Created 8 years, 8 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
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright 2012 The Native Client Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can
5 # be found in the LICENSE file.
6 #
7
8 """Decoder Generator script.
9
10 Usage: generate-decoder.py <table-file> <output-cc-file> <decoder-name>
11
12 Note: If the file ends with named.{h,cc}, it is assumed that one should
13 build the corresponding source file for named classes, so that testing
14 is easier to perform. In either case, the .h file will declare a decoder
15 state (with the given decoder name) to decode instructions, while the
16 .cc file will define the methods for the declared decoder state.
17 """
18
19 import re
20 import sys
21 import dgen_input
22 import dgen_decoder_output
23 import dgen_test_output
24
25 def _localize_filename(filename):
26 """ Strips off directories above 'native_client', returning
27 a location neutral name for the file
28 """
29 m = re.match(r'.*/(native_client/.*)', filename)
30 if m:
31 return m.group(1)
32 else:
33 # Don't know localized
34 return filename
35
36 def main(argv):
37 table_filename = argv[1]
38 output_filename = argv[2]
39 decoder_name = argv[3]
40
41 print "Decoder Generator reading ", table_filename
42 f = open(table_filename, 'r')
43 decoder = dgen_input.parse_tables(f)
44 f.close()
45
46 print "Successful - got %d tables." % len(decoder.tables())
47
48 print "Generating %s..." % output_filename
49 f = open(output_filename, 'w')
50
51 if output_filename.endswith('tests.cc'):
52 dgen_test_output.generate_tests_cc(decoder,
53 decoder_name,
54 f)
55 elif output_filename.endswith('named_classes.h'):
56 dgen_test_output.generate_named_classes_h(
57 decoder, decoder_name, _localize_filename(output_filename),
58 f)
59 elif output_filename.endswith('named_decoder.h'):
60 dgen_test_output.generate_named_decoder_h(
61 decoder, decoder_name, _localize_filename(output_filename), f)
62 elif output_filename.endswith('.h'):
63 dgen_decoder_output.generate_h(
64 decoder, decoder_name, _localize_filename(output_filename), f)
65 elif output_filename.endswith('named.cc'):
66 dgen_test_output.generate_named_cc(
67 decoder, decoder_name, _localize_filename(output_filename), f)
68 elif output_filename.endswith('.cc'):
69 dgen_decoder_output.generate_cc(
70 decoder, decoder_name, _localize_filename(output_filename), f)
71 else:
72 print 'Error: output filename not of form "*.{h,cc}"'
73 f.close()
74 print "Completed."
75
76 return 0
77
78 if __name__ == '__main__':
79 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « src/trusted/validator_arm/dgen_test_output.py ('k') | src/trusted/validator_arm/optimize-table.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698