https://github.com/element39/bun-llvm
🍔 use LLVM with bun effortlessly
https://github.com/element39/bun-llvm
bindings bun c cpp ffi go ir javascript llvm llvm-bindings rust typescript zig
Last synced: 3 months ago
JSON representation
🍔 use LLVM with bun effortlessly
- Host: GitHub
- URL: https://github.com/element39/bun-llvm
- Owner: element39
- License: mit
- Created: 2025-07-26T21:52:55.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-07-27T12:27:34.000Z (8 months ago)
- Last Synced: 2025-07-27T14:41:13.288Z (8 months ago)
- Topics: bindings, bun, c, cpp, ffi, go, ir, javascript, llvm, llvm-bindings, rust, typescript, zig
- Language: TypeScript
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🍔 bun-llvm
> ` use LLVM with bun effortlessly `
```ts
import LLVM from "./llvm";
function main() {
// initialize LLVM
const ctx = new LLVM.Context();
const mod = new LLVM.Module("demo", ctx);
const builder = new LLVM.IRBuilder(ctx);
// define types
const i32 = LLVM.Type.int32(ctx);
const fnType = new LLVM.FunctionType([i32, i32], i32);
// {} are used to separate scopes (optional)
{
// create the function
const fn = mod.createFunction("add", fnType, { linkage: LLVM.Linkage.External });
const entry = fn.addBlock("entry");
builder.insertInto(entry);
{
// get parameters & add them
const [a, b] = fn.getArgs();
const sum = builder.add(a, b);
// return the result
builder.ret(sum);
}
// make sure the function is valid
fn.verify();
}
// verify the module
mod.verify();
// output IR
console.log(mod.toString());
}
main();
```