Add -fobjc-gc and -fobjc-gc-only options to the driver.

Add corresponding enum in LangOptions.

llvm-svn: 50387
This commit is contained in:
Ted Kremenek 2008-04-29 04:37:03 +00:00
parent f9a49c4322
commit d796c18d7b
3 changed files with 40 additions and 7 deletions

View File

@ -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);

View File

@ -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;

View File

@ -31,6 +31,7 @@ void LangOptions::Emit(llvm::Serializer& S) const {
S.EmitBool((bool) CXXOperatorNames);
S.EmitBool((bool) ObjC1);
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;