PyCParser
PyCParser copied to clipboard
Real compiler script
A real compiler script with input file options as well as options like -I
, -D
and -o
would be great-
I'm not quite understanding. What do you want to compile it to? This project is not a compiler. It is a parser.
@albertz to a Python script, like cpython_static.py
is.
I've named my take on this runcprog.py. Example invocation ./runcprog.py example1.c example2.c -- arg1 arg2
There's no -I or -D or any other option parsing (just arguments) but as a substitute for the idea of -D you could put "#define"s in a .h file and make that your first argument, for example you might make mydefines.h and do ./runcprog.py mydefines.h code1.c code2.c -- programarg1 programarg2
As for -I support, that's going to require some deeper hacking in cparser.py to have support for searching multiple directories. Right now, readLocalInclude and the helper findIncludeFullFilename are just working relative to current working directory. A possible work around for that is to invoke runcprog.py with paths to every relevant .h file as the first set of arguments: runcprog.py headerneeded1.h /usr/local/include/headerneeded2.h code1.c code2.c -- programarg1 programarg2
Comments before a pull request?
Ah I see. That looks useful.
About the code: I would avoid the itertools
usage, that makes it quite hard to read, and complicated. You could replace that by much shorter code without itertools
. Also not_a_dashdash
can just be inline where you use it, makes it hard to read as well otherwise.
I've also created something for this even before I've opened this issue.
It supports -I
and -D
.
But it's a compiler script, not an interpreter.
Since it's based on the cpython_static.py
generation program (with import
), I'm currently unable to integrate it.
@kaeptmblaubaer1000 Ah, I think I also understand what you have now. This could also be useful.