[cfe-commits] r86816 - in /cfe/trunk/tools/clang-cc: Options.cpp Options.h clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Tue Nov 10 23:26:13 PST 2009
Author: ddunbar
Date: Wed Nov 11 01:26:12 2009
New Revision: 86816
URL: http://llvm.org/viewvc/llvm-project?rev=86816&view=rev
Log:
clang-cc: Move InitializeLangOptions to Options.cpp.
Also, inline InitializeLanguageStandard into InitializeLangOptions; this code
needs to be refactored but the current division doesn't make any sense.
Modified:
cfe/trunk/tools/clang-cc/Options.cpp
cfe/trunk/tools/clang-cc/Options.h
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/tools/clang-cc/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.cpp?rev=86816&r1=86815&r2=86816&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/Options.cpp (original)
+++ cfe/trunk/tools/clang-cc/Options.cpp Wed Nov 11 01:26:12 2009
@@ -86,6 +86,213 @@
}
//===----------------------------------------------------------------------===//
+// Language Options
+//===----------------------------------------------------------------------===//
+
+namespace langoptions {
+
+static llvm::cl::opt<bool>
+AllowBuiltins("fbuiltin", llvm::cl::init(true),
+ llvm::cl::desc("Disable implicit builtin knowledge of functions"));
+
+static llvm::cl::opt<bool>
+AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
+ llvm::cl::init(false));
+
+static llvm::cl::opt<bool>
+AccessControl("faccess-control",
+ llvm::cl::desc("Enable C++ access control"));
+
+static llvm::cl::opt<bool>
+CharIsSigned("fsigned-char",
+ llvm::cl::desc("Force char to be a signed/unsigned type"));
+
+static llvm::cl::opt<bool>
+DollarsInIdents("fdollars-in-identifiers",
+ llvm::cl::desc("Allow '$' in identifiers"));
+
+static llvm::cl::opt<bool>
+EmitAllDecls("femit-all-decls",
+ llvm::cl::desc("Emit all declarations, even if unused"));
+
+static llvm::cl::opt<bool>
+EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
+
+static llvm::cl::opt<bool>
+EnableHeinousExtensions("fheinous-gnu-extensions",
+ llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
+ llvm::cl::ValueDisallowed, llvm::cl::Hidden);
+
+static llvm::cl::opt<bool>
+Exceptions("fexceptions",
+ llvm::cl::desc("Enable support for exception handling"));
+
+static llvm::cl::opt<bool>
+Freestanding("ffreestanding",
+ llvm::cl::desc("Assert that the compilation takes place in a "
+ "freestanding environment"));
+
+static llvm::cl::opt<bool>
+GNURuntime("fgnu-runtime",
+ llvm::cl::desc("Generate output compatible with the standard GNU "
+ "Objective-C runtime"));
+
+/// LangStds - Language standards we support.
+enum LangStds {
+ lang_unspecified,
+ lang_c89, lang_c94, lang_c99,
+ lang_gnu89, lang_gnu99,
+ lang_cxx98, lang_gnucxx98,
+ lang_cxx0x, lang_gnucxx0x
+};
+static llvm::cl::opt<LangStds>
+LangStd("std", llvm::cl::desc("Language standard to compile for"),
+ llvm::cl::init(lang_unspecified),
+ llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
+ clEnumValN(lang_c89, "c90", "ISO C 1990"),
+ clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
+ clEnumValN(lang_c94, "iso9899:199409",
+ "ISO C 1990 with amendment 1"),
+ clEnumValN(lang_c99, "c99", "ISO C 1999"),
+ clEnumValN(lang_c99, "c9x", "ISO C 1999"),
+ clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
+ clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
+ clEnumValN(lang_gnu89, "gnu89",
+ "ISO C 1990 with GNU extensions"),
+ clEnumValN(lang_gnu99, "gnu99",
+ "ISO C 1999 with GNU extensions (default for C)"),
+ clEnumValN(lang_gnu99, "gnu9x",
+ "ISO C 1999 with GNU extensions"),
+ clEnumValN(lang_cxx98, "c++98",
+ "ISO C++ 1998 with amendments"),
+ clEnumValN(lang_gnucxx98, "gnu++98",
+ "ISO C++ 1998 with amendments and GNU "
+ "extensions (default for C++)"),
+ clEnumValN(lang_cxx0x, "c++0x",
+ "Upcoming ISO C++ 200x with amendments"),
+ clEnumValN(lang_gnucxx0x, "gnu++0x",
+ "Upcoming ISO C++ 200x with amendments and GNU "
+ "extensions"),
+ clEnumValEnd));
+
+static llvm::cl::opt<bool>
+MSExtensions("fms-extensions",
+ llvm::cl::desc("Accept some non-standard constructs used in "
+ "Microsoft header files "));
+
+static llvm::cl::opt<std::string>
+MainFileName("main-file-name",
+ llvm::cl::desc("Main file name to use for debug info"));
+
+static llvm::cl::opt<bool>
+MathErrno("fmath-errno", llvm::cl::init(true),
+ llvm::cl::desc("Require math functions to respect errno"));
+
+static llvm::cl::opt<bool>
+NeXTRuntime("fnext-runtime",
+ llvm::cl::desc("Generate output compatible with the NeXT "
+ "runtime"));
+
+static llvm::cl::opt<bool>
+NoElideConstructors("fno-elide-constructors",
+ llvm::cl::desc("Disable C++ copy constructor elision"));
+
+static llvm::cl::opt<bool>
+NoLaxVectorConversions("fno-lax-vector-conversions",
+ llvm::cl::desc("Disallow implicit conversions between "
+ "vectors with a different number of "
+ "elements or different element types"));
+
+
+static llvm::cl::opt<bool>
+NoOperatorNames("fno-operator-names",
+ llvm::cl::desc("Do not treat C++ operator name keywords as "
+ "synonyms for operators"));
+
+static llvm::cl::opt<std::string>
+ObjCConstantStringClass("fconstant-string-class",
+ llvm::cl::value_desc("class name"),
+ llvm::cl::desc("Specify the class to use for constant "
+ "Objective-C string objects."));
+
+static llvm::cl::opt<bool>
+ObjCEnableGC("fobjc-gc",
+ llvm::cl::desc("Enable Objective-C garbage collection"));
+
+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>
+ObjCEnableGCBitmapPrint("print-ivar-layout",
+ llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
+
+static llvm::cl::opt<bool>
+ObjCNonFragileABI("fobjc-nonfragile-abi",
+ llvm::cl::desc("enable objective-c's nonfragile abi"));
+
+static llvm::cl::opt<bool>
+OverflowChecking("ftrapv",
+ llvm::cl::desc("Trap on integer overflow"),
+ llvm::cl::init(false));
+
+static llvm::cl::opt<unsigned>
+PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
+
+static llvm::cl::opt<bool>
+PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
+ llvm::cl::init(false));
+
+static llvm::cl::opt<bool>
+PascalStrings("fpascal-strings",
+ llvm::cl::desc("Recognize and construct Pascal-style "
+ "string literals"));
+
+// FIXME: Move to CompileOptions.
+static llvm::cl::opt<bool>
+Rtti("frtti", llvm::cl::init(true),
+ llvm::cl::desc("Enable generation of rtti information"));
+
+static llvm::cl::opt<bool>
+ShortWChar("fshort-wchar",
+ llvm::cl::desc("Force wchar_t to be a short unsigned int"));
+
+static llvm::cl::opt<bool>
+StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
+
+static llvm::cl::opt<int>
+StackProtector("stack-protector",
+ llvm::cl::desc("Enable stack protectors"),
+ llvm::cl::init(-1));
+
+static llvm::cl::opt<LangOptions::VisibilityMode>
+SymbolVisibility("fvisibility",
+ llvm::cl::desc("Set the default symbol visibility:"),
+ llvm::cl::init(LangOptions::Default),
+ llvm::cl::values(clEnumValN(LangOptions::Default, "default",
+ "Use default symbol visibility"),
+ clEnumValN(LangOptions::Hidden, "hidden",
+ "Use hidden symbol visibility"),
+ clEnumValN(LangOptions::Protected,"protected",
+ "Use protected symbol visibility"),
+ clEnumValEnd));
+
+static llvm::cl::opt<unsigned>
+TemplateDepth("ftemplate-depth", llvm::cl::init(99),
+ llvm::cl::desc("Maximum depth of recursive template "
+ "instantiation"));
+
+static llvm::cl::opt<bool>
+Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
+
+static llvm::cl::opt<bool>
+WritableStrings("fwritable-strings",
+ llvm::cl::desc("Store string literals as writable data"));
+
+}
+
+//===----------------------------------------------------------------------===//
// General Preprocessor Options
//===----------------------------------------------------------------------===//
@@ -242,3 +449,258 @@
for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
Opts.addInclude(*OrderedPaths[i].second);
}
+
+void clang::InitializeLangOptions(LangOptions &Options, LangKind LK,
+ TargetInfo &Target,
+ const CompileOptions &CompileOpts,
+ const llvm::StringMap<bool> &Features) {
+ using namespace langoptions;
+
+ bool NoPreprocess = false;
+
+ switch (LK) {
+ default: assert(0 && "Unknown language kind!");
+ case langkind_asm_cpp:
+ Options.AsmPreprocessor = 1;
+ // FALLTHROUGH
+ case langkind_c_cpp:
+ NoPreprocess = true;
+ // FALLTHROUGH
+ case langkind_c:
+ // Do nothing.
+ break;
+ case langkind_cxx_cpp:
+ NoPreprocess = true;
+ // FALLTHROUGH
+ case langkind_cxx:
+ Options.CPlusPlus = 1;
+ break;
+ case langkind_objc_cpp:
+ NoPreprocess = true;
+ // FALLTHROUGH
+ case langkind_objc:
+ Options.ObjC1 = Options.ObjC2 = 1;
+ break;
+ case langkind_objcxx_cpp:
+ NoPreprocess = true;
+ // FALLTHROUGH
+ case langkind_objcxx:
+ Options.ObjC1 = Options.ObjC2 = 1;
+ Options.CPlusPlus = 1;
+ break;
+ case langkind_ocl:
+ Options.OpenCL = 1;
+ Options.AltiVec = 1;
+ Options.CXXOperatorNames = 1;
+ Options.LaxVectorConversions = 1;
+ break;
+ }
+
+ if (ObjCExclusiveGC)
+ Options.setGCMode(LangOptions::GCOnly);
+ else if (ObjCEnableGC)
+ Options.setGCMode(LangOptions::HybridGC);
+
+ if (ObjCEnableGCBitmapPrint)
+ Options.ObjCGCBitmapPrint = 1;
+
+ if (AltiVec)
+ Options.AltiVec = 1;
+
+ if (PThread)
+ Options.POSIXThreads = 1;
+
+ Options.setVisibilityMode(SymbolVisibility);
+ Options.OverflowChecking = OverflowChecking;
+
+
+ // Allow the target to set the default the language options as it sees fit.
+ Target.getDefaultLangOptions(Options);
+
+ // Pass the map of target features to the target for validation and
+ // processing.
+ Target.HandleTargetFeatures(Features);
+
+ if (LangStd == lang_unspecified) {
+ // Based on the base language, pick one.
+ switch (LK) {
+ case langkind_ast: assert(0 && "Invalid call for AST inputs");
+ case lang_unspecified: assert(0 && "Unknown base language");
+ case langkind_ocl:
+ LangStd = lang_c99;
+ break;
+ case langkind_c:
+ case langkind_asm_cpp:
+ case langkind_c_cpp:
+ case langkind_objc:
+ case langkind_objc_cpp:
+ LangStd = lang_gnu99;
+ break;
+ case langkind_cxx:
+ case langkind_cxx_cpp:
+ case langkind_objcxx:
+ case langkind_objcxx_cpp:
+ LangStd = lang_gnucxx98;
+ break;
+ }
+ }
+
+ switch (LangStd) {
+ default: assert(0 && "Unknown language standard!");
+
+ // Fall through from newer standards to older ones. This isn't really right.
+ // FIXME: Enable specifically the right features based on the language stds.
+ case lang_gnucxx0x:
+ case lang_cxx0x:
+ Options.CPlusPlus0x = 1;
+ // FALL THROUGH
+ case lang_gnucxx98:
+ case lang_cxx98:
+ Options.CPlusPlus = 1;
+ Options.CXXOperatorNames = !NoOperatorNames;
+ // FALL THROUGH.
+ case lang_gnu99:
+ case lang_c99:
+ Options.C99 = 1;
+ Options.HexFloats = 1;
+ // FALL THROUGH.
+ case lang_gnu89:
+ Options.BCPLComment = 1; // Only for C99/C++.
+ // FALL THROUGH.
+ case lang_c94:
+ Options.Digraphs = 1; // C94, C99, C++.
+ // FALL THROUGH.
+ case lang_c89:
+ break;
+ }
+
+ // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
+ switch (LangStd) {
+ default: assert(0 && "Unknown language standard!");
+ case lang_gnucxx0x:
+ case lang_gnucxx98:
+ case lang_gnu99:
+ case lang_gnu89:
+ Options.GNUMode = 1;
+ break;
+ case lang_cxx0x:
+ case lang_cxx98:
+ case lang_c99:
+ case lang_c94:
+ case lang_c89:
+ Options.GNUMode = 0;
+ break;
+ }
+
+ if (Options.CPlusPlus) {
+ Options.C99 = 0;
+ Options.HexFloats = 0;
+ }
+
+ if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
+ Options.ImplicitInt = 1;
+ else
+ Options.ImplicitInt = 0;
+
+ // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
+ // is specified, or -std is set to a conforming mode.
+ Options.Trigraphs = !Options.GNUMode;
+ if (Trigraphs.getPosition())
+ Options.Trigraphs = Trigraphs; // Command line option wins if specified.
+
+ // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
+ // even if they are normally on for the target. In GNU modes (e.g.
+ // -std=gnu99) the default for blocks depends on the target settings.
+ // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
+ if (!Options.ObjC1 && !Options.GNUMode)
+ Options.Blocks = 0;
+
+ // Default to not accepting '$' in identifiers when preprocessing assembler,
+ // but do accept when preprocessing C. FIXME: these defaults are right for
+ // darwin, are they right everywhere?
+ Options.DollarIdents = LK != langkind_asm_cpp;
+ if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
+ Options.DollarIdents = DollarsInIdents;
+
+ if (PascalStrings.getPosition())
+ Options.PascalStrings = PascalStrings;
+ if (MSExtensions.getPosition())
+ Options.Microsoft = MSExtensions;
+ Options.WritableStrings = WritableStrings;
+ if (NoLaxVectorConversions.getPosition())
+ Options.LaxVectorConversions = 0;
+ Options.Exceptions = Exceptions;
+ Options.Rtti = Rtti;
+ if (EnableBlocks.getPosition())
+ Options.Blocks = EnableBlocks;
+ if (CharIsSigned.getPosition())
+ Options.CharIsSigned = CharIsSigned;
+ if (ShortWChar.getPosition())
+ Options.ShortWChar = ShortWChar;
+
+ if (!AllowBuiltins)
+ Options.NoBuiltin = 1;
+ if (Freestanding)
+ Options.Freestanding = Options.NoBuiltin = 1;
+
+ if (EnableHeinousExtensions)
+ Options.HeinousExtensions = 1;
+
+ if (AccessControl)
+ Options.AccessControl = 1;
+
+ Options.ElideConstructors = !NoElideConstructors;
+
+ // OpenCL and C++ both have bool, true, false keywords.
+ Options.Bool = Options.OpenCL | Options.CPlusPlus;
+
+ Options.MathErrno = MathErrno;
+
+ Options.InstantiationDepth = TemplateDepth;
+
+ // Override the default runtime if the user requested it.
+ if (NeXTRuntime)
+ Options.NeXTRuntime = 1;
+ else if (GNURuntime)
+ Options.NeXTRuntime = 0;
+
+ if (!ObjCConstantStringClass.empty())
+ Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
+
+ if (ObjCNonFragileABI)
+ Options.ObjCNonFragileABI = 1;
+
+ if (EmitAllDecls)
+ Options.EmitAllDecls = 1;
+
+ // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
+ Options.OptimizeSize = 0;
+ Options.Optimize = !!CompileOpts.OptimizationLevel;
+
+ assert(PICLevel <= 2 && "Invalid value for -pic-level");
+ Options.PICLevel = PICLevel;
+
+ Options.GNUInline = !Options.C99;
+ // FIXME: This is affected by other options (-fno-inline).
+
+ // This is the __NO_INLINE__ define, which just depends on things like the
+ // optimization level and -fno-inline, not actually whether the backend has
+ // inlining enabled.
+ Options.NoInline = !CompileOpts.OptimizationLevel;
+
+ Options.Static = StaticDefine;
+
+ switch (StackProtector) {
+ default:
+ assert(StackProtector <= 2 && "Invalid value for -stack-protector");
+ case -1: break;
+ case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
+ case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
+ case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
+ }
+
+ if (MainFileName.getPosition())
+ Options.setMainFileName(MainFileName.c_str());
+
+ Target.setForcedLangOptions(Options);
+}
Modified: cfe/trunk/tools/clang-cc/Options.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.h?rev=86816&r1=86815&r2=86816&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/Options.h (original)
+++ cfe/trunk/tools/clang-cc/Options.h Wed Nov 11 01:26:12 2009
@@ -19,6 +19,21 @@
class PreprocessorOptions;
class TargetInfo;
+enum LangKind {
+ langkind_unspecified,
+ langkind_c,
+ langkind_c_cpp,
+ langkind_asm_cpp,
+ langkind_cxx,
+ langkind_cxx_cpp,
+ langkind_objc,
+ langkind_objc_cpp,
+ langkind_objcxx,
+ langkind_objcxx_cpp,
+ langkind_ocl,
+ langkind_ast
+};
+
// FIXME: This can be sunk into InitializeCompileOptions now that that happens
// before language initialization?
void ComputeFeatureMap(TargetInfo &Target, llvm::StringMap<bool> &Features);
@@ -26,6 +41,11 @@
void InitializeCompileOptions(CompileOptions &Opts,
const llvm::StringMap<bool> &Features);
+void InitializeLangOptions(LangOptions &Options, LangKind LK,
+ TargetInfo &Target,
+ const CompileOptions &CompileOpts,
+ const llvm::StringMap<bool> &Features);
+
void InitializePreprocessorOptions(PreprocessorOptions &Opts);
} // end namespace clang
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86816&r1=86815&r2=86816&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 01:26:12 2009
@@ -321,39 +321,10 @@
llvm::cl::desc("Print the amount of time each "
"phase of compilation takes"));
-static llvm::cl::opt<bool>
-Freestanding("ffreestanding",
- llvm::cl::desc("Assert that the compilation takes place in a "
- "freestanding environment"));
-
-static llvm::cl::opt<bool>
-AllowBuiltins("fbuiltin", llvm::cl::init(true),
- llvm::cl::desc("Disable implicit builtin knowledge of functions"));
-
-
-static llvm::cl::opt<bool>
-MathErrno("fmath-errno", llvm::cl::init(true),
- llvm::cl::desc("Require math functions to respect errno"));
-
//===----------------------------------------------------------------------===//
// Language Options
//===----------------------------------------------------------------------===//
-enum LangKind {
- langkind_unspecified,
- langkind_c,
- langkind_c_cpp,
- langkind_asm_cpp,
- langkind_cxx,
- langkind_cxx_cpp,
- langkind_objc,
- langkind_objc_cpp,
- langkind_objcxx,
- langkind_objcxx_cpp,
- langkind_ocl,
- langkind_ast
-};
-
static llvm::cl::opt<LangKind>
BaseLang("x", llvm::cl::desc("Base language to compile"),
llvm::cl::init(langkind_unspecified),
@@ -384,455 +355,14 @@
"Clang AST"),
clEnumValEnd));
-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<std::string>
-ObjCConstantStringClass("fconstant-string-class",
- llvm::cl::value_desc("class name"),
- llvm::cl::desc("Specify the class to use for constant "
- "Objective-C string objects."));
-
-static llvm::cl::opt<bool>
-ObjCEnableGC("fobjc-gc",
- llvm::cl::desc("Enable Objective-C garbage collection"));
-
-static llvm::cl::opt<bool>
-ObjCEnableGCBitmapPrint("print-ivar-layout",
- llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
-
-static llvm::cl::opt<LangOptions::VisibilityMode>
-SymbolVisibility("fvisibility",
- llvm::cl::desc("Set the default symbol visibility:"),
- llvm::cl::init(LangOptions::Default),
- llvm::cl::values(clEnumValN(LangOptions::Default, "default",
- "Use default symbol visibility"),
- clEnumValN(LangOptions::Hidden, "hidden",
- "Use hidden symbol visibility"),
- clEnumValN(LangOptions::Protected,"protected",
- "Use protected symbol visibility"),
- clEnumValEnd));
-
-static llvm::cl::opt<bool>
-OverflowChecking("ftrapv",
- llvm::cl::desc("Trap on integer overflow"),
- llvm::cl::init(false));
-
-static llvm::cl::opt<bool>
-AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
- llvm::cl::init(false));
-
-static llvm::cl::opt<bool>
-PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
- llvm::cl::init(false));
-
-static void InitializeLangOptions(LangOptions &Options, LangKind LK){
- bool NoPreprocess = false;
-
- switch (LK) {
- default: assert(0 && "Unknown language kind!");
- case langkind_asm_cpp:
- Options.AsmPreprocessor = 1;
- // FALLTHROUGH
- case langkind_c_cpp:
- NoPreprocess = true;
- // FALLTHROUGH
- case langkind_c:
- // Do nothing.
- break;
- case langkind_cxx_cpp:
- NoPreprocess = true;
- // FALLTHROUGH
- case langkind_cxx:
- Options.CPlusPlus = 1;
- break;
- case langkind_objc_cpp:
- NoPreprocess = true;
- // FALLTHROUGH
- case langkind_objc:
- Options.ObjC1 = Options.ObjC2 = 1;
- break;
- case langkind_objcxx_cpp:
- NoPreprocess = true;
- // FALLTHROUGH
- case langkind_objcxx:
- Options.ObjC1 = Options.ObjC2 = 1;
- Options.CPlusPlus = 1;
- break;
- case langkind_ocl:
- Options.OpenCL = 1;
- Options.AltiVec = 1;
- Options.CXXOperatorNames = 1;
- Options.LaxVectorConversions = 1;
- break;
- }
-
- if (ObjCExclusiveGC)
- Options.setGCMode(LangOptions::GCOnly);
- else if (ObjCEnableGC)
- Options.setGCMode(LangOptions::HybridGC);
-
- if (ObjCEnableGCBitmapPrint)
- Options.ObjCGCBitmapPrint = 1;
-
- if (AltiVec)
- Options.AltiVec = 1;
-
- if (PThread)
- Options.POSIXThreads = 1;
-
- Options.setVisibilityMode(SymbolVisibility);
- Options.OverflowChecking = OverflowChecking;
-}
-
-/// LangStds - Language standards we support.
-enum LangStds {
- lang_unspecified,
- lang_c89, lang_c94, lang_c99,
- lang_gnu89, lang_gnu99,
- lang_cxx98, lang_gnucxx98,
- lang_cxx0x, lang_gnucxx0x
-};
-
-static llvm::cl::opt<LangStds>
-LangStd("std", llvm::cl::desc("Language standard to compile for"),
- llvm::cl::init(lang_unspecified),
- llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
- clEnumValN(lang_c89, "c90", "ISO C 1990"),
- clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
- clEnumValN(lang_c94, "iso9899:199409",
- "ISO C 1990 with amendment 1"),
- clEnumValN(lang_c99, "c99", "ISO C 1999"),
- clEnumValN(lang_c99, "c9x", "ISO C 1999"),
- clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
- clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
- clEnumValN(lang_gnu89, "gnu89",
- "ISO C 1990 with GNU extensions"),
- clEnumValN(lang_gnu99, "gnu99",
- "ISO C 1999 with GNU extensions (default for C)"),
- clEnumValN(lang_gnu99, "gnu9x",
- "ISO C 1999 with GNU extensions"),
- clEnumValN(lang_cxx98, "c++98",
- "ISO C++ 1998 with amendments"),
- clEnumValN(lang_gnucxx98, "gnu++98",
- "ISO C++ 1998 with amendments and GNU "
- "extensions (default for C++)"),
- clEnumValN(lang_cxx0x, "c++0x",
- "Upcoming ISO C++ 200x with amendments"),
- clEnumValN(lang_gnucxx0x, "gnu++0x",
- "Upcoming ISO C++ 200x with amendments and GNU "
- "extensions"),
- clEnumValEnd));
-
-static llvm::cl::opt<bool>
-NoOperatorNames("fno-operator-names",
- llvm::cl::desc("Do not treat C++ operator name keywords as "
- "synonyms for operators"));
-
-static llvm::cl::opt<bool>
-PascalStrings("fpascal-strings",
- llvm::cl::desc("Recognize and construct Pascal-style "
- "string literals"));
-
-static llvm::cl::opt<bool>
-MSExtensions("fms-extensions",
- llvm::cl::desc("Accept some non-standard constructs used in "
- "Microsoft header files "));
-
-static llvm::cl::opt<bool>
-WritableStrings("fwritable-strings",
- llvm::cl::desc("Store string literals as writable data"));
-
-static llvm::cl::opt<bool>
-NoLaxVectorConversions("fno-lax-vector-conversions",
- llvm::cl::desc("Disallow implicit conversions between "
- "vectors with a different number of "
- "elements or different element types"));
-
-static llvm::cl::opt<bool>
-EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
-
-static llvm::cl::opt<bool>
-EnableHeinousExtensions("fheinous-gnu-extensions",
- llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
- llvm::cl::ValueDisallowed, llvm::cl::Hidden);
-
-static llvm::cl::opt<bool>
-ObjCNonFragileABI("fobjc-nonfragile-abi",
- llvm::cl::desc("enable objective-c's nonfragile abi"));
-
-
-static llvm::cl::opt<bool>
-EmitAllDecls("femit-all-decls",
- llvm::cl::desc("Emit all declarations, even if unused"));
-
-static llvm::cl::opt<bool>
-Exceptions("fexceptions",
- llvm::cl::desc("Enable support for exception handling"));
-
-static llvm::cl::opt<bool>
-Rtti("frtti", llvm::cl::init(true),
- llvm::cl::desc("Enable generation of rtti information"));
-
-static llvm::cl::opt<bool>
-GNURuntime("fgnu-runtime",
- llvm::cl::desc("Generate output compatible with the standard GNU "
- "Objective-C runtime"));
-
-static llvm::cl::opt<bool>
-NeXTRuntime("fnext-runtime",
- llvm::cl::desc("Generate output compatible with the NeXT "
- "runtime"));
-
-static llvm::cl::opt<bool>
-CharIsSigned("fsigned-char",
- llvm::cl::desc("Force char to be a signed/unsigned type"));
-
-static llvm::cl::opt<bool>
-ShortWChar("fshort-wchar",
- llvm::cl::desc("Force wchar_t to be a short unsigned int"));
-
-
-static llvm::cl::opt<bool>
-Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
-
-static llvm::cl::opt<unsigned>
-TemplateDepth("ftemplate-depth", llvm::cl::init(99),
- llvm::cl::desc("Maximum depth of recursive template "
- "instantiation"));
-static llvm::cl::opt<bool>
-DollarsInIdents("fdollars-in-identifiers",
- llvm::cl::desc("Allow '$' in identifiers"));
-
-static llvm::cl::opt<std::string>
-MainFileName("main-file-name",
- llvm::cl::desc("Main file name to use for debug info"));
-
-static llvm::cl::opt<bool>
-AccessControl("faccess-control",
- llvm::cl::desc("Enable C++ access control"));
-
-static llvm::cl::opt<bool>
-NoElideConstructors("fno-elide-constructors",
- llvm::cl::desc("Disable C++ copy constructor elision"));
+TargetTriple("triple",
+ llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
static llvm::cl::opt<std::string>
TargetABI("target-abi",
llvm::cl::desc("Target a particular ABI type"));
-static llvm::cl::opt<std::string>
-TargetTriple("triple",
- llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
-
-
-static llvm::cl::opt<unsigned>
-PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
-
-static llvm::cl::opt<bool>
-StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
-
-static llvm::cl::opt<int>
-StackProtector("stack-protector",
- llvm::cl::desc("Enable stack protectors"),
- llvm::cl::init(-1));
-
-static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
- TargetInfo &Target,
- const CompileOptions &CompileOpts,
- const llvm::StringMap<bool> &Features) {
- // Allow the target to set the default the language options as it sees fit.
- Target.getDefaultLangOptions(Options);
-
- // Pass the map of target features to the target for validation and
- // processing.
- Target.HandleTargetFeatures(Features);
-
- if (LangStd == lang_unspecified) {
- // Based on the base language, pick one.
- switch (LK) {
- case langkind_ast: assert(0 && "Invalid call for AST inputs");
- case lang_unspecified: assert(0 && "Unknown base language");
- case langkind_ocl:
- LangStd = lang_c99;
- break;
- case langkind_c:
- case langkind_asm_cpp:
- case langkind_c_cpp:
- case langkind_objc:
- case langkind_objc_cpp:
- LangStd = lang_gnu99;
- break;
- case langkind_cxx:
- case langkind_cxx_cpp:
- case langkind_objcxx:
- case langkind_objcxx_cpp:
- LangStd = lang_gnucxx98;
- break;
- }
- }
-
- switch (LangStd) {
- default: assert(0 && "Unknown language standard!");
-
- // Fall through from newer standards to older ones. This isn't really right.
- // FIXME: Enable specifically the right features based on the language stds.
- case lang_gnucxx0x:
- case lang_cxx0x:
- Options.CPlusPlus0x = 1;
- // FALL THROUGH
- case lang_gnucxx98:
- case lang_cxx98:
- Options.CPlusPlus = 1;
- Options.CXXOperatorNames = !NoOperatorNames;
- // FALL THROUGH.
- case lang_gnu99:
- case lang_c99:
- Options.C99 = 1;
- Options.HexFloats = 1;
- // FALL THROUGH.
- case lang_gnu89:
- Options.BCPLComment = 1; // Only for C99/C++.
- // FALL THROUGH.
- case lang_c94:
- Options.Digraphs = 1; // C94, C99, C++.
- // FALL THROUGH.
- case lang_c89:
- break;
- }
-
- // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
- switch (LangStd) {
- default: assert(0 && "Unknown language standard!");
- case lang_gnucxx0x:
- case lang_gnucxx98:
- case lang_gnu99:
- case lang_gnu89:
- Options.GNUMode = 1;
- break;
- case lang_cxx0x:
- case lang_cxx98:
- case lang_c99:
- case lang_c94:
- case lang_c89:
- Options.GNUMode = 0;
- break;
- }
-
- if (Options.CPlusPlus) {
- Options.C99 = 0;
- Options.HexFloats = 0;
- }
-
- if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
- Options.ImplicitInt = 1;
- else
- Options.ImplicitInt = 0;
-
- // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
- // is specified, or -std is set to a conforming mode.
- Options.Trigraphs = !Options.GNUMode;
- if (Trigraphs.getPosition())
- Options.Trigraphs = Trigraphs; // Command line option wins if specified.
-
- // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
- // even if they are normally on for the target. In GNU modes (e.g.
- // -std=gnu99) the default for blocks depends on the target settings.
- // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
- if (!Options.ObjC1 && !Options.GNUMode)
- Options.Blocks = 0;
-
- // Default to not accepting '$' in identifiers when preprocessing assembler,
- // but do accept when preprocessing C. FIXME: these defaults are right for
- // darwin, are they right everywhere?
- Options.DollarIdents = LK != langkind_asm_cpp;
- if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
- Options.DollarIdents = DollarsInIdents;
-
- if (PascalStrings.getPosition())
- Options.PascalStrings = PascalStrings;
- if (MSExtensions.getPosition())
- Options.Microsoft = MSExtensions;
- Options.WritableStrings = WritableStrings;
- if (NoLaxVectorConversions.getPosition())
- Options.LaxVectorConversions = 0;
- Options.Exceptions = Exceptions;
- Options.Rtti = Rtti;
- if (EnableBlocks.getPosition())
- Options.Blocks = EnableBlocks;
- if (CharIsSigned.getPosition())
- Options.CharIsSigned = CharIsSigned;
- if (ShortWChar.getPosition())
- Options.ShortWChar = ShortWChar;
-
- if (!AllowBuiltins)
- Options.NoBuiltin = 1;
- if (Freestanding)
- Options.Freestanding = Options.NoBuiltin = 1;
-
- if (EnableHeinousExtensions)
- Options.HeinousExtensions = 1;
-
- if (AccessControl)
- Options.AccessControl = 1;
-
- Options.ElideConstructors = !NoElideConstructors;
-
- // OpenCL and C++ both have bool, true, false keywords.
- Options.Bool = Options.OpenCL | Options.CPlusPlus;
-
- Options.MathErrno = MathErrno;
-
- Options.InstantiationDepth = TemplateDepth;
-
- // Override the default runtime if the user requested it.
- if (NeXTRuntime)
- Options.NeXTRuntime = 1;
- else if (GNURuntime)
- Options.NeXTRuntime = 0;
-
- if (!ObjCConstantStringClass.empty())
- Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
-
- if (ObjCNonFragileABI)
- Options.ObjCNonFragileABI = 1;
-
- if (EmitAllDecls)
- Options.EmitAllDecls = 1;
-
- // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
- Options.OptimizeSize = 0;
- Options.Optimize = !!CompileOpts.OptimizationLevel;
-
- assert(PICLevel <= 2 && "Invalid value for -pic-level");
- Options.PICLevel = PICLevel;
-
- Options.GNUInline = !Options.C99;
- // FIXME: This is affected by other options (-fno-inline).
-
- // This is the __NO_INLINE__ define, which just depends on things like the
- // optimization level and -fno-inline, not actually whether the backend has
- // inlining enabled.
- Options.NoInline = !CompileOpts.OptimizationLevel;
-
- Options.Static = StaticDefine;
-
- switch (StackProtector) {
- default:
- assert(StackProtector <= 2 && "Invalid value for -stack-protector");
- case -1: break;
- case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
- case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
- case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
- }
-
- if (MainFileName.getPosition())
- Options.setMainFileName(MainFileName.c_str());
-
- Target.setForcedLangOptions(Options);
-}
-
//===----------------------------------------------------------------------===//
// SourceManager initialization.
//===----------------------------------------------------------------------===//
@@ -1939,11 +1469,9 @@
// FIXME: These aren't used during operations on ASTs. Split onto a separate
// code path to make this obvious.
- if (LK != langkind_ast) {
- InitializeLangOptions(Opts.getLangOpts(), LK);
- InitializeLanguageStandard(Opts.getLangOpts(), LK, Target,
- Opts.getCompileOpts(), Opts.getTargetFeatures());
- }
+ if (LK != langkind_ast)
+ InitializeLangOptions(Opts.getLangOpts(), LK, Target,
+ Opts.getCompileOpts(), Opts.getTargetFeatures());
// Initialize the header search options.
InitializeIncludePaths(Opts.getHeaderSearchOpts(), Argv0, Opts.getLangOpts());
More information about the cfe-commits
mailing list