Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / utils / cat_files.py
blob77127cb98c8a86049a9c7a41a895f4b833956927
1 #!/usr/bin/env python
2 # ===----------------------------------------------------------------------===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # ===----------------------------------------------------------------------===##
10 from argparse import ArgumentParser
11 import sys
14 def print_and_exit(msg):
15 sys.stderr.write(msg + "\n")
16 sys.exit(1)
19 def main():
20 parser = ArgumentParser(description="Concatenate two files into a single file")
21 parser.add_argument(
22 "-o",
23 "--output",
24 dest="output",
25 required=True,
26 help="The output file. stdout is used if not given",
27 type=str,
28 action="store",
30 parser.add_argument(
31 "files", metavar="files", nargs="+", help="The files to concatenate"
34 args = parser.parse_args()
36 if len(args.files) < 2:
37 print_and_exit("fewer than 2 inputs provided")
38 data = ""
39 for filename in args.files:
40 with open(filename, "r") as f:
41 data += f.read()
42 if len(data) != 0 and data[-1] != "\n":
43 data += "\n"
44 assert len(data) > 0 and "cannot cat empty files"
45 with open(args.output, "w") as f:
46 f.write(data)
49 if __name__ == "__main__":
50 main()
51 sys.exit(0)