qbe icon indicating copy to clipboard operation
qbe copied to clipboard

gcc extension: nested procedures?

Open gtoal opened this issue 3 years ago • 0 comments

This is a feature request, not a bug issue.

You've implemented some gcc extensions in Cproc; and a good use for QBE is as a back-end for compilers (not necessarily C) and other language translators that generate source code as output... I have a use-case which is related - some historical languages that no longer have native compilers can be implemented by source to source translation, for example Algol60 to C ... your back-end is a good option for one of those that would allow a full compiler to be implemented that produced Intel or ARM binaries. The project I'm working on converts another algol-like language into C, but the C has to be GCC with extensions because it is the only C variant (at least that I know of) which supports nested procedures. (Clang doesn't for example, though possibly the LLVM back-end might). If your CProc and QBE back-end supported nested procedures, it could be used in systems like this. Converting languages that use nested procedures without a back-end language that supports them is very very tricky and in several translators the problem is just ignored and source files using that feature don't get translated. Translators like this have two functions: either to convert the old sources into high-level maintainable code in the more modern language; or to use the modern language as an unseen intermediate code on the way to creating binaries, with the expectation that users of the original language will never look at it. With Cproc and gcc's nested procedure extensions we could implement the former, and with QBE we could go direct to the latter.

I'm quite impressed by what I've seen so far of your combined cproc+qbe suite - if it had been around some years ago when we worked on another project that output C code (a static binary translator for 8-bit processors), we would have used it instead. (At the time even LLVM was new and not ready for use in other projects)

Thanks for your consideration whether you add this feature to your wish list or not,

Graham

gtoal avatar Oct 07 '22 03:10 gtoal