cgen
cgen copied to clipboard
split preprocessor-related classes to different file
with the current file structure, it is not possible to implement the preprocessor #if statement, as it would overwrite (or be overwritten by) the C if () statement.
I would propose to update the file structure to:
cgen
+-- cgen
+-- __init__.py
+-- cuda.py
+-- ispc.py
+-- mapper.py
+-- opencl.py
+-- preprocessor
+-- __init__.py
and implement the preprocessor #if (and others preprocessor statements?) in the file cgen/preprocessor/__init__.py.
this would provide access to the preprocessor functionalities like this:
import cgen as c
import cgen.preprocessor as pp
func = c.FunctionBody(
c.FunctionDeclaration(c.Const(c.Pointer(c.Value("char", "greet"))), []),
c.Block([
pp.If('(a == 0)',
[
c.If('b == 0', c.Block([
c.Statement('return "hello world"')
]))
],
[])
])
)
print(func)
and will output something like:
char const *greet()
{
#if (a == 0)
if (b == 0)
{
return "hello world";
}
#endif
}
Sure, send a patch--but make sure to keep it backwards compatible (and make it so the now-deprecated location complains with a DeprecationWarning).