Extracting native code from C

Henrik Gedenryd h.gedenryd at open.ac.uk
Wed Mar 13 17:54:44 UTC 2002


Anthony Hannan wrote:

> Below is a small C program that copies some of its machine code to
> dynamic memory and executes it.  It works on my Linux-i86.  I was
> thinking we could use this technique to dynamically translate bytecodes
> into native code, without using machine-dependent assembly language.

I've toyed with the idea but haven't at all thought of an actual a way for
doing it. This technique would allow us to have a platform-independent JIT
written in Smalltalk. No yucky C++ which seems to be where the JIT guys
spend their lives.

In short: it would be very cool if you pulled it off!

I have a partial evaluator for Squeak that could be used to generate code
more conveniently, and do things like inlining and specialization. It has a
few hitches but does do some cool things. Let me know if you would like to
have the code.

An alternative technique to yours could be to co-opt gcc as a code
generator, if one could break out the relevant part (far smaller than all of
the compiler) and feed it the right kind of input. I don't know if that is
practical at all though.

You really ought to get Ian Piumarta's thoughts on this since he is the guy
who would know these things. (Note that he's not subscribed to the list.)

> would like to find out if this C example works on other platforms.  I
> would appreciate people testing it.  Note, it does use a GNU C
> extension, namely goto expressions.  But we use goto expressions already
> in gnuify.  

Yes but "gnuify" is obviously used in the cases where you do use the gnu
compiler :-)

> Is GNU used/available for most other platforms.  Ie. can we
> base our portability on GNU-C instead of just ANSI-C?

If you came through with a working solution, it wouldn't be unreasonable at
all to swallow this requirement. It would after all be a plugin of sorts
anyway.

Henrik




More information about the Squeak-dev mailing list