[cfe-commits] r66881 - in /cfe/trunk: include/clang/Driver/Types.h lib/Driver/Types.cpp

Daniel Dunbar daniel at zuster.org
Fri Mar 13 04:28:31 PDT 2009


Author: ddunbar
Date: Fri Mar 13 06:28:30 2009
New Revision: 66881

URL: http://llvm.org/viewvc/llvm-project?rev=66881&view=rev
Log:
Driver: Add types::getNumCompilationPhases, getCompilationPhase to
provide information about what steps should be done for a particular
file type.

Modified:
    cfe/trunk/include/clang/Driver/Types.h
    cfe/trunk/lib/Driver/Types.cpp

Modified: cfe/trunk/include/clang/Driver/Types.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.h?rev=66881&r1=66880&r2=66881&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Types.h (original)
+++ cfe/trunk/include/clang/Driver/Types.h Fri Mar 13 06:28:30 2009
@@ -10,6 +10,8 @@
 #ifndef CLANG_DRIVER_TYPES_H_
 #define CLANG_DRIVER_TYPES_H_
 
+#include "clang/Driver/Phases.h"
+
 namespace clang {
 namespace driver {
 namespace types {
@@ -62,6 +64,14 @@
   /// specified type name.
   ID lookupTypeForTypeSpecifier(const char *Name);
 
+  /// getNumCompilationPhases - Return the complete number of phases
+  /// to be done for this type.
+  unsigned getNumCompilationPhases(ID Id);
+
+  /// getCompilationPhase - Return the \args N th compilation phase to
+  /// be done for this type.
+  phases::ID getCompilationPhase(ID Id, unsigned N);
+
 } // end namespace types
 } // end namespace driver
 } // end namespace clang

Modified: cfe/trunk/lib/Driver/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Types.cpp?rev=66881&r1=66880&r2=66881&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Types.cpp (original)
+++ cfe/trunk/lib/Driver/Types.cpp Fri Mar 13 06:28:30 2009
@@ -128,3 +128,47 @@
 
   return TY_INVALID;
 }
+
+// FIXME: Why don't we just put this list in the defs file, eh.
+
+unsigned types::getNumCompilationPhases(ID Id) {  
+  if (Id == TY_Object)
+    return 1;
+    
+  unsigned N = 0;
+  if (getPreprocessedType(Id) != TY_INVALID)
+    N += 1;
+  
+  if (onlyAssembleType(Id))
+    return N + 2; // assemble, link
+  if (onlyPrecompileType(Id))
+    return N + 1; // precompile
+  
+  return N + 3; // compile, assemble, link
+}
+
+phases::ID types::getCompilationPhase(ID Id, unsigned N) {
+  assert(N < getNumCompilationPhases(Id) && "Invalid index.");
+  
+  if (Id == TY_Object)
+    return phases::Link;
+
+  if (getPreprocessedType(Id) != TY_INVALID) {
+    if (N == 0)
+      return phases::Preprocess;
+    --N;
+  }
+
+  if (onlyAssembleType(Id))
+    return N == 0 ? phases::Assemble : phases::Link;
+
+  if (onlyPrecompileType(Id))
+    return phases::Precompile;
+
+  if (N == 0)
+    return phases::Compile;
+  if (N == 1)
+    return phases::Assemble;
+  
+  return phases::Link;
+}





More information about the cfe-commits mailing list