Skip to content

Commit 1313195

Browse files
committed
[Bridging PCH] Add -emit-pch to Frontend; call emitBridgingPCH.
1 parent 244ec57 commit 1313195

File tree

11 files changed

+44
-0
lines changed

11 files changed

+44
-0
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ ERROR(bridging_header_error,Fatal,
5353
WARNING(could_not_rewrite_bridging_header,none,
5454
"failed to serialize bridging header; "
5555
"target may not be debuggable outside of its original project", ())
56+
ERROR(bridging_header_pch_error,Fatal,
57+
"failed to emit PCH file '%0' for bridging header '%1'",
58+
(StringRef, StringRef))
5659

5760
WARNING(invalid_swift_name_method,none,
5861
"too %select{few|many}0 parameters in swift_name attribute (expected %1; "

include/swift/Driver/Types.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ TYPE("remap", Remapping, "remap", "")
6060

6161
// Misc types
6262
TYPE("pcm", ClangModuleFile, "pcm", "")
63+
TYPE("pch", PCH, "pch", "")
6364
TYPE("none", Nothing, "", "")
6465

6566
#undef TYPE

include/swift/Frontend/FrontendOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class FrontendOptions {
149149
/// Parse, type-check, and dump type refinement context hierarchy
150150
DumpTypeRefinementContexts,
151151

152+
EmitPCH, ///< Emit PCH of imported bridging header
153+
152154
EmitSILGen, ///< Emit raw SIL
153155
EmitSIL, ///< Emit canonical SIL
154156

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def disable_modules_validate_system_headers : Flag<["-"], "disable-modules-valid
233233
def emit_verbose_sil : Flag<["-"], "emit-verbose-sil">,
234234
HelpText<"Emit locations during SIL emission">;
235235

236+
def emit_pch : Flag<["-"], "emit-pch">,
237+
HelpText<"Emit PCH for imported Objective-C header file">, ModeOpt;
238+
236239
def enable_sil_ownership : Flag<["-"], "enable-sil-ownership">,
237240
HelpText<"Enable the SIL Ownership Model">;
238241

include/swift/Strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace swift {
1818
static const char SERIALIZED_MODULE_EXTENSION[] = "swiftmodule";
1919
/// The extension for serialized documentation comments.
2020
static const char SERIALIZED_MODULE_DOC_EXTENSION[] = "swiftdoc";
21+
/// The extension for PCH files.
22+
static const char PCH_EXTENSION[] = "pch";
2123
/// The extension for SIL files.
2224
static const char SIL_EXTENSION[] = "sil";
2325
/// The extension for SIB files.

lib/Driver/Driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,11 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
10731073
OI.CompilerOutputType = types::TY_LLVM_BC;
10741074
break;
10751075

1076+
case options::OPT_emit_pch:
1077+
OI.CompilerMode = OutputInfo::Mode::SingleCompile;
1078+
OI.CompilerOutputType = types::TY_PCH;
1079+
break;
1080+
10761081
case options::OPT_parse:
10771082
case options::OPT_typecheck:
10781083
case options::OPT_dump_parse:
@@ -1328,6 +1333,7 @@ void Driver::buildActions(const ToolChain &TC,
13281333
case types::TY_ClangModuleFile:
13291334
case types::TY_SwiftDeps:
13301335
case types::TY_Remapping:
1336+
case types::TY_PCH:
13311337
// We could in theory handle assembly or LLVM input, but let's not.
13321338
// FIXME: What about LTO?
13331339
Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file,

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ ToolChain::constructInvocation(const CompileJobAction &job,
191191
case types::TY_Object:
192192
FrontendModeOption = "-c";
193193
break;
194+
case types::TY_PCH:
195+
FrontendModeOption = "-emit-pch";
196+
break;
194197
case types::TY_RawSIL:
195198
FrontendModeOption = "-emit-silgen";
196199
break;
@@ -480,6 +483,7 @@ ToolChain::constructInvocation(const BackendJobAction &job,
480483
case types::TY_RawSIB:
481484
case types::TY_SIL:
482485
case types::TY_SIB:
486+
case types::TY_PCH:
483487
llvm_unreachable("Cannot be output from backend job");
484488
case types::TY_Swift:
485489
case types::TY_dSYM:

lib/Driver/Types.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ bool types::isTextual(ID Id) {
7878
case types::TY_Image:
7979
case types::TY_Object:
8080
case types::TY_dSYM:
81+
case types::TY_PCH:
8182
case types::TY_SIB:
8283
case types::TY_RawSIB:
8384
case types::TY_SwiftModuleFile:
@@ -105,6 +106,7 @@ bool types::isAfterLLVM(ID Id) {
105106
case types::TY_Object:
106107
return true;
107108
case types::TY_Swift:
109+
case types::TY_PCH:
108110
case types::TY_SIL:
109111
case types::TY_Dependencies:
110112
case types::TY_RawSIL:
@@ -145,6 +147,7 @@ bool types::isPartOfSwiftCompilation(ID Id) {
145147
case types::TY_Dependencies:
146148
case types::TY_ObjCHeader:
147149
case types::TY_AutolinkFile:
150+
case types::TY_PCH:
148151
case types::TY_Image:
149152
case types::TY_dSYM:
150153
case types::TY_SwiftModuleFile:

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
256256
Action = FrontendOptions::EmitSIB;
257257
} else if (Opt.matches(OPT_emit_sibgen)) {
258258
Action = FrontendOptions::EmitSIBGen;
259+
} else if (Opt.matches(OPT_emit_pch)) {
260+
Action = FrontendOptions::EmitPCH;
259261
} else if (Opt.matches(OPT_parse)) {
260262
Action = FrontendOptions::Parse;
261263
} else if (Opt.matches(OPT_typecheck)) {
@@ -482,6 +484,10 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
482484
Opts.setSingleOutputFilename("-");
483485
break;
484486

487+
case FrontendOptions::EmitPCH:
488+
Suffix = PCH_EXTENSION;
489+
break;
490+
485491
case FrontendOptions::EmitSILGen:
486492
case FrontendOptions::EmitSIL: {
487493
if (Opts.OutputFilenames.empty())
@@ -675,6 +681,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
675681
case FrontendOptions::Parse:
676682
case FrontendOptions::Typecheck:
677683
case FrontendOptions::EmitModuleOnly:
684+
case FrontendOptions::EmitPCH:
678685
case FrontendOptions::EmitSILGen:
679686
case FrontendOptions::EmitSIL:
680687
case FrontendOptions::EmitSIBGen:
@@ -694,6 +701,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
694701
case FrontendOptions::DumpInterfaceHash:
695702
case FrontendOptions::DumpAST:
696703
case FrontendOptions::PrintAST:
704+
case FrontendOptions::EmitPCH:
697705
case FrontendOptions::DumpScopeMaps:
698706
case FrontendOptions::DumpTypeRefinementContexts:
699707
case FrontendOptions::Immediate:
@@ -725,6 +733,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
725733
case FrontendOptions::DumpInterfaceHash:
726734
case FrontendOptions::DumpAST:
727735
case FrontendOptions::PrintAST:
736+
case FrontendOptions::EmitPCH:
728737
case FrontendOptions::DumpScopeMaps:
729738
case FrontendOptions::DumpTypeRefinementContexts:
730739
case FrontendOptions::EmitSILGen:

lib/Frontend/FrontendOptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bool FrontendOptions::actionHasOutput() const {
2828
case DumpScopeMaps:
2929
case DumpTypeRefinementContexts:
3030
return false;
31+
case EmitPCH:
3132
case EmitSILGen:
3233
case EmitSIL:
3334
case EmitSIBGen:
@@ -57,6 +58,7 @@ bool FrontendOptions::actionIsImmediate() const {
5758
case PrintAST:
5859
case DumpScopeMaps:
5960
case DumpTypeRefinementContexts:
61+
case EmitPCH:
6062
case EmitSILGen:
6163
case EmitSIL:
6264
case EmitSIBGen:

lib/FrontendTool/FrontendTool.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ static bool performCompile(std::unique_ptr<CompilerInstance> &Instance,
335335
FrontendOptions opts = Invocation.getFrontendOptions();
336336
FrontendOptions::ActionType Action = opts.RequestedAction;
337337

338+
// We've been asked to precompile a bridging header; we want to
339+
// avoid touching any other inputs and just parse, emit and exit.
340+
if (Action == FrontendOptions::EmitPCH) {
341+
auto clangImporter = static_cast<ClangImporter *>(
342+
Instance->getASTContext().getClangModuleLoader());
343+
return clangImporter->emitBridgingPCH(
344+
Invocation.getInputFilenames()[0], opts.getSingleOutputFilename());
345+
}
346+
338347
IRGenOptions &IRGenOpts = Invocation.getIRGenOptions();
339348

340349
bool inputIsLLVMIr = Invocation.getInputKind() == InputFileKind::IFK_LLVM_IR;

0 commit comments

Comments
 (0)