[cfe-commits] r45809 - in /cfe/trunk/utils: ./ ccc
Seo Sanghyeon
sanxiyn at gmail.com
Wed Jan 9 17:43:47 PST 2008
Author: sanxiyn
Date: Wed Jan 9 19:43:47 2008
New Revision: 45809
URL: http://llvm.org/viewvc/llvm-project?rev=45809&view=rev
Log:
Compiler driver
Added:
cfe/trunk/utils/
cfe/trunk/utils/ccc (with props)
Added: cfe/trunk/utils/ccc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/ccc?rev=45809&view=auto
==============================================================================
--- cfe/trunk/utils/ccc (added)
+++ cfe/trunk/utils/ccc Wed Jan 9 19:43:47 2008
@@ -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:])
Propchange: cfe/trunk/utils/ccc
------------------------------------------------------------------------------
svn:executable = *
More information about the cfe-commits
mailing list