|
| 1 | +/******************************************************************************* |
| 2 | + * |
| 3 | + * University of Illinois/NCSA |
| 4 | + * Open Source License |
| 5 | + * |
| 6 | + * Copyright (c) 2018 Advanced Micro Devices, Inc. All Rights Reserved. |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * with the Software without restriction, including without limitation the |
| 11 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | + * sell copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * * Redistributions of source code must retain the above copyright notice, |
| 16 | + * this list of conditions and the following disclaimers. |
| 17 | + * |
| 18 | + * * Redistributions in binary form must reproduce the above copyright |
| 19 | + * notice, this list of conditions and the following disclaimers in the |
| 20 | + * documentation and/or other materials provided with the distribution. |
| 21 | + * |
| 22 | + * * Neither the names of Advanced Micro Devices, Inc. nor the names of its |
| 23 | + * contributors may be used to endorse or promote products derived from |
| 24 | + * this Software without specific prior written permission. |
| 25 | + * |
| 26 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 27 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 28 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 29 | + * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 30 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 31 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH |
| 32 | + * THE SOFTWARE. |
| 33 | + * |
| 34 | + ******************************************************************************/ |
| 35 | + |
| 36 | +#ifndef COMGR_CACHE_COMMAND_H |
| 37 | +#define COMGR_CACHE_COMMAND_H |
| 38 | + |
| 39 | +#include "amd_comgr.h" |
| 40 | + |
| 41 | +#include <clang/Driver/Action.h> |
| 42 | +#include <llvm/Support/Error.h> |
| 43 | +#include <llvm/Support/MemoryBuffer.h> |
| 44 | +#include <llvm/Support/SHA256.h> |
| 45 | +#include <llvm/Support/VirtualFileSystem.h> |
| 46 | + |
| 47 | +namespace clang { |
| 48 | +class DiagnosticOptions; |
| 49 | +namespace driver { |
| 50 | +class Command; |
| 51 | +} // namespace driver |
| 52 | +} // namespace clang |
| 53 | + |
| 54 | +namespace llvm { |
| 55 | +class raw_ostream; |
| 56 | +} |
| 57 | + |
| 58 | +namespace COMGR { |
| 59 | +class CachedCommandAdaptor { |
| 60 | +public: |
| 61 | + virtual amd_comgr_status_t execute(llvm::raw_ostream &LogS) = 0; |
| 62 | + |
| 63 | + virtual ~CachedCommandAdaptor() = default; |
| 64 | +}; |
| 65 | + |
| 66 | +class CachedCommand final : public CachedCommandAdaptor { |
| 67 | +public: |
| 68 | + using ExecuteFnTy = std::function<amd_comgr_status_t( |
| 69 | + clang::driver::Command &, llvm::raw_ostream &, clang::DiagnosticOptions &, |
| 70 | + llvm::vfs::FileSystem &)>; |
| 71 | + |
| 72 | +private: |
| 73 | + clang::driver::Command &Command; |
| 74 | + clang::DiagnosticOptions &DiagOpts; |
| 75 | + llvm::vfs::FileSystem &VFS; |
| 76 | + ExecuteFnTy ExecuteImpl; |
| 77 | + |
| 78 | +public: |
| 79 | + CachedCommand(clang::driver::Command &Command, |
| 80 | + clang::DiagnosticOptions &DiagOpts, llvm::vfs::FileSystem &VFS, |
| 81 | + ExecuteFnTy &&ExecuteImpl); |
| 82 | + |
| 83 | + amd_comgr_status_t execute(llvm::raw_ostream &LogS) override; |
| 84 | + |
| 85 | + ~CachedCommand() override = default; |
| 86 | +}; |
| 87 | +} // namespace COMGR |
| 88 | + |
| 89 | +#endif |
0 commit comments