use cutile_ir::ir::Attribute;
pub use crate::hints::{CompileOptions, OptimizationHints, SMHints};
pub type NamedAttr = (String, Attribute);
pub fn str_attr(name: &str, value: &str) -> NamedAttr {
(name.to_string(), Attribute::String(value.to_string()))
}
pub fn type_attr(name: &str, ty: cutile_ir::ir::Type) -> NamedAttr {
(name.to_string(), Attribute::Type(ty))
}
pub fn flag_attr(name: &str) -> NamedAttr {
(name.to_string(), Attribute::Bool(true))
}
pub fn int_attr(name: &str, value: i64) -> NamedAttr {
(name.to_string(), Attribute::i32(value))
}
pub fn float_attr(name: &str, value: f64) -> NamedAttr {
(
name.to_string(),
Attribute::float(value, cutile_ir::ir::ScalarType::F64),
)
}
pub fn cmp_pred_attr(pred: &str) -> NamedAttr {
let val = match pred {
"equal" => 0,
"not_equal" => 1,
"less_than" => 2,
"less_than_or_equal" => 3,
"greater_than" => 4,
"greater_than_or_equal" => 5,
_ => panic!("unknown comparison predicate: {pred}"),
};
int_attr("comparison_predicate", val)
}
pub fn cmp_ordering_attr(ordering: &str) -> NamedAttr {
let val = match ordering {
"unordered" => 0,
"ordered" => 1,
_ => panic!("unknown comparison ordering: {ordering}"),
};
int_attr("comparison_ordering", val)
}
pub fn signedness_attr(name: &str, signedness: &str) -> NamedAttr {
let val = match signedness {
"unsigned" => 0,
"signed" => 1,
_ => panic!("unknown signedness: {signedness}"),
};
int_attr(name, val)
}
pub fn rounding_mode_attr(mode: &str) -> NamedAttr {
let val = match mode {
"nearest_even" => 0,
"zero" => 1,
"negative_inf" => 2,
"positive_inf" => 3,
"approx" => 4,
"full" => 5,
"nearest_int_to_zero" => 6,
_ => panic!("unknown rounding mode: {mode}"),
};
int_attr("rounding_mode", val)
}
pub fn overflow_attr(overflow: &str) -> NamedAttr {
let val = match overflow {
"none" => 0,
"no_signed_wrap" | "nsw" => 1,
"no_unsigned_wrap" | "nuw" => 2,
"no_wrap" | "nw" => 3,
_ => panic!("unknown overflow: {overflow}"),
};
int_attr("overflow", val)
}
pub fn memory_ordering_attr(ordering: &str) -> NamedAttr {
let val = match ordering {
"weak" => 0,
"relaxed" => 1,
"acquire" => 2,
"release" => 3,
"acq_rel" => 4,
_ => panic!("unknown memory ordering: {ordering}"),
};
int_attr("memory_ordering_semantics", val)
}
pub fn memory_scope_attr(scope: &str) -> NamedAttr {
let val = match scope {
"tl_blk" => 0,
"device" => 1,
"sys" => 2,
_ => panic!("unknown memory scope: {scope}"),
};
int_attr("memory_scope", val)
}