Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split preprocessor-related classes to different file #16

Open
Sauci opened this issue Jul 18, 2018 · 1 comment
Open

split preprocessor-related classes to different file #16

Sauci opened this issue Jul 18, 2018 · 1 comment

Comments

@Sauci
Copy link
Contributor

Sauci commented Jul 18, 2018

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
}
@inducer
Copy link
Owner

inducer commented Jul 18, 2018

Sure, send a patch--but make sure to keep it backwards compatible (and make it so the now-deprecated location complains with a DeprecationWarning).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants