diff --git a/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp b/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp index ac7625d346..1e10b72962 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/frontend.cpp @@ -4,14 +4,12 @@ #include "top.hpp" #include "frontend.hpp" #include "bif/bifbase.hpp" -#include "utils/libUtils.h" #include "utils/target_mappings.h" #include "utils/options.hpp" #include "os/os.hpp" #include "llvm/ADT/StringRef.h" #include #include -#include #include #include #include @@ -172,10 +170,7 @@ amdcl::OCLFrontend::getFrontendCommand(aclBinary *elf, #endif if (Opts && Opts->isDumpFlagSet(amd::option::DUMP_CL) && !preprocessOnly) { - std::string clFileName = Opts->getDumpFileName(".cl"); - f.open(clFileName.c_str(), (std::fstream::out | std::fstream::binary)); - f.write(src.data(), src.length()); - f.close(); + dumpSource(src, Opts); } std::string clcCmd = systemPath.str(); return clcCmd; diff --git a/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp b/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp index 13686329c1..f9755e6175 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/frontend.hpp @@ -4,8 +4,10 @@ #ifndef _BE_FRONTEND_HPP_ #define _BE_FRONTEND_HPP_ #include +#include #include "aclTypes.h" #include "compiler_stage.hpp" +#include "utils/libUtils.h" namespace amdcl { @@ -32,6 +34,16 @@ namespace amdcl virtual int compileCommand(const std::string& singleSrc) = 0; virtual std::string getClassName() = 0; + + //! Dumps source CL text with compiler options in a file. + void dumpSource(const std::string& src, amd::option::Options* opts) { + std::ofstream f(opts->getDumpFileName(".cl").c_str(), std::ios::trunc); + if(f.is_open()) { + f << "/* Compiler options:\n" << opts->origOptionStr << "\n*/\n\n" << src; + } else { + appendLogToCL(CL(), "File for dumping source cl isn't opened"); + } + } }; // class Frontend /*@}*/ diff --git a/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp b/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp index 34e46b3675..71b7b0b3c6 100644 --- a/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp +++ b/projects/clr/rocclr/compiler/lib/backends/common/frontend_clang.cpp @@ -8,7 +8,6 @@ #include "frontend.hpp" #include "os/os.hpp" #include "top.hpp" -#include "utils/libUtils.h" #include "utils/options.hpp" #include "utils/target_mappings.h" @@ -20,7 +19,6 @@ #include #include -#include amdcl::ClangOCLFrontend::ClangOCLFrontend(aclCompiler* cl, aclBinary* elf, aclLogFunction log) @@ -128,11 +126,7 @@ int amdcl::ClangOCLFrontend::compileCommand(const std::string& src) { ClangOptions.CompilerContext = &Context(); if (amdOpts && amdOpts->isDumpFlagSet(amd::option::DUMP_CL)) { - std::string inpCLFileName = amdOpts->getDumpFileName(".cl"); - std::fstream f; - f.open(inpCLFileName.c_str(), (std::fstream::out | std::fstream::binary)); - f.write(src.data(), src.length()); - f.close(); + dumpSource(src, amdOpts); } //Start the compilation