Skip to content

Commit 3552db6

Browse files
authored
flambda-backend: Factor out duplicated code in cmm_helpers (#1822)
1 parent caf938f commit 3552db6

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

asmcomp/cmm_helpers.ml

+12-21
Original file line numberDiff line numberDiff line change
@@ -947,10 +947,11 @@ let unique_arity_identifier (arity : Cmm.machtype list) =
947947
then Int.to_string (List.length arity)
948948
else String.concat "_" (List.map machtype_identifier arity)
949949

950+
let result_layout_suffix result =
951+
match result with [| Val |] -> "" | _ -> "_R" ^ machtype_identifier result
952+
950953
let send_function_name arity result (mode : Lambda.alloc_mode) =
951-
let res =
952-
match result with [| Val |] -> "" | _ -> "_R" ^ machtype_identifier result
953-
in
954+
let res = result_layout_suffix result in
954955
let suff = match mode with Alloc_heap -> "" | Alloc_local -> "L" in
955956
"caml_send" ^ unique_arity_identifier arity ^ res ^ suff
956957

@@ -1018,9 +1019,7 @@ let make_checkbound dbg = function
10181019
(* Record application and currying functions *)
10191020

10201021
let apply_function_name arity result (mode : Lambda.alloc_mode) =
1021-
let res =
1022-
match result with [| Val |] -> "" | _ -> "_R" ^ machtype_identifier result
1023-
in
1022+
let res = result_layout_suffix result in
10241023
let suff = match mode with Alloc_heap -> "" | Alloc_local -> "L" in
10251024
"caml_apply" ^ unique_arity_identifier arity ^ res ^ suff
10261025

@@ -1031,25 +1030,23 @@ let apply_function_sym arity result mode =
10311030
Compilenv.need_apply_fun arity result mode;
10321031
apply_function_name arity result mode
10331032

1033+
let tuplify_function_name arity result =
1034+
"caml_tuplify" ^ Int.to_string arity ^ result_layout_suffix result
1035+
10341036
let curry_function_sym function_kind arity result =
10351037
Compilenv.need_curry_fun function_kind arity result;
10361038
match function_kind with
10371039
| Lambda.Curried { nlocal } ->
10381040
"caml_curry"
10391041
^ unique_arity_identifier arity
1040-
^ (match result with
1041-
| [| Val |] -> ""
1042-
| _ -> "_R" ^ machtype_identifier result)
1042+
^ result_layout_suffix result
10431043
^ if nlocal > 0 then "L" ^ Int.to_string nlocal else ""
1044-
| Lambda.Tupled -> (
1044+
| Lambda.Tupled ->
10451045
if List.exists (function [| Val |] -> false | _ -> true) arity
10461046
then
10471047
Misc.fatal_error
10481048
"tuplify_function is currently unsupported if arity contains non-values";
1049-
"caml_tuplify"
1050-
^ Int.to_string (List.length arity)
1051-
^
1052-
match result with [| Val |] -> "" | _ -> "_R" ^ machtype_identifier result)
1049+
tuplify_function_name (List.length arity) result
10531050

10541051
(* Big arrays *)
10551052

@@ -2254,13 +2251,7 @@ let tuplify_function arity return =
22542251
else get_field_gen Asttypes.Mutable (Cvar arg) i (dbg ())
22552252
:: access_components(i+1)
22562253
in
2257-
let fun_name =
2258-
"caml_tuplify" ^ Int.to_string arity
2259-
^
2260-
match return with
2261-
| [| Val |] -> ""
2262-
| _ -> "_R" ^ machtype_identifier return
2263-
in
2254+
let fun_name = tuplify_function_name arity return in
22642255
let fun_dbg = placeholder_fun_dbg ~human_name:fun_name in
22652256
Cfunction
22662257
{fun_name;

0 commit comments

Comments
 (0)