Skip to content

Commit

Permalink
Expose CUDA function attributes to the C interface.
Browse files Browse the repository at this point in the history
Until now all CUDA-specific attributes were represented with
CXCursor_UnexposedAttr; now they are actually implemented, including the Python
bindings.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209767 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eliben committed May 28, 2014
1 parent 5ff1d8a commit f722606
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ def __repr__(self):
CursorKind.PURE_ATTR = CursorKind(409)
CursorKind.CONST_ATTR = CursorKind(410)
CursorKind.NODUPLICATE_ATTR = CursorKind(411)
CursorKind.CUDACONSTANT_ATTR = CursorKind(412)
CursorKind.CUDADEVICE_ATTR = CursorKind(413)
CursorKind.CUDAGLOBAL_ATTR = CursorKind(414)
CursorKind.CUDAHOST_ATTR = CursorKind(415)

###
# Preprocessing
Expand Down
8 changes: 6 additions & 2 deletions include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2168,8 +2168,12 @@ enum CXCursorKind {
CXCursor_PureAttr = 409,
CXCursor_ConstAttr = 410,
CXCursor_NoDuplicateAttr = 411,
CXCursor_LastAttr = CXCursor_NoDuplicateAttr,

CXCursor_CUDAConstantAttr = 412,
CXCursor_CUDADeviceAttr = 413,
CXCursor_CUDAGlobalAttr = 414,
CXCursor_CUDAHostAttr = 415,
CXCursor_LastAttr = CXCursor_CUDAHostAttr,

/* Preprocessing */
CXCursor_PreprocessingDirective = 500,
CXCursor_MacroDefinition = 501,
Expand Down
16 changes: 16 additions & 0 deletions test/Index/attributes-cuda.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: c-index-test -test-load-source all -x cuda %s | FileCheck %s

__attribute__((device)) void f_device();
__attribute__((global)) void f_global();
__attribute__((constant)) int* g_constant;
__attribute__((host)) void f_host();


// CHECK: attributes-cuda.cu:3:30: FunctionDecl=f_device:3:30
// CHECK-NEXT: attributes-cuda.cu:3:16: attribute(device)
// CHECK: attributes-cuda.cu:4:30: FunctionDecl=f_global:4:30
// CHECK-NEXT: attributes-cuda.cu:4:16: attribute(global)
// CHECK: attributes-cuda.cu:5:32: VarDecl=g_constant:5:32 (Definition)
// CHECK-NEXT: attributes-cuda.cu:5:16: attribute(constant)
// CHECK: attributes-cuda.cu:6:28: FunctionDecl=f_host:6:28
// CHECK-NEXT: attributes-cuda.cu:6:16: attribute(host)
8 changes: 8 additions & 0 deletions tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3879,6 +3879,14 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("attribute(const)");
case CXCursor_NoDuplicateAttr:
return cxstring::createRef("attribute(noduplicate)");
case CXCursor_CUDAConstantAttr:
return cxstring::createRef("attribute(constant)");
case CXCursor_CUDADeviceAttr:
return cxstring::createRef("attribute(device)");
case CXCursor_CUDAGlobalAttr:
return cxstring::createRef("attribute(global)");
case CXCursor_CUDAHostAttr:
return cxstring::createRef("attribute(host)");
case CXCursor_PreprocessingDirective:
return cxstring::createRef("preprocessing directive");
case CXCursor_MacroDefinition:
Expand Down
4 changes: 4 additions & 0 deletions tools/libclang/CXCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ static CXCursorKind GetCursorKind(const Attr *A) {
case attr::Pure: return CXCursor_PureAttr;
case attr::Const: return CXCursor_ConstAttr;
case attr::NoDuplicate: return CXCursor_NoDuplicateAttr;
case attr::CUDAConstant: return CXCursor_CUDAConstantAttr;
case attr::CUDADevice: return CXCursor_CUDADeviceAttr;
case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr;
case attr::CUDAHost: return CXCursor_CUDAHostAttr;
}

return CXCursor_UnexposedAttr;
Expand Down

0 comments on commit f722606

Please sign in to comment.