Skip to content

Commit 4138991

Browse files
committed
Add -include-footer option.
1 parent da480db commit 4138991

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4620,10 +4620,14 @@ def image__base : Separate<["-"], "image_base">;
46204620
def include_ : JoinedOrSeparate<["-", "--"], "include">, Group<clang_i_Group>, EnumName<"include">,
46214621
MetaVarName<"<file>">, HelpText<"Include file before parsing">,
46224622
Visibility<[ClangOption, CC1Option]>;
4623-
def include_footer : Separate<["-"], "include-footer">, Group<clang_i_Group>,
4623+
def include_internal_footer : Separate<["-"], "include-internal-footer">, Group<clang_i_Group>,
46244624
Visibility<[CC1Option]>,
46254625
HelpText<"Name of the footer integration file">, MetaVarName<"<file>">,
46264626
MarshallingInfoString<PreprocessorOpts<"IncludeFooter">>;
4627+
def include_internal_header : Separate<["-"], "include-internal-header">, Group<clang_i_Group>,
4628+
Visibility<[CC1Option]>,
4629+
HelpText<"Name of the header integration file">, MetaVarName<"<file>">,
4630+
MarshallingInfoString<PreprocessorOpts<"IncludeHeader">>;
46274631
def include_pch : Separate<["-"], "include-pch">, Group<clang_i_Group>,
46284632
Visibility<[ClangOption, CC1Option]>,
46294633
HelpText<"Include precompiled header file">, MetaVarName<"<file>">,

clang/include/clang/Lex/PreprocessorOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PreprocessorOptions {
6868
std::vector<std::pair<std::string, bool/*isUndef*/>> Macros;
6969
std::vector<std::string> Includes;
7070
std::string IncludeFooter;
71+
std::string IncludeHeader;
7172
std::vector<std::string> MacroIncludes;
7273

7374
/// Perform extra checks when loading PCM files for mutable file systems.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5729,7 +5729,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57295729
// action to determine this.
57305730
if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID &&
57315731
!Header.empty()) {
5732-
CmdArgs.push_back("-include");
5732+
CmdArgs.push_back("-include-internal-header");
57335733
CmdArgs.push_back(Args.MakeArgString(Header));
57345734
// When creating dependency information, filter out the generated
57355735
// header file.
@@ -5745,7 +5745,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
57455745
StringRef Footer = D.getIntegrationFooter(Input.getBaseInput());
57465746
if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID &&
57475747
!Args.hasArg(options::OPT_fno_sycl_use_footer) && !Footer.empty()) {
5748-
CmdArgs.push_back("-include-footer");
5748+
CmdArgs.push_back("-include-internal-footer");
57495749
CmdArgs.push_back(Args.MakeArgString(Footer));
57505750
// When creating dependency information, filter out the generated
57515751
// integration footer file.

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,19 @@ void clang::InitializePreprocessor(Preprocessor &PP,
16631663
AddImplicitInclude(Builder, Path);
16641664
}
16651665

1666+
#if 1
1667+
// Process -include-internal-header directive.
1668+
if (!LangOpts.SYCLIsDevice) {
1669+
if (!InitOpts.IncludeHeader.empty()) {
1670+
AddImplicitInclude(Builder, InitOpts.IncludeHeader);
1671+
}
1672+
// Process -include-internal-footer directive.
1673+
if (!InitOpts.IncludeFooter.empty()) {
1674+
AddImplicitInclude(Builder, InitOpts.IncludeFooter);
1675+
}
1676+
}
1677+
#endif
1678+
16661679
// Instruct the preprocessor to skip the preamble.
16671680
PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
16681681
InitOpts.PrecompiledPreambleBytes.second);

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,18 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
272272

273273
// Emit #line directives or GNU line markers depending on what mode we're in.
274274
if (UseLineDirectives) {
275-
*OS << "#line" << ' ' << LineNo << ' ' << '"';
276-
OS->write_escaped(CurFilename);
275+
if (CurFilename != PP.getPreprocessorOpts().IncludeFooter &&
276+
CurFilename != PP.getPreprocessorOpts().IncludeHeader) {
277+
*OS << "#line" << ' ' << LineNo << ' ' << '"';
278+
OS->write_escaped(CurFilename);
279+
*OS << '"';
280+
}
281+
// *OS << "#line" << ' ' << LineNo << ' ' << '"';
282+
// OS->write_escaped(CurFilename);
277283
*OS << '"';
278284
} else {
285+
if (CurFilename != PP.getPreprocessorOpts().IncludeFooter &&
286+
CurFilename != PP.getPreprocessorOpts().IncludeHeader) {
279287
*OS << '#' << ' ' << LineNo << ' ' << '"';
280288
OS->write_escaped(CurFilename);
281289
*OS << '"';
@@ -287,6 +295,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
287295
OS->write(" 3", 2);
288296
else if (FileType == SrcMgr::C_ExternCSystem)
289297
OS->write(" 3 4", 4);
298+
}
290299
}
291300
*OS << '\n';
292301
}
@@ -417,13 +426,26 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
417426

418427
switch (Reason) {
419428
case PPCallbacks::EnterFile:
429+
#if 0
430+
// Don't print the header and footer lines in the pre-processed output.
431+
if (CurFilename != PP.getPreprocessorOpts().IncludeFooter &&
432+
CurFilename != PP.getPreprocessorOpts().IncludeHeader)
433+
#endif
420434
WriteLineInfo(CurLine, " 1", 2);
421435
break;
422436
case PPCallbacks::ExitFile:
437+
#if 0
438+
if (CurFilename != PP.getPreprocessorOpts().IncludeFooter &&
439+
CurFilename != PP.getPreprocessorOpts().IncludeHeader)
440+
#endif
423441
WriteLineInfo(CurLine, " 2", 2);
424442
break;
425443
case PPCallbacks::SystemHeaderPragma:
426444
case PPCallbacks::RenameFile:
445+
#if 0
446+
if (CurFilename != PP.getPreprocessorOpts().IncludeFooter &&
447+
CurFilename != PP.getPreprocessorOpts().IncludeHeader)
448+
#endif
427449
WriteLineInfo(CurLine);
428450
break;
429451
}
@@ -914,7 +936,7 @@ static void PrintIncludeFooter(Preprocessor &PP, SourceLocation Loc,
914936
FileID FooterFileID = SourceMgr.ComputeValidFooterFileID(Footer);
915937
StringRef FooterContentBuffer = SourceMgr.getBufferData(FooterFileID);
916938
// print out the name of the integration footer.
917-
Callbacks->WriteFooterInfo(Footer);
939+
// Callbacks->WriteFooterInfo(Footer);
918940
SmallVector<StringRef, 8> FooterContentArr;
919941
FooterContentBuffer.split(FooterContentArr, '\r');
920942
// print out the content of the integration footer.
@@ -1187,6 +1209,7 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
11871209
PrintPreprocessedTokens(PP, Tok, Callbacks);
11881210
*OS << '\n';
11891211

1212+
#if 0
11901213
if (!PP.getPreprocessorOpts().IncludeFooter.empty() &&
11911214
!PP.IncludeFooterProcessed) {
11921215
assert(PP.getLangOpts().SYCLIsHost &&
@@ -1195,7 +1218,7 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
11951218
PrintIncludeFooter(PP, Loc, PP.getPreprocessorOpts().IncludeFooter,
11961219
Callbacks);
11971220
}
1198-
1221+
#endif
11991222
// Remove the handlers we just added to leave the preprocessor in a sane state
12001223
// so that it can be reused (for example by a clang::Parser instance).
12011224
PP.RemovePragmaHandler(MicrosoftExtHandler.get());

clang/lib/Lex/PPLexerChange.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
535535
}
536536
}
537537

538+
#if 0
538539
if (isInPrimaryFile() && getLangOpts().SYCLIsHost &&
539540
!getPreprocessorOpts().IncludeFooter.empty()) {
540541
SourceManager &SourceMgr = getSourceManager();
@@ -555,6 +556,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
555556
return false;
556557
}
557558
}
559+
#endif
558560

559561
// If this is the end of the main file, form an EOF token.
560562
assert(CurLexer && "Got EOF but no current lexer set!");

0 commit comments

Comments
 (0)