diff options
author | Eric Liu <ioeric@google.com> | 2018-05-18 16:06:19 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-05-18 16:06:19 +0000 |
commit | 20e9101add0b8e12a1cedfb0c3092f030acaa897 (patch) | |
tree | 1e5ae8d131df5c25f6b932606b20ac9c119e8f99 /lib/Tooling/Tooling.cpp | |
parent | 1fa3e2699a6a422a044c097e7f3d5ade1cf3b8a8 (diff) |
[Tooling] Add an overload of runToolOnCodeWithArgs that takes VFS
Summary: ... to support purely VFS-based tools.
Reviewers: bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D47074
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Tooling.cpp')
-rw-r--r-- | lib/Tooling/Tooling.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 9ef578b362..c22ad93c76 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -155,27 +155,37 @@ namespace tooling { bool runToolOnCodeWithArgs( FrontendAction *ToolAction, const Twine &Code, + llvm::IntrusiveRefCntPtr<vfs::FileSystem> VFS, const std::vector<std::string> &Args, const Twine &FileName, const Twine &ToolName, - std::shared_ptr<PCHContainerOperations> PCHContainerOps, - const FileContentMappings &VirtualMappedFiles) { + std::shared_ptr<PCHContainerOperations> PCHContainerOps) { SmallString<16> FileNameStorage; StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); - llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( - new vfs::InMemoryFileSystem); - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr<FileManager> Files( - new FileManager(FileSystemOptions(), OverlayFileSystem)); + new FileManager(FileSystemOptions(), VFS)); ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(); ToolInvocation Invocation( getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), ToolAction, Files.get(), std::move(PCHContainerOps)); + return Invocation.run(); +} + +bool runToolOnCodeWithArgs( + FrontendAction *ToolAction, const Twine &Code, + const std::vector<std::string> &Args, const Twine &FileName, + const Twine &ToolName, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + const FileContentMappings &VirtualMappedFiles) { + llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem( + new vfs::OverlayFileSystem(vfs::getRealFileSystem())); + llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( + new vfs::InMemoryFileSystem); + OverlayFileSystem->pushOverlay(InMemoryFileSystem); SmallString<1024> CodeStorage; - InMemoryFileSystem->addFile(FileNameRef, 0, + InMemoryFileSystem->addFile(FileName, 0, llvm::MemoryBuffer::getMemBuffer( Code.toNullTerminatedStringRef(CodeStorage))); @@ -185,7 +195,8 @@ bool runToolOnCodeWithArgs( llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); } - return Invocation.run(); + return runToolOnCodeWithArgs(ToolAction, Code, OverlayFileSystem, Args, + FileName, ToolName); } std::string getAbsolutePath(StringRef File) { |