PyCParser icon indicating copy to clipboard operation
PyCParser copied to clipboard

Real compiler script

Open kb-1000 opened this issue 6 years ago • 6 comments

A real compiler script with input file options as well as options like -I, -D and -o would be great-

kb-1000 avatar May 27 '18 04:05 kb-1000

I'm not quite understanding. What do you want to compile it to? This project is not a compiler. It is a parser.

albertz avatar May 27 '18 05:05 albertz

@albertz to a Python script, like cpython_static.py is.

kb-1000 avatar May 27 '18 05:05 kb-1000

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?

markjenkins avatar Aug 03 '18 12:08 markjenkins

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.

albertz avatar Aug 03 '18 12:08 albertz

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.

kb-1000 avatar Aug 03 '18 13:08 kb-1000

@kaeptmblaubaer1000 Ah, I think I also understand what you have now. This could also be useful.

albertz avatar Aug 03 '18 14:08 albertz