Skip to content

Commit

Permalink
define declare_const_result type
Browse files Browse the repository at this point in the history
  • Loading branch information
alanechang committed Nov 29, 2023
1 parent f5aa651 commit 676c3f4
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions middle_end/flambda2/from_lambda/closure_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type close_functions_result =
| Lifted of (Symbol.t * Env.value_approximation) Function_slot.Lmap.t
| Dynamic of Set_of_closures.t * Env.value_approximation Function_slot.Map.t

type declare_const_result =
| Field of Field_of_static_block.t
| Unboxed_float of Numeric_types.Float_by_bit_pattern.t

let manufacture_symbol acc proposed_name =
let acc, linkage_name =
if Flambda_features.Expert.shorten_symbol_names ()
Expand Down Expand Up @@ -88,25 +92,21 @@ let register_const0 acc constant name =
acc, symbol
| symbol -> acc, symbol

let register_const acc constant name :
Acc.t * [> `Field of Field_of_static_block.t] * string =
let register_const acc constant name : Acc.t * declare_const_result * string =
let acc, symbol = register_const0 acc constant name in
acc, `Field (Symbol symbol), name
acc, Field (Symbol symbol), name

let rec declare_const acc (const : Lambda.structured_constant) :
Acc.t
* [ `Field of Field_of_static_block.t
| `Unboxed_float of Numeric_types.Float_by_bit_pattern.t ]
* string =
Acc.t * declare_const_result * string =
let module SC = Static_const in
match const with
| Const_base (Const_int c) ->
acc, `Field (Tagged_immediate (Targetint_31_63.of_int c)), "int"
acc, Field (Tagged_immediate (Targetint_31_63.of_int c)), "int"
| Const_base (Const_char c) ->
acc, `Field (Tagged_immediate (Targetint_31_63.of_char c)), "char"
acc, Field (Tagged_immediate (Targetint_31_63.of_char c)), "char"
| Const_base (Const_unboxed_float c) ->
let c = Numeric_types.Float_by_bit_pattern.create (float_of_string c) in
acc, `Unboxed_float c, "unboxed_float"
acc, Unboxed_float c, "unboxed_float"
| Const_base (Const_string (s, _, _)) ->
register_const acc (SC.immutable_string s) "immstring"
| Const_base (Const_float c) ->
Expand Down Expand Up @@ -149,8 +149,8 @@ let rec declare_const acc (const : Lambda.structured_constant) :
(fun acc c ->
let acc, f, _ = declare_const acc c in
match f with
| `Field f -> acc, f
| `Unboxed_float _ ->
| Field f -> acc, f
| Unboxed_float _ ->
Misc.fatal_error
"Unboxed floats are not allowed inside of Const_block")
acc consts
Expand All @@ -163,19 +163,19 @@ let rec declare_const acc (const : Lambda.structured_constant) :
let close_const0 acc (const : Lambda.structured_constant) =
let acc, const, name = declare_const acc const in
match const with
| `Field (Tagged_immediate i) ->
| Field (Tagged_immediate i) ->
( acc,
Simple.const (Reg_width_const.tagged_immediate i),
name,
Flambda_kind.With_subkind.tagged_immediate )
| `Unboxed_float f ->
| Unboxed_float f ->
( acc,
Simple.const (Reg_width_const.naked_float f),
name,
Flambda_kind.With_subkind.naked_float )
| `Field (Symbol s) ->
| Field (Symbol s) ->
acc, Simple.symbol s, name, Flambda_kind.With_subkind.any_value
| `Field (Dynamically_computed _) ->
| Field (Dynamically_computed _) ->
Misc.fatal_errorf "Declaring a computed constant %s" name

let close_const acc const =
Expand Down

0 comments on commit 676c3f4

Please sign in to comment.