I am trying to find out how Cython compiles .pyx into .cpp files, and how to find the exact piece of C++ translation of my .pyx file.
My file is a simple helloworld.pyx file
print("Hello world")
I use my setup.py as follows from the official Cython guide, which is as follows:
from Cython.Build import cythonize
extensions = [
Extension(
"helloworld",
sources=["helloworld.pyx"],
language="c++"
),
]
setup(ext_modules = cythonize(extensions))
After running python3 setup.py build_ext --inplace
This very nicely produces both a .cpp and .so file. However, I get approximately 3000 lines of code in my .cpp file, and most of it are definitions and the like. I was rather happy when I saw that the file contained the following:
/* Implementation of 'helloworld' */
static const char __pyx_k_end[] = "end";
static const char __pyx_k_file[] = "file";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_Hello_world[] = "Hello world";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static PyObject *__pyx_kp_s_Hello_world;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_test;
/* Late includes */
However, this is not valid .cpp. Is it possible to generate valid C++ code in the process of compilation and output this piece of code somehow? I am not able to copy the entire file, as it is too long, sadly.
EDIT:
A very concrete example of what I wish to achieve is the exact things these guys are doing: Generating SIMD instructions from Cython code
They write Cython, use the command as I, and then get some clean C code which is compilable.