inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 28 forks source link

Small Code Error when trying to parse OpenCL #5

Closed openclman closed 11 years ago

openclman commented 11 years ago

Hello,

I tried to use the OpenCL parser but there were some small mistakes in the code. In ext_c_parser.py in the class OpenCLCParser, the first line reads from pycparserext.ext_c_lexer import GnuCLexer as lexer_class

it should be ---------------------------------------------v v from pycparserext.ext_c_lexer import OpenCLCLexer as lexer_class

After this it complains about not having the 'ASM' token so I added 'asm' to the lexer keywords in ext_c_lexer.py. That is: --------------------------------------------------------- v v add_lexer_keywords(GnuCLexer, [ 'attribute', 'asm', 'asm', 'asm', '__typeof', 'real', 'imag', 'builtin_types_compatible_p', 'const', 'restrict', 'inline', 'inline', 'extension', 'asm'])

_CL_KEYWORDS = ['kernel', 'constant', 'global', 'local', 'private', "read_only", "write_only", "read_write"] add_lexer_keywords(OpenCLCLexer, [ 'attribute', 'asm', '**asm', 'asm']

Also, I wrote a small OpenCL test program:

def test_OpenCL(): from pycparserext.ext_c_parser import OpenCLCParser, c_ast src = """ kernel void zeroMatrix(global float _A, int n, __global float * B) { int i = get_global_id(0); for (int k=0; k<n; k++) A[i_n+k] = 0; } """

p = OpenCLCParser()
ast = p.parse(src)
ast.show()

from pycparserext.ext_c_generator import OpenCLCGenerator
print OpenCLCGenerator().visit(ast)

test_OpenCL()

Perhaps you could incorporate these changes.

Best Regards, Jacob

inducer commented 11 years ago

Thanks for your contribution! I've also released 2013.1, partially in response to this.