aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-29 04:37:03 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-29 04:37:03 +0000
commit01d9dbf4ae627e2ba42fc23485789a33fa296516 (patch)
tree12276e949a344ec33f1a1712bf5a497ba0496eaa
parent274f4334f6dd35239e5c3d4b86198f7f5804b059 (diff)
Add -fobjc-gc and -fobjc-gc-only options to the driver.
Add corresponding enum in LangOptions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50387 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/clang.cpp21
-rw-r--r--include/clang/Basic/LangOptions.h22
-rw-r--r--lib/Basic/LangOptions.cpp4
3 files changed, 40 insertions, 7 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index f077952ea2..0b9841687b 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -283,7 +283,7 @@ static void InitializeLangOptions(LangOptions &Options, LangKind LK) {
NoPreprocess = true;
// FALLTHROUGH
case langkind_objc:
- Options.ObjC1 = Options.ObjC2 = 1;
+ Options.ObjC1 = Options.ObjC2 = 1;
break;
case langkind_objcxx_cpp:
NoPreprocess = true;
@@ -358,6 +358,7 @@ LaxVectorConversions("flax-vector-conversions",
llvm::cl::desc("Allow implicit conversions between vectors"
" with a different number of elements or "
"different element types."));
+
// FIXME: add:
// -ansi
// -trigraphs
@@ -425,6 +426,23 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK) {
Options.LaxVectorConversions = LaxVectorConversions;
}
+static llvm::cl::opt<bool>
+ObjCExclusiveGC("fobjc-gc-only",
+ llvm::cl::desc("Use GC exclusively for Objective-C related "
+ "memory management."));
+
+static llvm::cl::opt<bool>
+ObjCEnableGC("fobjc-gc",
+ llvm::cl::desc("Enable Objective-C garbage collection."));
+
+void InitializeGCMode(LangOptions &Options) {
+ if (ObjCExclusiveGC)
+ Options.setGCMode(LangOptions::GCOnly);
+ else if (ObjCEnableGC)
+ Options.setGCMode(LangOptions::HybridGC);
+}
+
+
//===----------------------------------------------------------------------===//
// Our DiagnosticClient implementation
//===----------------------------------------------------------------------===//
@@ -1399,6 +1417,7 @@ int main(int argc, char **argv) {
LangKind LK = GetLanguage(InFile);
InitializeLangOptions(LangInfo, LK);
InitializeLanguageStandard(LangInfo, LK);
+ InitializeGCMode(LangInfo);
// Process the -I options and set them in the HeaderInfo.
HeaderSearch HeaderInfo(FileMgr);
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index 3975c51b9f..589153f47e 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -21,6 +21,7 @@ namespace clang {
/// LangOptions - This class keeps track of the various options that can be
/// enabled, which controls the dialect of C that is accepted.
struct LangOptions {
+
unsigned Trigraphs : 1; // Trigraphs in source files.
unsigned BCPLComment : 1; // BCPL-style '//' comments.
unsigned DollarIdents : 1; // '$' allowed in identifiers.
@@ -34,23 +35,34 @@ struct LangOptions {
unsigned NoExtensions : 1; // All extensions are disabled, strict mode.
unsigned CXXOperatorNames : 1; // Treat C++ operator names as keywords.
- unsigned ObjC1 : 1; // Objective C 1 support enabled.
- unsigned ObjC2 : 1; // Objective C 2 support enabled.
-
+ unsigned ObjC1 : 1; // Objective-C 1 support enabled.
+ unsigned ObjC2 : 1; // Objective-C 2 support enabled.
+
unsigned PascalStrings : 1; // Allow Pascal strings
unsigned Boolean : 1; // Allow bool/true/false
unsigned WritableStrings : 1; // Allow writable strings
unsigned LaxVectorConversions : 1;
-
+
+private:
+ unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
+ // this enum as unsigned because MSVC insists on making enums
+ // signed. Set/Query this value using accessors.
+public:
+
+ enum GCMode { NonGC, GCOnly, HybridGC };
+
LangOptions() {
Trigraphs = BCPLComment = DollarIdents = ImplicitInt = Digraphs = 0;
HexFloats = 0;
- ObjC1 = ObjC2 = 0;
+ GC = ObjC1 = ObjC2 = 0;
C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0;
CXXOperatorNames = PascalStrings = Boolean = WritableStrings = 0;
LaxVectorConversions = 0;
}
+ GCMode getGCMode() const { return (GCMode) GC; }
+ void setGCMode(GCMode m) { GC = (unsigned) m; }
+
/// Emit - Emit this LangOptions object to bitcode.
void Emit(llvm::Serializer& S) const;
diff --git a/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp
index f7fd91fbda..6119afc790 100644
--- a/lib/Basic/LangOptions.cpp
+++ b/lib/Basic/LangOptions.cpp
@@ -30,7 +30,8 @@ void LangOptions::Emit(llvm::Serializer& S) const {
S.EmitBool((bool) NoExtensions);
S.EmitBool((bool) CXXOperatorNames);
S.EmitBool((bool) ObjC1);
- S.EmitBool((bool) ObjC2);
+ S.EmitBool((bool) ObjC2);
+ S.EmitBool((unsigned) GC);
S.EmitBool((bool) PascalStrings);
S.EmitBool((bool) Boolean);
S.EmitBool((bool) WritableStrings);
@@ -51,6 +52,7 @@ void LangOptions::Read(llvm::Deserializer& D) {
CXXOperatorNames = D.ReadBool() ? 1 : 0;
ObjC1 = D.ReadBool() ? 1 : 0;
ObjC2 = D.ReadBool() ? 1 : 0;
+ GC = D.ReadInt();
PascalStrings = D.ReadBool() ? 1 : 0;
Boolean = D.ReadBool() ? 1 : 0;
WritableStrings = D.ReadBool() ? 1 : 0;