From d773facac21e2dca085d1f4b7447ca55b2b169ce Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 8 Dec 2016 22:45:10 +0300 Subject: [PATCH] [HIPIFY] -no-output support. Actually output file is created by clang itself, but isn't updated and is deleted after processing. In cooperation with -print-stat -no-output (or single -n) is used for examine the source CUDA code. Conflicting options: -inplce -o [ROCm/hip commit: 2374153c10dc14ae0eff0e97ca7e560686401150] --- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 2c934aebbc..a124fb7c64 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -2107,6 +2107,16 @@ int main(int argc, const char **argv) { if (N) { NoOutput = PrintStats = true; } + if (NoOutput) { + if (Inplace) { + llvm::errs() << "Conflict: both -no-output and -inplace options are specified.\n"; + return 1; + } + if (!dst.empty()) { + llvm::errs() << "Conflict: both -no-output and -o options are specified.\n"; + return 1; + } + } if (dst.empty()) { dst = fileSources[0]; if (!Inplace) { @@ -2120,6 +2130,7 @@ int main(int argc, const char **argv) { } else { if (Inplace) { llvm::errs() << "Conflict: both -o and -inplace options are specified.\n"; + return 1; } dst += ".hip"; } @@ -2167,15 +2178,18 @@ int main(int argc, const char **argv) { if (!Tool.applyAllReplacements(Rewrite)) { DEBUG(dbgs() << "Skipped some replacements.\n"); } - - Result = Rewrite.overwriteChangedFiles(); - - if (!Inplace) { + if (!NoOutput) { + Result = Rewrite.overwriteChangedFiles(); + } + if (!Inplace && !NoOutput) { size_t pos = dst.rfind("."); if (pos != std::string::npos) { rename(dst.c_str(), dst.substr(0, pos).c_str()); } } + if (NoOutput) { + remove(dst.c_str()); + } if (PrintStats) { printStats(fileSources[0], PPCallbacks, Callback); }