I'm trying to implement statically typed language with user defined types using LLVM and OCaml, but I don't know how to actually add newtype definition into a LLVM module.
I've looked into OCaml documentation and haven't found any function for that. I've tried answer from LLVM: Defining a new type via OCaml bindings, but it doesn't work.
Example code that I've tried:
let c = Llvm.create_context () in
let m = Llvm.create_module c "MainModule" in
let llar = [| Llvm.i16_type c; Llvm.float_type c; |] in
let value_t = Llvm.struct_type c llar in
ignore (Llvm.declare_global value_t "value_t" m);
let llvalue_t = Llvm.named_struct_type c "value_t" in
Llvm.struct_set_body llvalue_t llar true;
ignore (Llvm.struct_type c llar);
Compiled output:
; ModuleID = 'MainModule'
source_filename = "MainModule"
@value_t = external global { i16, float }