Generating and Executing LLVM IR Code from Java Using Foreign Function & Memory API
By
ingve
The kind of bagel that ruins lesser bagels for you.
Summary
This technical article demonstrates how to use Java's Foreign Function & Memory (FFM) API to generate and execute LLVM IR (Intermediate Representation) code. The author shows how to create a "Hello, World!" program by calling LLVM's C API from Java, generating LLVM IR, and JIT-compiling it to native code. This represents an unexpected approach for Java developers who typically work with Java bytecode, exploring the intersection of Java programming with low-level compiler infrastructure.
Key quotes
· 3 pulledAfter exploring Java bytecode in previous years (2022, 2023, 2024), this year we'll take an unexpected detour for a Java advent: instead of generating Java bytecode, we'll use Java to build and execute LLVM IR, the intermediate language behind compilers like clang.
Using Java's Foreign Function & Memory (FFM) API, we'll call the LLVM C API, generate a 'Hello, World!' program, and even JIT-compile it to native code – all from Java.
The task is simple: create a program that simply prints 'Hello, World!'. But we must do this from Java via LLVM.
You might also wanna read
Tiny C Compiler (TCC) Performance Benchmark: 9x Faster Than GCC
The article presents Tiny C Compiler (TCC), a fast C compiler that demonstrates significantly faster compilation speeds compared to GCC. It
Eurydice: A Rust to C Compiler for Legacy System Integration
The article discusses Eurydice, a Rust to C compiler, exploring the surprising interest in compiling Rust code to C despite Rust's memory sa
Technical Notes and Experience with Fil-C Memory-Safe C/C++ Compiler
The article presents detailed technical notes and experiences with Fil-C, a new memory-safe C/C++ compiler. The author shares their positive
Why Average LLM Use Is Likely Destroying Value in Software Development
The author argues that, contrary to prevailing hype, the average use of Large Language Models (LLMs) is likely destroying value rather than
How AI Accelerated Prototyping: From Idea to Tangible in Record Time
The author reflects on how AI has transformed their prototyping workflow. Previously, the biggest bottleneck was the time needed to scaffold
GitLab 19.0 launches with Secrets Manager, agentic workflows, and self-hosted AI models
GitLab 19.0 has been released, positioning itself as an intelligent orchestration platform for DevSecOps. The release includes expanded secr
bit.ly·23h ago