Yang Guo | 2fd941d | 2019-03-05 11:30:15 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2019 The Chromium 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 | |
| 7 | ''' |
| 8 | Converts a given file in clang assembly syntax to a corresponding |
| 9 | representation in inline assembly. Specifically, this is used for |
| 10 | Windows clang builds. |
| 11 | ''' |
| 12 | |
| 13 | import argparse |
| 14 | import sys |
| 15 | |
| 16 | def asm_to_inl_asm(in_filename, out_filename): |
| 17 | with open(in_filename, 'r') as infile, open(out_filename, 'wb') as outfile: |
| 18 | outfile.write('__asm__(\n') |
| 19 | for line in infile: |
| 20 | # Escape " in .S file before outputing it to inline asm file. |
| 21 | line = line.replace('"', '\\"') |
| 22 | outfile.write(' "%s\\n"\n' % line.rstrip()) |
| 23 | outfile.write(');\n') |
| 24 | return 0 |
| 25 | |
| 26 | if __name__ == '__main__': |
| 27 | parser = argparse.ArgumentParser(description=__doc__) |
| 28 | parser.add_argument('input', help='Name of the input assembly file') |
| 29 | parser.add_argument('output', help='Name of the target CC file') |
| 30 | args = parser.parse_args() |
| 31 | sys.exit(asm_to_inl_asm(args.input, args.output)) |