• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3# Copyright 2018 the V8 project 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'''
8Converts a given file in clang assembly syntax to a corresponding
9representation in inline assembly. Specifically, this is used to convert
10embedded.S to embedded.cc for Windows clang builds.
11'''
12
13import argparse
14import sys
15
16def 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(b'__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(b'  "%s\\n"\n' % line.rstrip().encode('utf8'))
23    outfile.write(b');\n')
24  return 0
25
26if __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))
32