[m-users.] Link-time optimization
zoltan.somogyi at runbox.com
Sun Jun 14 02:21:23 AEST 2020
2020-06-13 12:24 GMT+10:00 Peter Wang<novalazy at gmail.com>:
> On Fri, 12 Jun 2020 22:27:28 +0200 Massimo Dentico <m.dentico at virgilio.it> wrote:
>> b. How much effort would be needed to modify the Mercury compiler
>> (specifically the back-end that produces high-level C code)
>> to produce a single stand-alone C file? That is, a single source file
>> easy to include in other C projects, which has *only* the necessary
>> machinery from the run-time library and refers to C standard
>> libraries only, with an option to avoid them too.
> A lot of effort.
As Peter says, with a lot of effort, you could implement what you propose.
However, the result will very likely *not* be all that useful. Putting all
the C code generated by the Mercury compiler into a single .c file
will generate a huge .c file for any Mercury program of a nontrivial size,
especially when compiled in a debug grade. This will mean that you
wouldn't be able to compile that .c file with any C compiler options
that call for the use of any algorithm whose complexity is O(n^2) or
worse in the number of functions in the file. The last time I looked,
this meant that even -O2 was off the table (though admittedly
that was more than a decade ago). So the resulting executable
code may be compact, but would also be quite slow.
More information about the users