简体   繁体   English

从中间代码到Java字节码(龙书)

[英]From intermediate code to Java bytecode (dragon book)

I'm enrolled in a compilers course, using the "dragon book" as textbook. 我参加了编译器课程,使用“龙书”作为教科书。 It gives instructions on how to convert the intermediate code generated by its compiler to an object language, assembly. 它给出了有关如何将其编译器生成的中间代码转换为目标语言,程序集的说明。

My question is: where can I find instructions to convert an intermediate code in the 3-address format to java bytecode, for the same grammar used in the book? 我的问题是:对于本书中使用的相同语法,在哪里可以找到将3位地址格式的中间代码转换为Java字节码的说明?

Textbook site: http://dragonbook.stanford.edu/index.html#courses 教科书网站: http : //dragonbook.stanford.edu/index.html#courses

If you want to know how to create a binary Java classfile yourself, there's no better resource than the official JVM specification . 如果您想知道如何自己创建二进制Java类文件,没有比官方JVM规范更好的资源了。

If you want to write a classfile in a human readable textual format, there are various assemblers available: Krakatau , Jasmin , and Lilac among others. 如果要以人类可读的文本格式编写类文件,则可以使用各种汇编程序: KrakatauJasminLilac等。 Note that Jasmin is old and largely unmaintained, though the Sable Research Group maintains a fork of it for use with their own tools. 请注意,尽管Sable Research Group保留了Jasmin的一个分支以供其自己的工具使用,但Jasmin却很旧,几乎没有维护。

I have implemented a translator that takes the three-address intermediate code, generated by the Dragon Book implementation of the front end of a compiler, and converts it to a Java bytecodes with a syntax similar to Jasmin . 我实现了一个转换器,该转换器采用由编译器前端的Dragon Book实现生成的三地址中间代码,并将其转换为Java字节码,其语法类似于Jasmin Then it uses Krakatau to assemble it into a classfile executable through the JVM. 然后,它使用Krakatau将其组装成可通过JVM执行的类文件。

You can check my implementation at https://github.com/joaofbsm/smallL/tree/master/code/translator . 您可以在https://github.com/joaofbsm/smallL/tree/master/code/translator检查我的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM