Reputation: 1160
I am looking at a codegen.ml file being used to create LLVM IR. I am unfamilar with Ocaml so just require some clarification
let i32_t = L.i32_type context
and float_t = L.double_type context
let ltype_of_typ = function
A.Int -> i32_t
| A.Float -> float_t
in
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
So for this line
A.Float -> L.const_float (ltype_of_typ t) 0.0
What is the stuff after "->" doing? Is it casting 0.0 to a float?
Upvotes: 0
Views: 112
Reputation: 66808
The code is calling a function L.const_float
with two parameters. The code reads as if it's setting up a global mapping from names to values. Some of the values appear to be representations of fixed floating numbers. Beyond that I can't help you because I'm not familiar with LLVM.
However there are no "type casts" in OCaml. There are a few functions in the standard library that convert between numeric types (int_of_float
for example). But there's no language feature for casting types. OCaml is a strongly typed language, and type casting (as in C or C++) is pretty much a violation of that.
It might be more helpful to ask your question in a forum devoted to LLVM.
Upvotes: 1