Skip to content

split preprocessor-related classes to different file #16

Description

@Sauci

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions