| 1 |
// Copyright (C) 2024 Advanced Micro Devices. All rights reserved. |
| 2 |
// |
| 3 |
// Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
// this software and associated documentation files (the "Software"), to deal in |
| 5 |
// the Software without restriction, including without limitation the rights to |
| 6 |
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 7 |
// the Software, and to permit persons to whom the Software is furnished to do so, |
| 8 |
// subject to the following conditions: |
| 9 |
// |
| 10 |
// The above copyright notice and this permission notice shall be included in all |
| 11 |
// copies or substantial portions of the Software. |
| 12 |
// |
| 13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 15 |
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 16 |
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 17 |
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 18 |
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 19 |
// |
| 20 |
|
| 21 |
use bindgen::callbacks::EnumVariantValue; |
| 22 |
|
| 23 |
#[derive(Debug)] |
| 24 |
pub struct UpperCamelCaseCallbacks; |
| 25 |
|
| 26 |
impl bindgen::callbacks::ParseCallbacks for UpperCamelCaseCallbacks { |
| 27 |
fn item_name(&self, original_item_name: &str) -> Option<String> { |
| 28 |
if original_item_name.starts_with("amdsmi") |
| 29 |
&& (original_item_name.ends_with("_t") || original_item_name.contains("_t_")) |
| 30 |
{ |
| 31 |
Some(convert_to_upper_camel_case(original_item_name)) |
| 32 |
} else { |
| 33 |
match original_item_name { |
| 34 |
"amdsmi_processor_handle" |
| 35 |
| "amdsmi_socket_handle" |
| 36 |
| "processor_type_t" |
| 37 |
| "amd_metrics_table_header_t" => { |
| 38 |
Some(convert_to_upper_camel_case(original_item_name)) |
| 39 |
} |
| 40 |
_ => None, |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
fn enum_variant_name( |
| 46 |
&self, |
| 47 |
_enum_name: Option<&str>, |
| 48 |
original_variant_name: &str, |
| 49 |
_variant_value: EnumVariantValue, |
| 50 |
) -> Option<String> { |
| 51 |
Some(convert_to_upper_camel_case(original_variant_name)) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
fn convert_to_upper_camel_case(s: &str) -> String { |
| 56 |
let mut result = String::new(); |
| 57 |
let mut capitalize_next = true; |
| 58 |
|
| 59 |
for c in s.chars() { |
| 60 |
if c == '_' { |
| 61 |
capitalize_next = true; |
| 62 |
} else if capitalize_next { |
| 63 |
result.push(c.to_ascii_uppercase()); |
| 64 |
capitalize_next = false; |
| 65 |
} else { |
| 66 |
result.push(c.to_ascii_lowercase()); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
result |
| 71 |
} |