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 be
5# found in the LICENSE file.
6# Copyright 2012, Google Inc.
7#
8
9"""Decoder Generator script.
10
11Usage: generate-decoder.py <table-file> <output-cc-file>
12"""
13
14# TODO(petarj): This was copied from the old ARM decoder tablegen.
15# Once the changes on that tablegen are stable, this will be rewritten to use
16# the new tablegen.
17
18from __future__ import print_function
19
20import sys
21import dgen_input
22import dgen_output
23
24def main(argv):
25  table_filename, output_filename = argv[1], argv[2]
26
27  print("Decoder Generator reading ", table_filename)
28  f = open(table_filename, 'r')
29  tables = dgen_input.parse_tables(f)
30  f.close()
31
32  print("Successful - got %d tables." % len(tables))
33
34  print("Generating output to %s..." % output_filename)
35  f = open(output_filename, 'w')
36  dgen_output.generate_decoder(tables, dgen_output.COutput(f))
37  f.close()
38  print("Completed.")
39
40  return 0
41
42
43if __name__ == '__main__':
44  sys.exit(main(sys.argv))
45