diff options
author | Adrian Prantl <aprantl@apple.com> | 2015-06-20 18:53:08 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2015-06-20 18:53:08 +0000 |
commit | bb165fb04db511d0f6927133662b74943f76cc39 (patch) | |
tree | 5c8150e9096c41f7a426c704aa4762e6420cd28e /clang/lib/ARCMigrate | |
parent | 6ed81cbcdb6e5f07f6ac71a446d970c2db8945a5 (diff) | |
download | bcm5719-llvm-bb165fb04db511d0f6927133662b74943f76cc39.tar.gz bcm5719-llvm-bb165fb04db511d0f6927133662b74943f76cc39.zip |
Introduce a PCHContainerOperations interface (NFC).
A PCHContainerOperations abstract interface provides operations for
creating and unwrapping containers for serialized ASTs (precompiled
headers and clang modules). The default implementation is
RawPCHContainerOperations, which uses a flat file for the output.
The main application for this interface will be an
ObjectFilePCHContainerOperations implementation that uses LLVM to
wrap the module in an ELF/Mach-O/COFF container to store debug info
alongside the AST.
rdar://problem/20091852
llvm-svn: 240225
Diffstat (limited to 'clang/lib/ARCMigrate')
-rw-r--r-- | clang/lib/ARCMigrate/ARCMT.cpp | 82 | ||||
-rw-r--r-- | clang/lib/ARCMigrate/ARCMTActions.cpp | 12 |
2 files changed, 48 insertions, 46 deletions
diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp index f266eaf8396..f33ad21cf02 100644 --- a/clang/lib/ARCMigrate/ARCMT.cpp +++ b/clang/lib/ARCMigrate/ARCMT.cpp @@ -166,7 +166,8 @@ static bool HasARCRuntime(CompilerInvocation &origCI) { } static CompilerInvocation * -createInvocationForMigration(CompilerInvocation &origCI) { +createInvocationForMigration(CompilerInvocation &origCI, + const PCHContainerOperations &PCHContainerOps) { std::unique_ptr<CompilerInvocation> CInvok; CInvok.reset(new CompilerInvocation(origCI)); PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts(); @@ -178,9 +179,8 @@ createInvocationForMigration(CompilerInvocation &origCI) { IntrusiveRefCntPtr<DiagnosticsEngine> Diags( new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(), new IgnoringDiagConsumer())); - std::string OriginalFile = - ASTReader::getOriginalSourceFile(PPOpts.ImplicitPCHInclude, - FileMgr, *Diags); + std::string OriginalFile = ASTReader::getOriginalSourceFile( + PPOpts.ImplicitPCHInclude, FileMgr, PCHContainerOps, *Diags); if (!OriginalFile.empty()) PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile); PPOpts.ImplicitPCHInclude.clear(); @@ -230,11 +230,11 @@ static void emitPremigrationErrors(const CapturedDiagList &arcDiags, // checkForManualIssues. //===----------------------------------------------------------------------===// -bool arcmt::checkForManualIssues(CompilerInvocation &origCI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient, - bool emitPremigrationARCErrors, - StringRef plistOut) { +bool arcmt::checkForManualIssues( + CompilerInvocation &origCI, const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors, + StringRef plistOut) { if (!origCI.getLangOpts()->ObjC1) return false; @@ -247,7 +247,7 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, assert(!transforms.empty()); std::unique_ptr<CompilerInvocation> CInvok; - CInvok.reset(createInvocationForMigration(origCI)); + CInvok.reset(createInvocationForMigration(origCI, *PCHContainerOps)); CInvok->getFrontendOpts().Inputs.clear(); CInvok->getFrontendOpts().Inputs.push_back(Input); @@ -263,8 +263,8 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags); Diags->setClient(&errRec, /*ShouldOwnClient=*/false); - std::unique_ptr<ASTUnit> Unit( - ASTUnit::LoadFromCompilerInvocationAction(CInvok.release(), Diags)); + std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction( + CInvok.release(), PCHContainerOps, Diags)); if (!Unit) { errRec.FinishCapture(); return true; @@ -330,12 +330,11 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, // applyTransformations. //===----------------------------------------------------------------------===// -static bool applyTransforms(CompilerInvocation &origCI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient, - StringRef outputDir, - bool emitPremigrationARCErrors, - StringRef plistOut) { +static bool +applyTransforms(CompilerInvocation &origCI, const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient, StringRef outputDir, + bool emitPremigrationARCErrors, StringRef plistOut) { if (!origCI.getLangOpts()->ObjC1) return false; @@ -343,15 +342,16 @@ static bool applyTransforms(CompilerInvocation &origCI, // Make sure checking is successful first. CompilerInvocation CInvokForCheck(origCI); - if (arcmt::checkForManualIssues(CInvokForCheck, Input, DiagClient, - emitPremigrationARCErrors, plistOut)) + if (arcmt::checkForManualIssues(CInvokForCheck, Input, PCHContainerOps, + DiagClient, emitPremigrationARCErrors, + plistOut)) return true; CompilerInvocation CInvok(origCI); CInvok.getFrontendOpts().Inputs.clear(); CInvok.getFrontendOpts().Inputs.push_back(Input); - - MigrationProcess migration(CInvok, DiagClient, outputDir); + + MigrationProcess migration(CInvok, PCHContainerOps, DiagClient, outputDir); bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval; std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode, @@ -376,22 +376,22 @@ static bool applyTransforms(CompilerInvocation &origCI, } } -bool arcmt::applyTransformations(CompilerInvocation &origCI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient) { - return applyTransforms(origCI, Input, DiagClient, +bool arcmt::applyTransformations( + CompilerInvocation &origCI, const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient) { + return applyTransforms(origCI, Input, PCHContainerOps, DiagClient, StringRef(), false, StringRef()); } -bool arcmt::migrateWithTemporaryFiles(CompilerInvocation &origCI, - const FrontendInputFile &Input, - DiagnosticConsumer *DiagClient, - StringRef outputDir, - bool emitPremigrationARCErrors, - StringRef plistOut) { +bool arcmt::migrateWithTemporaryFiles( + CompilerInvocation &origCI, const FrontendInputFile &Input, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *DiagClient, StringRef outputDir, + bool emitPremigrationARCErrors, StringRef plistOut) { assert(!outputDir.empty() && "Expected output directory path"); - return applyTransforms(origCI, Input, DiagClient, - outputDir, emitPremigrationARCErrors, plistOut); + return applyTransforms(origCI, Input, PCHContainerOps, DiagClient, outputDir, + emitPremigrationARCErrors, plistOut); } bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > & @@ -499,10 +499,12 @@ public: /// \brief Anchor for VTable. MigrationProcess::RewriteListener::~RewriteListener() { } -MigrationProcess::MigrationProcess(const CompilerInvocation &CI, - DiagnosticConsumer *diagClient, - StringRef outputDir) - : OrigCI(CI), DiagClient(diagClient), HadARCErrors(false) { +MigrationProcess::MigrationProcess( + const CompilerInvocation &CI, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + DiagnosticConsumer *diagClient, StringRef outputDir) + : OrigCI(CI), PCHContainerOps(PCHContainerOps), DiagClient(diagClient), + HadARCErrors(false) { if (!outputDir.empty()) { IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); IntrusiveRefCntPtr<DiagnosticsEngine> Diags( @@ -515,7 +517,7 @@ MigrationProcess::MigrationProcess(const CompilerInvocation &CI, bool MigrationProcess::applyTransform(TransformFn trans, RewriteListener *listener) { std::unique_ptr<CompilerInvocation> CInvok; - CInvok.reset(createInvocationForMigration(OrigCI)); + CInvok.reset(createInvocationForMigration(OrigCI, *PCHContainerOps)); CInvok->getDiagnosticOpts().IgnoreWarnings = true; Remapper.applyMappings(CInvok->getPreprocessorOpts()); @@ -537,7 +539,7 @@ bool MigrationProcess::applyTransform(TransformFn trans, ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs)); std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction( - CInvok.release(), Diags, ASTAction.get())); + CInvok.release(), PCHContainerOps, Diags, ASTAction.get())); if (!Unit) { errRec.FinishCapture(); return true; diff --git a/clang/lib/ARCMigrate/ARCMTActions.cpp b/clang/lib/ARCMigrate/ARCMTActions.cpp index 0ed36ddf68c..39a922f426c 100644 --- a/clang/lib/ARCMigrate/ARCMTActions.cpp +++ b/clang/lib/ARCMigrate/ARCMTActions.cpp @@ -16,6 +16,7 @@ using namespace arcmt; bool CheckAction::BeginInvocation(CompilerInstance &CI) { if (arcmt::checkForManualIssues(CI.getInvocation(), getCurrentInput(), + CI.getPCHContainerOperations(), CI.getDiagnostics().getClient())) return false; // errors, stop the action. @@ -29,6 +30,7 @@ CheckAction::CheckAction(FrontendAction *WrappedAction) bool ModifyAction::BeginInvocation(CompilerInstance &CI) { return !arcmt::applyTransformations(CI.getInvocation(), getCurrentInput(), + CI.getPCHContainerOperations(), CI.getDiagnostics().getClient()); } @@ -36,12 +38,10 @@ ModifyAction::ModifyAction(FrontendAction *WrappedAction) : WrapperFrontendAction(WrappedAction) {} bool MigrateAction::BeginInvocation(CompilerInstance &CI) { - if (arcmt::migrateWithTemporaryFiles(CI.getInvocation(), - getCurrentInput(), - CI.getDiagnostics().getClient(), - MigrateDir, - EmitPremigrationARCErros, - PlistOut)) + if (arcmt::migrateWithTemporaryFiles( + CI.getInvocation(), getCurrentInput(), CI.getPCHContainerOperations(), + CI.getDiagnostics().getClient(), MigrateDir, EmitPremigrationARCErros, + PlistOut)) return false; // errors, stop the action. // We only want to see diagnostics emitted by migrateWithTemporaryFiles. |