ccc: Bug fix and gcc compatibility tweak.

 - --gstabs only goes to Darwin/Assembler when dealing with an
     assembly file from the command line.

 - Relative placement of -o option for cc1 moves depending on
   -fsyntax-only/-S, how quaint.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62152 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/ccc/ccclib/Tools.py b/tools/ccc/ccclib/Tools.py
index 57c8afc..1140dee 100644
--- a/tools/ccc/ccclib/Tools.py
+++ b/tools/ccc/ccclib/Tools.py
@@ -115,8 +115,10 @@
 
         cmd_args = []
         
-        if arglist.getLastArg(arglist.parser.gGroup):
-            cmd_args.append('--gstabs')
+        # Bit of a hack, this is only used for original inputs.
+        if input.isOriginalInput():
+            if arglist.getLastArg(arglist.parser.gGroup):
+                cmd_args.append('--gstabs')
 
         # Derived from asm spec.
         if arch:
@@ -442,13 +444,20 @@
         #arglist.addLastArg(cmd_args, arglist.parser._helpOption)
         #arglist.addLastArg(cmd_args, arglist.parser._targetHelpOption)
 
+        # There is no need for this level of compatibility, but it
+        # makes diffing easier.
+        outputAtEnd = (not arglist.getLastArg(arglist.parser.syntaxOnlyOption) and
+                       not arglist.getLastArg(arglist.parser.SOption))
         if isinstance(output, Jobs.PipedJob):
-            cmd_args.extend(['-o', '-'])
+            output_args = ['-o', '-']
         elif output is None:
-            cmd_args.extend(['-o', '/dev/null'])
+            output_args = ['-o', '/dev/null']
         else:
-            cmd_args.extend(arglist.render(output))
-  
+            output_args = arglist.render(output)
+
+        if not outputAtEnd:
+            cmd_args.extend(output_args)
+
         # FIXME: Still don't get what is happening here. Investigate.
         arglist.addAllArgs(cmd_args, arglist.parser._paramOption)
 
@@ -461,6 +470,9 @@
             cmd_args.append('-fprofile-arcs')
             cmd_args.append('-ftest-coverage')
 
+        if outputAtEnd:
+            cmd_args.extend(output_args)
+
         jobs.addJob(Jobs.Command(self.toolChain.getProgramPath(cc1Name), 
                                  cmd_args))