]> granicus.if.org Git - clang/commitdiff
Driver: Add types::getNumCompilationPhases, getCompilationPhase to
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Mar 2009 11:28:30 +0000 (11:28 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Mar 2009 11:28:30 +0000 (11:28 +0000)
provide information about what steps should be done for a particular
file type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66881 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Types.h
lib/Driver/Types.cpp

index f9f7601c7cbb40ccc17f8700e74e8183b0b0288d..9d2313c62bcb9957f8e5b304b612f4ebcb0a2c41 100644 (file)
@@ -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 @@ namespace types {
   /// 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
index 88389c9ce3a8b35fd7640aa81468a4b757e58de4..96d76dd4d6067d522e829506b968278b6cb0ad9d 100644 (file)
@@ -128,3 +128,47 @@ types::ID types::lookupTypeForTypeSpecifier(const char *Name) {
 
   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;
+}