Re: in memory compiling?

"Basile Starynkevitch \[news\]" <>
15 Apr 2004 20:27:17 -0400

          From comp.compilers

Related articles
in memory compiling? (2004-04-15)
Re: in memory compiling? (Basile Starynkevitch \[news\]) (2004-04-15)
| List of all articles for this month |

From: "Basile Starynkevitch \[news\]" <>
Newsgroups: comp.compilers
Date: 15 Apr 2004 20:27:17 -0400
Organization: - Ours
References: 04-04-038
Keywords: code, practice
Posted-Date: 15 Apr 2004 20:27:17 EDT

Le 15-04-2004, rtischer <> a écrit :
> I need to compile C++ to memory instead of a file. Does anyone know if
> any well-known compilers have an option for code placement?

I don't know of any (open-source) compiler for C++ generating code in
memory. However (at linux on most Unix or Linux system) you could
generate a shared object file .so and use dlopen() to load it

If you accept to use only C and not C++, you can use, on Linux/x86
systems, the tinycc compiler (tcc), which can compile into memory. See for more. Tcc generate machine code vey quickly,
but the generated code is less optimised (and about 10-30% slower)
than what GCC produces (with optimisations enabled).

An alternative could be to use some library generating machine code
into memory. I did use successfully for that purpose the GNU lightning
library (I suggest using the latest CVS snapshot from GNU lightning run on x86, Sparc, PowerPC (all in 32
bits mode).

By the way, C++ is quite complex to compile (even to parse) and
usually requires many #include-d files in practical programs (in
particular, those using templates and other C++ fancy features), so
you won't win much to compile into memory. In other words, why don't
you compile your C++ code into a file?

Please note also that several language implementations
(e.g. CommonLisp as SBCL...) give you the ability to generate machine
code into memory with great ease. Perhaps your C++ requirement could
be softened to something more appropriate for your task..
email: basile<at>starynkevitch<dot>net
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Faïencerie, 92340 Bourg La Reine, France

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.