编译成java字节码(不使用Java)

2022-01-17 00:00:00 bytecode compiler-construction java

我的编译器类正在创建一种我们打算编译为 Java 字节码的语言.我们已经取得了很大进展,并且已经接近生成代码的时间了.

My compilers class is creating a language that we intend to compile to Java Bytecode. We have made plenty of progress and are nearing the time where it's time for code generation.

我们在查找有关如何从我们的编译器创建 .class 文件的信息时遇到问题.你有什么资源可以给我们一些帮助吗?我们已经有很多关于指令集的文档,但是需要关于如何直接填写类文件/十六进制编写的信息.

We are having problems locating information on how to create .class files from our compiler. Do you have any resources that can give us some assistance? We already have plenty of documentation on the instruction set, but need information on how to directly fill out the class file/the writing of hex.

我们不需要反编译 .class 文件的信息或建议.

We do not need information or suggestions on decompiling the .class files.

即使是从头开始写出 .class 文件的简单示例也非常棒.

Even a simple example of writing out a .class file from scratch would be excellent.

JVM 规范不是我们所追求的.我们真正需要的是示例或演练.

The JVM spec is not what we're after. What we really need is an example or a walkthrough.

推荐答案

VM 规范:类文件格式 和 Java 虚拟机指令集 应该这样做.

The VM Spec: The Class File Format and the The Java Virtual Machine Instruction Set should do it.

您可以查看字节码工程库 (BCEL) 以获得一些灵感以及 Findbugs(它必须阅读/理解类文件).

You might look at the Byte Code Engineering Library (BCEL) for some inspiration as well as Findbugs (it has to read/understand class files).

相关文章