From 10105394de5f7ffccd84bc39e23fbaf57de7fbfe Mon Sep 17 00:00:00 2001 From: Pierre Oechsel Date: Tue, 8 Feb 2022 11:09:49 +0000 Subject: [PATCH] flambda-backend: Use C++ name mangling convention (#483) Co-authored-by: basimkhajwal Co-authored-by: Mark Shinwell --- testsuite/tests/asmcomp/func_sections.run | 2 +- utils/misc.ml | 41 +++++++++++++++++++++++ utils/misc.mli | 9 +++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/testsuite/tests/asmcomp/func_sections.run b/testsuite/tests/asmcomp/func_sections.run index a9323be005f9..cf1fe58570e5 100755 --- a/testsuite/tests/asmcomp/func_sections.run +++ b/testsuite/tests/asmcomp/func_sections.run @@ -7,4 +7,4 @@ ${program} # now check the assembly file produced during compilation asm=${test_build_directory}/func_sections.s -grep ".section .text.caml.camlFunc_sections__" "$asm" | wc -l | tr -d ' ' | sed '/^$/d' +grep -E ".section .text.caml.(camlFunc_sections__|_ZN13Func_sections)" "$asm" | wc -l | tr -d ' ' | sed '/^$/d' diff --git a/utils/misc.ml b/utils/misc.ml index 8182777c60ae..d34d19b30b23 100644 --- a/utils/misc.ml +++ b/utils/misc.ml @@ -97,6 +97,8 @@ let rec split_last = function module Stdlib = struct module List = struct + include List + type 'a t = 'a list let rec compare cmp l1 l2 = @@ -227,6 +229,45 @@ module Stdlib = struct let print ppf t = Format.pp_print_string ppf t + + let begins_with ?(from = 0) str ~prefix = + let rec helper idx = + if idx < 0 then true + else + String.get str (from + idx) = String.get prefix idx && helper (idx-1) + in + let n = String.length str in + let m = String.length prefix in + if n >= from + m then helper (m-1) else false + + let split_on_string str ~split_on = + let n = String.length str in + let m = String.length split_on in + let rec helper acc last_idx idx = + if idx = n then + let cur = String.sub str last_idx (idx - last_idx) in + List.rev (cur :: acc) + else if begins_with ~from:idx str ~prefix:split_on then + let cur = String.sub str last_idx (idx - last_idx) in + helper (cur :: acc) (idx + m) (idx + m) + else + helper acc last_idx (idx + 1) + in + helper [] 0 0 + + let split_on_chars str ~split_on:chars = + let rec helper chars_left s acc = + match chars_left with + | [] -> s :: acc + | c :: cs -> + List.fold_right (helper cs) (String.split_on_char c s) acc + in + helper chars str [] + + let split_last_exn str ~split_on = + let n = String.length str in + let ridx = String.rindex str split_on in + String.sub str 0 ridx, String.sub str (ridx + 1) (n - ridx - 1) end external compare : 'a -> 'a -> int = "%compare" diff --git a/utils/misc.mli b/utils/misc.mli index 53e9d844f795..beb0a3817a83 100644 --- a/utils/misc.mli +++ b/utils/misc.mli @@ -173,6 +173,15 @@ module Stdlib : sig val print : Format.formatter -> t -> unit val for_all : (char -> bool) -> t -> bool + + val begins_with : ?from:int -> string -> prefix:string -> bool + + val split_on_string : string -> split_on:string -> string list + + val split_on_chars : string -> split_on:char list -> string list + + (** Splits on the last occurrence of the given character. *) + val split_last_exn : string -> split_on:char -> string * string end external compare : 'a -> 'a -> int = "%compare"