convert_rtcd_assembler.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # Copyright 2014 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Script for converting celt_pitch_xcorr_arm.s -> celt_pitch_xcorr_arm.S
  6. # using the arm2gnu.pl script.
  7. from __future__ import print_function
  8. import os
  9. import sys
  10. USAGE = ('Usage:\n'
  11. './convert_rtcd_assembler.py arm2gnu_script input_file output_file')
  12. def main(argv):
  13. if len(argv) != 3:
  14. print('Error: You must pass the following arguments:\n'
  15. ' * arm2gnu_script_path\n'
  16. ' * input_file\n'
  17. ' * output_file', file=sys.stderr)
  18. print(USAGE)
  19. return 1
  20. arm2gnu_script = os.path.abspath(argv[0])
  21. if not os.path.exists(arm2gnu_script):
  22. print('Error: Cannot find arm2gnu.pl script at: %s.' %
  23. arm2gnu_script, file=sys.stderr)
  24. return 2
  25. input_file = os.path.abspath(argv[1])
  26. if not os.path.exists(input_file):
  27. print('Error: Cannot find input file at: %s.' % input_file, file=sys.stderr)
  28. return 3
  29. output_file = argv[2]
  30. # Ensure the output file's directory path exists.
  31. output_dir = os.path.dirname(output_file)
  32. if not os.path.exists(output_dir):
  33. os.makedirs(output_dir)
  34. cmd = ('perl %s %s | '
  35. 'sed "s/OPUS_ARM_MAY_HAVE_[A-Z]*/1/g" | '
  36. 'sed "/.include/d" '
  37. '> %s') % (arm2gnu_script, input_file, output_file)
  38. return os.system(cmd)
  39. if __name__ == '__main__':
  40. sys.exit(main(sys.argv[1:]))