1 | // Derived from code in LLVM, which is: |
---|---|
2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 | // See https://llvm.org/LICENSE.txt for license information. |
4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 | |
6 | pub fn get_arm64ec_mangled_function_name(name: &str) -> Option<String> { |
7 | let first_char = name.chars().next().unwrap(); |
8 | let is_cpp_fn = first_char == '?'; |
9 | if is_cpp_fn && name.contains("$$h") { |
10 | return None; |
11 | } |
12 | if !is_cpp_fn && first_char == '#'{ |
13 | return None; |
14 | } |
15 | |
16 | let mut prefix = "$$h"; |
17 | let insert_idx = if is_cpp_fn { |
18 | match name.find("@@") { |
19 | Some(two_at_signs_idx) if Some(two_at_signs_idx) != name.find("@@@") => { |
20 | two_at_signs_idx + 2 |
21 | } |
22 | _ => name.find('@').map_or(name.len(), |idx| idx + 1), |
23 | } |
24 | } else { |
25 | prefix = "#"; |
26 | 0 |
27 | }; |
28 | |
29 | Some(format!( |
30 | "{}{prefix}{} ", |
31 | &name[..insert_idx], |
32 | &name[insert_idx..] |
33 | )) |
34 | } |
35 | |
36 | pub fn get_arm64ec_demangled_function_name(name: &str) -> Option<String> { |
37 | let first_char: char = name.chars().next().unwrap(); |
38 | if first_char == '#'{ |
39 | return Some(name[1..].to_string()); |
40 | } |
41 | if first_char != '?'{ |
42 | return None; |
43 | } |
44 | |
45 | match name.split_once(delimiter:"$$h") { |
46 | Some((first: &str, second: &str)) if !second.is_empty() => Some(format!("{first}{second} ")), |
47 | _ => None, |
48 | } |
49 | } |
50 |