Generate Bytecode from an AST
Jonathan Gibbons
jonathan.gibbons at oracle.com
Tue Jun 24 17:56:39 UTC 2014
On 06/21/2014 09:53 PM, Daisy Nkweteyim wrote:
> Heelo everyone,
>
> I saw a blog post on Generating Byte Code by Building AST's
> <https://blogs.oracle.com/yj/entry/yet_another_way_to_hack> which
> describes how bytecode can be generated from an AST. It involves
> changing the javac source code to bypass the parsing phase and
> generate bytecode which is produced when one passes his/her own AST.
> But I would ike to do this in a better way.
>
> Is it possible to actually generate a .class file from an AST using
> javac without changing the javac source code and without using a
> framework?
>
> Thanks for your time. Any help is greatly appreciated.
>
> Regards,
>
> --
> /Daisy Nkweteyim
> Cameroon/
>
Right now, the recommended solution is to print the AST to a string and
to compile the string. This can all be done in memory -- there is no
need to write the text to the filesystem as an interim step.
Currently, there is no way to compile an arbitrary tree created by the
user using arbitrary implementions of com.sun.source.tree.*.
-- Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20140624/76f9eac2/attachment-0001.html>
More information about the compiler-dev
mailing list