Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions clang/lib/DPCT/PatternRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ updateExtentionName(const std::string &Input, size_t Next,
auto Extension = clang::dpct::DpctGlobalInfo::getSYCLSourceExtension();
if (Input.compare(Next, strlen(".cpp"), ".cpp") == 0) {
size_t Pos = Next - 1;
for (; Pos > 0 && (isIdentifiedChar(Input[Pos]) || Input[Pos] == '.');
Pos--) {
for (; Pos > 0 && !isWhitespace(Input[Pos]); Pos--) {
}
Pos = Pos == 0 ? 0 : Pos + 1;
std::string SrcFile = Input.substr(Pos, Next + strlen(".cpp") - Pos);
Expand All @@ -420,23 +419,43 @@ updateExtentionName(const std::string &Input, size_t Next,
// In a CMakeLists.txt file, the relative directory path for a source
// file is the location of the CMakeLists.txt file itself

// To get the directory path where CMake script is located
SmallString<512> CMakeDirectory(FileName);
llvm::sys::path::replace_path_prefix(
CMakeDirectory, OutRoot.getCanonicalPath().str() + "/", "");
llvm::sys::path::remove_filename(CMakeDirectory);

std::string CMakeFilePath = CMakeDirectory.c_str();
CMakeFilePath = CMakeFilePath + "/" + SrcFile;
std::string CMakeFilePath;
if (llvm::sys::path::filename(SrcFile) == SrcFile) {
// To get the directory path where CMake script is located
SmallString<512> CMakeDirectory(FileName);
llvm::sys::path::replace_path_prefix(
CMakeDirectory, OutRoot.getCanonicalPath().str() + "/", "");
llvm::sys::path::remove_filename(CMakeDirectory);

CMakeFilePath = CMakeDirectory.c_str();
CMakeFilePath = CMakeFilePath + "/" + SrcFile;
} else {
std::string FileName = llvm::sys::path::filename(SrcFile).str();
SmallString<512> _SrcFile(SrcFile);
llvm::sys::path::remove_dots(_SrcFile, /* remove_dot_dot= */ true);
llvm::sys::path::replace_path_prefix(_SrcFile, "${CMAKE_SOURCE_DIR}/",
"");
llvm::sys::path::remove_filename(_SrcFile);
std::string ParentPath = _SrcFile.c_str();

auto LastDotPos = ParentPath.find_last_of('.');
if (LastDotPos != std::string::npos) {
auto PrexPos = ParentPath.find('/', LastDotPos);
if (PrexPos != std::string::npos)
ParentPath = ParentPath.substr(PrexPos + 1);
}

CMakeFilePath = ParentPath + "/" + FileName;
}
if (llvm::StringRef(File).ends_with(CMakeFilePath)) {
HasCudaSyntax = true;
break;
}
} else {
// For other module files (e.g., .cmake files), just check the
// file names.
if (llvm::sys::path::filename(File) == SrcFile) {
if (llvm::sys::path::filename(File) ==
llvm::sys::path::filename(SrcFile)) {
HasCudaSyntax = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ add_subdirectory(priv)

add_library(nvcv_types SHARED
Image.cpp
${CMAKE_SOURCE_DIR}/priv/foo.cpp.dp.cpp
${CMAKE_SOURCE_DIR}/../infrastructure/Utilities.cpp.dp.cpp
${CMAKE_SOURCE_DIR}/../../infrastructure/bar.cpp.dp.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Replacements:
MainSourceFilesDigest:
- MainSourceFile: '/path/to/src/nvcv_types/priv/Image.cpp'
Digest: 80a9873e8ab8a95f59e7f11682db7690
- MainSourceFile: '/path/to/src/nvcv_types/priv/foo.cpp'
Digest: 80a9873e8ab8a95f59e7f11682db7690
- MainSourceFile: '/path/to/infrastructure/Utilities.cpp'
Digest: 5fba1ea8b69476a153fc01f408e467b8
- MainSourceFile: '/path/to/infrastructure/bar.cpp'
Digest: 4fba1ea8b69476a153fc01f408e467b8
DpctVersion: 19.0.0
MainHelperFileName: ''
USMLevel: ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ add_subdirectory(priv)

add_library(nvcv_types SHARED
Image.cpp
${CMAKE_SOURCE_DIR}/priv/foo.cpp
${CMAKE_SOURCE_DIR}/../infrastructure/Utilities.cpp
${CMAKE_SOURCE_DIR}/../../infrastructure/bar.cpp
)