[cfe-dev] AST and Sema: find out if a variable with a name is visible in a particular scope

GabrieleCocco cocco at di.unipi.it
Mon Oct 22 06:44:58 PDT 2012


Hi to everybody.
I'm trying to build a source to source transformation in Clang. In
particular, I'm trying to generate OpenCL host-side code (create platform,
context, buffers, transfer data to and from the kernel, etc.) using
informations stored in the AST and custom attributes.
My target is to allow programmers to write kernels as C functions (relying
on OpenCL syntax support) and to avoid to code a big part of the host-side
code needed to set up devices, contexts, transfer data and so on. The tool
I'm developing should:

1) Lift away the functions marked with "kernel" attribute (call the kernel
functions) from the translation unit, putting them into .cl files
2) Substitute each kernel function with a "wrapper function" that does the
appropriate invocation of the OpenCL kernel (setKernelArg,
enqueueNDRangeKernel, ...) 
3) Replace each invocation of a kernel function with an invocation of the
corresponding wrapper function, injecting the appropriate OpenCL API
functions (create buffer, write buffer, read buffer after the call) before
and after the call.

The problem I'm facing by now is pretty simple, but I'm not sure about the
best way to solve it. Since I'm injecting new declarations, such as
"cl_context cntx = clCreateContext(....)", I've to deal with variable names
potentially already defined somewhere and visible in the scope where I'm
injecting code.
Can you suggest me a way to find out if a var name is visible in a
particular scope and/or a way to produce (if clang provides a tool/api to do
that) an unique ID in a particular scope?

Thank you very much! 



--
View this message in context: http://clang-developers.42468.n3.nabble.com/AST-and-Sema-find-out-if-a-variable-with-a-name-is-visible-in-a-particular-scope-tp4027638.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list