vicis_core/ir/function/param_attrs/
mod.rs1pub mod parser;
2
3use crate::ir::types::{Type, Types};
4use std::fmt;
5
6#[derive(PartialEq, Eq, Clone)]
7pub enum ParameterAttribute {
8 ZeroExt,
9 SignExt,
10 InReg,
11 ByVal,
12 InAlloca,
13 SRet(Option<Type>),
14 Alignment(u64),
15 ReadOnly,
16 NoAlias,
17 NoCapture,
18 NoFree,
19 Nest,
20 Returned,
21 NonNull,
22 Dereferenceable(u64),
23 DereferenceableOrNull(u64),
24 SwiftSelf,
25 SwiftError,
26 ImmArg,
27 WriteOnly,
28 StringAttribute { kind: String, value: String },
29 Ref(u32),
30 UnknownAttribute,
31}
32
33impl ParameterAttribute {
34 pub fn to_string(&self, types: &Types) -> String {
35 match self {
36 Self::ZeroExt => "zeroext".to_string(),
37 Self::SignExt => "signext".to_string(),
38 Self::InReg => "inreg".to_string(),
39 Self::ByVal => "byval".to_string(),
40 Self::InAlloca => "inalloca".to_string(),
41 Self::SRet(None) => "sret".to_string(),
42 Self::SRet(Some(ty)) => format!("sret({})", types.to_string(*ty)),
43 Self::Alignment(i) => format!("align {}", i),
44 Self::ReadOnly => "readonly".to_string(),
45 Self::NoAlias => "noalias".to_string(),
46 Self::NoCapture => "nocapture".to_string(),
47 Self::NoFree => "nofree".to_string(),
48 Self::Nest => "nest".to_string(),
49 Self::Returned => "returned".to_string(),
50 Self::NonNull => "nonnull".to_string(),
51 Self::Dereferenceable(i) => format!("dereferenceable({})", i),
52 Self::DereferenceableOrNull(i) => format!("dereferenceableornull({})", i),
53 Self::SwiftSelf => "swiftself".to_string(),
54 Self::SwiftError => "swifterror".to_string(),
55 Self::ImmArg => "immarg".to_string(),
56 Self::WriteOnly => "writeonly".to_string(),
57 Self::StringAttribute { kind, value } => format!("\"{}\"=\"{}\"", kind, value),
58 Self::Ref(i) => format!("#{}", i),
59 Self::UnknownAttribute => "".to_string(),
60 }
61 }
62}
63
64impl fmt::Debug for ParameterAttribute {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 match self {
67 Self::ZeroExt => write!(f, "zeroext"),
68 Self::SignExt => write!(f, "signext"),
69 Self::InReg => write!(f, "inreg"),
70 Self::ByVal => write!(f, "byval"),
71 Self::InAlloca => write!(f, "inalloca"),
72 Self::SRet(None) => write!(f, "sret"),
73 Self::SRet(Some(_)) => write!(f, "sret(type)"),
74 Self::Alignment(i) => write!(f, "align {}", i),
75 Self::ReadOnly => write!(f, "readonly"),
76 Self::NoAlias => write!(f, "noalias"),
77 Self::NoCapture => write!(f, "nocapture"),
78 Self::NoFree => write!(f, "nofree"),
79 Self::Nest => write!(f, "nest"),
80 Self::Returned => write!(f, "returned"),
81 Self::NonNull => write!(f, "nonnull"),
82 Self::Dereferenceable(i) => write!(f, "dereferenceable({})", i),
83 Self::DereferenceableOrNull(i) => write!(f, "dereferenceableornull({})", i),
84 Self::SwiftSelf => write!(f, "swiftself"),
85 Self::SwiftError => write!(f, "swifterror"),
86 Self::ImmArg => write!(f, "immarg"),
87 Self::WriteOnly => write!(f, "writeonly"),
88 Self::StringAttribute { kind, value } => write!(f, "\"{}\"=\"{}\"", kind, value),
89 Self::Ref(i) => write!(f, "#{}", i),
90 Self::UnknownAttribute => write!(f, ""),
91 }
92 }
93}