From f5deff4ba32f3429132e1aacccc34557d2bc9cc3 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 --- hipamd/hipify-clang/src/Cuda2Hip.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hipamd/hipify-clang/src/Cuda2Hip.cpp b/hipamd/hipify-clang/src/Cuda2Hip.cpp index 2c934aebbc..a124fb7c64 100644 --- a/hipamd/hipify-clang/src/Cuda2Hip.cpp +++ b/hipamd/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); }