Shisui
Shisui

Reputation: 1160

What is this Ocaml code written to generate LLVM IR doing?

I am new to Ocaml and don't understand what this block of code is doing

  let global_vars : L.llvalue StringMap.t =
    let global_var m (t, n) = 
      let init = match t with
          A.Float -> L.const_float (ltype_of_typ t) 0.0
        | _ -> L.const_int (ltype_of_typ t) 0
      in StringMap.add n (L.define_global n init the_module) m in
    List.fold_left global_var StringMap.empty globals in

Specifically what does StringMap.t do? what is t here? What does "global_vars : L.llvalue StringMap.t" do?

Upvotes: 1

Views: 250

Answers (1)

octachron
octachron

Reputation: 18892

The syntactic form x: typ is a type annotation which is restricting the type of x to a type that can be unified with typ.

StringMap.t is a type named t defined in the module StringMap.

Upvotes: 4

Related Questions