llvm_scratch/core/function/
param_attrs.rs1use fmt::Formatter;
2use std::collections::BTreeSet;
3use std::fmt;
4
5#[derive(Eq, PartialEq, PartialOrd, Ord, Hash)]
8pub struct ParameterAttributes {
9 attrs: BTreeSet<ParameterAttribute>,
10}
11
12impl Default for ParameterAttributes {
13 fn default() -> Self {
14 Self {
15 attrs: BTreeSet::new(),
16 }
17 }
18}
19
20impl ParameterAttributes {
21 pub fn add_attr(&mut self, attr: ParameterAttribute) {
22 self.attrs.insert(attr);
23 }
24}
25
26impl fmt::Display for ParameterAttributes {
27 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28 let fmt_string = self
29 .attrs
30 .iter()
31 .map(|attr| attr.to_string())
32 .collect::<Vec<String>>()
33 .join(", ");
34
35 write!(f, "{}", fmt_string)
36 }
37}
38
39#[derive(Eq, PartialEq, PartialOrd, Ord, Hash)]
42pub enum ParameterAttribute {
43 ZEROEXT,
45 SIGNEXT,
47}
48
49impl fmt::Display for ParameterAttribute {
50 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
51 let attr_string = match self {
52 Self::ZEROEXT => "zeroext",
53 Self::SIGNEXT => "signext",
54 };
55
56 write!(f, "{}", attr_string)
57 }
58}