aboutsummaryrefslogtreecommitdiff
path: root/Driver/clang.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-10 01:53:41 +0000
committerChris Lattner <sabre@nondot.org>2008-01-10 01:53:41 +0000
commit64299f81aa497ce5694f04a32ee09b618fdbbd32 (patch)
tree68f3fc57abec55e33c43225448760edac5bba84b /Driver/clang.cpp
parent2bfa5334a7d76168ab07d2ad8a9aa636a4b2f06d (diff)
add support for the GCC -include option.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45810 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/clang.cpp')
-rw-r--r--Driver/clang.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index c2ebfb38a8..26cbd4863f 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -506,6 +506,11 @@ static llvm::cl::list<std::string>
U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
llvm::cl::desc("Undefine the specified macro"));
+static llvm::cl::list<std::string>
+ImplicitIncludes("include", llvm::cl::value_desc("file"),
+ llvm::cl::desc("Include file before parsing"));
+
+
// Append a #define line to Buf for Macro. Macro should be of the form XXX,
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
// "#define XXX Y z W". To get a #define with no value, use "XXX=".
@@ -526,6 +531,16 @@ static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro,
Buf.push_back('\n');
}
+/// AddImplicitInclude - Add an implicit #include of the specified file to the
+/// predefines buffer.
+static void AddImplicitInclude(std::vector<char> &Buf, const std::string &File){
+ const char *Inc = "#include \"";
+ Buf.insert(Buf.end(), Inc, Inc+strlen(Inc));
+ Buf.insert(Buf.end(), File.begin(), File.end());
+ Buf.push_back('"');
+ Buf.push_back('\n');
+}
+
/// InitializePreprocessor - Initialize the preprocessor getting it and the
/// environment ready to process a single file. This returns the file ID for the
@@ -562,7 +577,11 @@ static unsigned InitializePreprocessor(Preprocessor &PP,
for (unsigned i = 0, e = U_macros.size(); i != e; ++i)
DefineBuiltinMacro(PredefineBuffer, U_macros[i].c_str(), "#undef ");
- // FIXME: Read any files specified by -imacros or -include.
+ // FIXME: Read any files specified by -imacros.
+
+ // Add implicit #includes from -include.
+ for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
+ AddImplicitInclude(PredefineBuffer, ImplicitIncludes[i]);
// Null terminate PredefinedBuffer and add it.
PredefineBuffer.push_back(0);
@@ -583,7 +602,7 @@ static unsigned InitializePreprocessor(Preprocessor &PP,
// FIXME: -nostdinc,-nostdinc++
// FIXME: -imultilib
//
-// FIXME: -include,-imacros
+// FIXME: -imacros
static llvm::cl::opt<bool>
nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));