inducer / cgen Goto Github PK
View Code? Open in Web Editor NEWC/C++ source generation from an AST
Home Page: http://pypi.python.org/pypi/cgen
License: Other
C/C++ source generation from an AST
Home Page: http://pypi.python.org/pypi/cgen
License: Other
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
}
While trying to modify opesci-fd to use this project's code generation capabilities, there were some classes I would have found helpful but couldn't find them in cgen. I added them to a wrapper and used them in the project. These include a class for IfDef and one for InlineInitializers. If you think they would be helpful to this project, I could submit a pull request here.
Hello, guys,
Is it possible to generate if-else-if structure using cgen?
if (condition_1) declaration_1;
else if (condition_2) declaration_2;
else if (condition_3) declaration_3;
.
.
.
else if (condition_n) declaration_n;
else declaration_default;
Hello all. I'd like to use cgen to create come C++ classes. From what I see that's not supported, correct?
Both
Pointer(ArrayOf(Pointer(POD(np.float32, "xxx")), 2)),
Pointer(Pointer(ArrayOf(POD(np.float32, "yyy"), 2))),
result in
float **xxx[2];
float **yyy[2];
The expected result is
float *(*xxx)[2];
float (**xxx)[2];
I have a cgen.Value("float", "temp")
and an assignemnt, cgen.Assign("temp", "somefunc(1)")
. It will generate the following C code
float temp;
temp = somefunc(1);
How to make the generated C code more nested from cgen.Value and cgen.Assign, such that it will look like:
float temp = somefunc(1);
Hi @inducer, thanks for maintaining the project it's very useful.
Looking at https://pypi.org/project/cgen/#history I don't see the latest release.
I would like to make use of the recently addded ifndef
support.
import cgen as c
test = c.IfNDef("SOME_DEF",[c.Comment("Test1")],[c.Comment("Test2")])
print(test)
When running this code from:
http://pastebin.com/pr15PirN
I get this error.
I would like to generate arithmetic expressions. for example:
float z = -25.f
float x = -(1.5f * 3e5) + (z / 123.f);
What is the idiomatic way to do it with cgen?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.