Skip to content

Commit 1010539

Browse files
poechselbasimkhajwalmshinwell
authored
flambda-backend: Use C++ name mangling convention (ocaml-flambda#483)
Co-authored-by: basimkhajwal <basimkhajwal@gmail.com> Co-authored-by: Mark Shinwell <mshinwell@pm.me>
1 parent 81881bb commit 1010539

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

testsuite/tests/asmcomp/func_sections.run

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ${program}
77

88
# now check the assembly file produced during compilation
99
asm=${test_build_directory}/func_sections.s
10-
grep ".section .text.caml.camlFunc_sections__" "$asm" | wc -l | tr -d ' ' | sed '/^$/d'
10+
grep -E ".section .text.caml.(camlFunc_sections__|_ZN13Func_sections)" "$asm" | wc -l | tr -d ' ' | sed '/^$/d'

utils/misc.ml

+41
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ let rec split_last = function
9797

9898
module Stdlib = struct
9999
module List = struct
100+
include List
101+
100102
type 'a t = 'a list
101103

102104
let rec compare cmp l1 l2 =
@@ -227,6 +229,45 @@ module Stdlib = struct
227229

228230
let print ppf t =
229231
Format.pp_print_string ppf t
232+
233+
let begins_with ?(from = 0) str ~prefix =
234+
let rec helper idx =
235+
if idx < 0 then true
236+
else
237+
String.get str (from + idx) = String.get prefix idx && helper (idx-1)
238+
in
239+
let n = String.length str in
240+
let m = String.length prefix in
241+
if n >= from + m then helper (m-1) else false
242+
243+
let split_on_string str ~split_on =
244+
let n = String.length str in
245+
let m = String.length split_on in
246+
let rec helper acc last_idx idx =
247+
if idx = n then
248+
let cur = String.sub str last_idx (idx - last_idx) in
249+
List.rev (cur :: acc)
250+
else if begins_with ~from:idx str ~prefix:split_on then
251+
let cur = String.sub str last_idx (idx - last_idx) in
252+
helper (cur :: acc) (idx + m) (idx + m)
253+
else
254+
helper acc last_idx (idx + 1)
255+
in
256+
helper [] 0 0
257+
258+
let split_on_chars str ~split_on:chars =
259+
let rec helper chars_left s acc =
260+
match chars_left with
261+
| [] -> s :: acc
262+
| c :: cs ->
263+
List.fold_right (helper cs) (String.split_on_char c s) acc
264+
in
265+
helper chars str []
266+
267+
let split_last_exn str ~split_on =
268+
let n = String.length str in
269+
let ridx = String.rindex str split_on in
270+
String.sub str 0 ridx, String.sub str (ridx + 1) (n - ridx - 1)
230271
end
231272

232273
external compare : 'a -> 'a -> int = "%compare"

utils/misc.mli

+9
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ module Stdlib : sig
173173
val print : Format.formatter -> t -> unit
174174

175175
val for_all : (char -> bool) -> t -> bool
176+
177+
val begins_with : ?from:int -> string -> prefix:string -> bool
178+
179+
val split_on_string : string -> split_on:string -> string list
180+
181+
val split_on_chars : string -> split_on:char list -> string list
182+
183+
(** Splits on the last occurrence of the given character. *)
184+
val split_last_exn : string -> split_on:char -> string * string
176185
end
177186

178187
external compare : 'a -> 'a -> int = "%compare"

0 commit comments

Comments
 (0)