From 77133e6d3078d890a1471dc69b0ffff47d74a4f9 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Thu, 10 Jan 2008 01:43:47 +0000 Subject: [PATCH] Compiler driver llvm-svn: 45809 --- clang/utils/ccc | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 clang/utils/ccc diff --git a/clang/utils/ccc b/clang/utils/ccc new file mode 100755 index 000000000000..083fd93d1a66 --- /dev/null +++ b/clang/utils/ccc @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +# +# This script attempts to be a drop-in replacement for gcc. +# +##===----------------------------------------------------------------------===## + +import sys +import subprocess + +def error(message): + print 'ccc: ' + message + sys.exit(1) + +def run(args): + print ' '.join(args) + code = subprocess.call(args) + if code: + sys.exit(code) + +def preprocess(args): + command = 'clang -E'.split() + run(command + args) + +def compile(args): + command = 'clang -emit-llvm-bc'.split() + run(command + args) + +def link(args): + command = 'llvm-ld -native'.split() + run(command + args) + +def main(args): + action = 'link' + output = '' + compile_opts = ['-U__GNUC__'] + link_opts = [] + files = [] + + i = 0 + while i < len(args): + arg = args[i] + if arg == '-E': + action = 'preprocess' + if arg == '-c': + action = 'compile' + if arg == '-o': + output = args[i+1] + i += 1 + if arg[:2] in ['-D', '-I', '-U']: + if not arg[2:]: + arg += args[i+1] + i += 1 + compile_opts.append(arg) + if arg[:2] in ['-l', '-L', '-O']: + if arg == '-O': arg = '-O1' + if arg == '-Os': arg = '-O2' + link_opts.append(arg) + if arg[0] != '-': + files.append(arg) + i += 1 + + if not files: + error('no input files') + + if action == 'preprocess': + args = compile_opts + files + preprocess(args) + + if action == 'compile': + if not output: + output = files[0].replace('.c', '.o') + args = ['-o', output] + compile_opts + files + compile(args) + + if action == 'link': + for i, file in enumerate(files): + if '.c' in file: + out = file.replace('.c', '.o') + args = ['-o', out] + compile_opts + [file] + compile(args) + files[i] = out + if not output: + output = 'a.out' + args = ['-o', output] + link_opts + files + link(args) + +if __name__ == '__main__': + main(sys.argv[1:])