Created
April 27, 2026 18:29
-
-
Save CypherpunkSamurai/cda754f7c3969042a3365f9acbe6eb2f to your computer and use it in GitHub Desktop.
LLVM Odin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "core:fmt" | |
| import "core:dynlib" | |
| sym_get :: proc(lib: dynlib.Library, name: string) -> rawptr { | |
| addr, f := dynlib.symbol_address(lib, name) | |
| return addr | |
| } | |
| main :: proc() { | |
| lib, ok := dynlib.load_library("C:\\tools\\Odin\\dist\\LLVM-C.dll") | |
| if !ok { | |
| fmt.eprintln("load failed") | |
| return | |
| } | |
| create_ctx := transmute(proc() -> rawptr) sym_get(lib, "LLVMContextCreate") | |
| ctx := create_ctx() | |
| dispose_ctx := transmute(proc(rawptr)) sym_get(lib, "LLVMContextDispose") | |
| dispose_ctx(ctx) | |
| create_mod := transmute(proc(cstring) -> rawptr) sym_get(lib, "LLVMModuleCreateWithName") | |
| mod := create_mod("example") | |
| dispose_mod := transmute(proc(rawptr)) sym_get(lib, "LLVMDisposeModule") | |
| dispose_mod(mod) | |
| print_mod := transmute(proc(rawptr) -> cstring) sym_get(lib, "LLVMPrintModuleToString") | |
| ir := print_mod(mod) | |
| dispose_msg := transmute(proc(cstring)) sym_get(lib, "LLVMDisposeMessage") | |
| dispose_msg(ir) | |
| dynlib.unload_library(lib) | |
| fmt.println("OK") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment