从 C 源代码到 Java 字节码?

发布于 2024-07-11 23:05:24 字数 1542 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岛徒 2024-07-18 23:05:25

我相信有些项目已经尝试过这样做,但是如果没有关于什么可以访问什么的一些相当严格的限制,就没有办法处理指针(本质上它们必须转换为数组索引和分配的数组而不是内存)

如果你有 C 没有过于依赖指针,并且您希望将其放入 JVM 中,您可能只需将其转换为 Java 即可——应该很容易,而且性能应该不会太差。 C 在大多数领域仍然比 Java 强约 2 倍,有些领域更差,在一些领域 Java 实际上击败了 C(其中之一是堆内存管理),但与大多数其他语言(至少是解释型语言)相比,java 和 c 是快 100 倍,因此从这个角度来看,它们之间的差异毫无意义。

I believe some projects have attempted this, but there is just no way to deal with pointers without some pretty severe restrictions about what can access what (essentially they have to be converted into array indexes and arrays allocated instead of memory)

If you have C without too much reliance on pointers, and you want it into the JVM, you might just convert it to Java--should be pretty easy and the performance shouldn't be too bad. C still beats Java in most areas by about 2x with some areas much worse and in a few areas Java actually beats C (heap memory management, for one), but compared to most other languages (interpreted ones at least), java and c are 100x faster, so the difference between them is pretty meaningless from that point of view.

够运 2024-07-18 23:05:25

尝试一下 C2J 软件......

在 google 中输入 c 到 java 翻译器。您将获得下载链接

try C2J software................

type c to java translator in google .you will get the link to download

一人独醉 2024-07-18 23:05:24

作为 Cibyl 的作者,我可能会有偏见。 无论如何,我查看了 axiomatic C 编译器生成的 java 字节码,效率不高。 NestedVM 和 Cibyl 的工作原理都是编译 MIPS 二进制文件,然后将二进制文件转换为 Java 字节码。 它的效率出奇的高,主要问题是 8 字节和 16 字节值的内存访问(需要分多个步骤完成)。

NestedVM 和 Cibyl 的性能特征略有不同,Cibyl 通常对于整数密集型工作负载更快,而 NestedVM 可以更好地处理浮点数和双精度数。 这是因为 Cibyl 使用 GCC 软浮点支持(尽管使用“真正的”Java 字节码浮点指令),而 NestedVM 转换 MIPS FPU 指令。

Cibyl 也更适合 J2ME 环境,尽管它肯定也可以在其他平台上使用。 我的猜测是,使用它们中的任何一个都会比使用 Axiomatic C 编译器更幸运。

Being the author of Cibyl, I might be biased here. Anyway, I've looked at the java bytecode generated by the axiomatic C compiler, and it is not efficient. NestedVM and Cibyl both works by compiling MIPS binaries and then translating the binary into Java bytecode. It's surprisingly efficient, with the main problem being memory access of 8- and 16-byte values (which needs to be done in multiple steps).

NestedVM and Cibyl have slightly different performance characteristics, with Cibyl typically being faster for integer-heavy workloads whereas NestedVM handles floats and doubles better. This is because Cibyl uses GCC soft-float support (though using "real" Java bytecode floating point instructions) while NestedVM translates MIPS FPU instructions.

Cibyl is also more targeted to J2ME environments, although it's definately useable on other platforms as well. My guess is that you would have more luck with either of them than with the Axiomatic C compiler.

溺孤伤于心 2024-07-18 23:05:24

这不完全是您所要求的,但 Cibyl 转换编译 C 程序转换为 JVM 字节码。 它与 NestedVM (您提到的)的想法相同,但对于您的任务来说可能会更快,因为它是一个独立的实现。

It's not exactly what you asked for, but Cibyl converts compiled C programs into JVM bytecode. It's the same idea as NestedVM (which you mentioned) but might be faster for your task being as how it's an independent implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文