Welcome to cgen’s documentation!¶

cgen offers a simple abstract syntax tree for C and related languages (C++/CUDA/OpenCL) to allow structured code generation from Python.

Here’s an example, to give you an impression:

import cgen as c

func = c.FunctionBody(
    c.FunctionDeclaration(c.Const(c.Pointer(c.Value("char", "greet"))), []),
        c.Statement('return "hello world"')


This prints the following:

char const *greet()
  return "hello world";

cgen deliberately does not worry about expression trees. Its sister package pymbolic can help you build those.

Indices and tables¶