Add documentation for intrinsics
This commit is contained in:
parent
aa1de16f4c
commit
f4bce14299
@ -66,12 +66,18 @@ pub enum LLVMIntrinsicKind {
|
|||||||
const INTRINSIC_IDENT: &str = "reid.intrinsic";
|
const INTRINSIC_IDENT: &str = "reid.intrinsic";
|
||||||
const MALLOC_IDENT: &str = "malloc";
|
const MALLOC_IDENT: &str = "malloc";
|
||||||
|
|
||||||
|
macro_rules! doc {
|
||||||
|
($str:expr) => {
|
||||||
|
Some($str.to_string())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn form_intrinsics() -> Vec<FunctionDefinition> {
|
pub fn form_intrinsics() -> Vec<FunctionDefinition> {
|
||||||
let mut intrinsics = Vec::new();
|
let mut intrinsics = Vec::new();
|
||||||
|
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: MALLOC_IDENT.to_owned(),
|
name: MALLOC_IDENT.to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Allocates `size` bytes and returns a `u8`-pointer."),
|
||||||
linkage_name: Some("malloc".to_owned()),
|
linkage_name: Some("malloc".to_owned()),
|
||||||
is_pub: false,
|
is_pub: false,
|
||||||
is_imported: true,
|
is_imported: true,
|
||||||
@ -91,13 +97,14 @@ pub fn form_intrinsics() -> Vec<FunctionDefinition> {
|
|||||||
|
|
||||||
pub fn simple_intrinsic<T: Into<String> + Clone>(
|
pub fn simple_intrinsic<T: Into<String> + Clone>(
|
||||||
name: T,
|
name: T,
|
||||||
|
doc: T,
|
||||||
params: Vec<T>,
|
params: Vec<T>,
|
||||||
ret: TypeKind,
|
ret: TypeKind,
|
||||||
intrisic: LLVMIntrinsicKind,
|
intrisic: LLVMIntrinsicKind,
|
||||||
) -> FunctionDefinition {
|
) -> FunctionDefinition {
|
||||||
FunctionDefinition {
|
FunctionDefinition {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: Some(doc.into()),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -117,7 +124,7 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
if let TypeKind::Array(_, len) = ty {
|
if let TypeKind::Array(_, len) = ty {
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "length".to_owned(),
|
name: "length".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Returns the length of this given array"),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -135,127 +142,147 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
if ty.category() == TypeCategory::Real {
|
if ty.category() == TypeCategory::Real {
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"sqrt",
|
"sqrt",
|
||||||
|
"Calculates the square-root of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Sqrt(ty.clone()),
|
LLVMIntrinsicKind::Sqrt(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"sin",
|
"sin",
|
||||||
|
"Calculates sine of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Sin(ty.clone()),
|
LLVMIntrinsicKind::Sin(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"cos",
|
"cos",
|
||||||
|
"Calculates cosine of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Cos(ty.clone()),
|
LLVMIntrinsicKind::Cos(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"tan",
|
"tan",
|
||||||
|
"Calculates tangent of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Tan(ty.clone()),
|
LLVMIntrinsicKind::Tan(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"sinh",
|
"sinh",
|
||||||
|
"Calculates hyperbolic sine of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::SinH(ty.clone()),
|
LLVMIntrinsicKind::SinH(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"cosh",
|
"cosh",
|
||||||
|
"Calculates hyperbolic cosine of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::CosH(ty.clone()),
|
LLVMIntrinsicKind::CosH(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"tanh",
|
"tanh",
|
||||||
|
"Calculates hyperbolic tangent of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::TanH(ty.clone()),
|
LLVMIntrinsicKind::TanH(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"asin",
|
"asin",
|
||||||
|
"Calculates arcsine of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::ASin(ty.clone()),
|
LLVMIntrinsicKind::ASin(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"acos",
|
"acos",
|
||||||
|
"Calculates arccosine of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::ACos(ty.clone()),
|
LLVMIntrinsicKind::ACos(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"atan",
|
"atan",
|
||||||
|
"Calculates arctangent of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::ATan(ty.clone()),
|
LLVMIntrinsicKind::ATan(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"atan2",
|
"atan2",
|
||||||
|
"Calculates 2-argument arctangent of `value`",
|
||||||
vec!["self", "other"],
|
vec!["self", "other"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::ATan2(ty.clone()),
|
LLVMIntrinsicKind::ATan2(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"log",
|
"log",
|
||||||
|
"Returns logₑ of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Log(ty.clone()),
|
LLVMIntrinsicKind::Log(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"log2",
|
"log2",
|
||||||
|
"Returns log₂ of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Log2(ty.clone()),
|
LLVMIntrinsicKind::Log2(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"log10",
|
"log10",
|
||||||
|
"Returns log₁₀ of `value`",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Log10(ty.clone()),
|
LLVMIntrinsicKind::Log10(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"floor",
|
"floor",
|
||||||
|
"Rounds `value` towards negative infinity.",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Floor(ty.clone()),
|
LLVMIntrinsicKind::Floor(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"ceil",
|
"ceil",
|
||||||
|
"Rounds `value` towards positive infinity.",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Ceil(ty.clone()),
|
LLVMIntrinsicKind::Ceil(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"trunc",
|
"trunc",
|
||||||
|
"Truncates `value` to the integer nearest to `0`.",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Trunc(ty.clone()),
|
LLVMIntrinsicKind::Trunc(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"round",
|
"round",
|
||||||
|
"Rounds `value` to the closest even integer.",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Round(ty.clone()),
|
LLVMIntrinsicKind::Round(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"even",
|
"even",
|
||||||
|
"Rounds `value` to the closest even integer.",
|
||||||
vec!["self"],
|
vec!["self"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::RoundEven(ty.clone()),
|
LLVMIntrinsicKind::RoundEven(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"pow",
|
"pow",
|
||||||
|
"Returns `value` raised to the exponent of `exponent`.",
|
||||||
vec!["self", "exponent"],
|
vec!["self", "exponent"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Pow(ty.clone()),
|
LLVMIntrinsicKind::Pow(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "powi".to_owned(),
|
name: "powi".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Returns `value` raised to the exponent of `exponent`."),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -284,12 +311,14 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
TypeCategory::Integer | TypeCategory::Real | TypeCategory::Bool => {
|
TypeCategory::Integer | TypeCategory::Real | TypeCategory::Bool => {
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"max",
|
"max",
|
||||||
|
"Returns the larger of `a` and `b`.",
|
||||||
vec!["self", "other"],
|
vec!["self", "other"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Max(ty.clone()),
|
LLVMIntrinsicKind::Max(ty.clone()),
|
||||||
));
|
));
|
||||||
intrinsics.push(simple_intrinsic(
|
intrinsics.push(simple_intrinsic(
|
||||||
"min",
|
"min",
|
||||||
|
"Returns the smaller of `a` and `b`.",
|
||||||
vec!["self", "other"],
|
vec!["self", "other"],
|
||||||
ty.clone(),
|
ty.clone(),
|
||||||
LLVMIntrinsicKind::Min(ty.clone()),
|
LLVMIntrinsicKind::Min(ty.clone()),
|
||||||
@ -297,7 +326,7 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
if ty.signed() {
|
if ty.signed() {
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "abs".to_owned(),
|
name: "abs".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Returns the absolute value of `value`."),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -328,7 +357,7 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
}
|
}
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "sizeof".to_owned(),
|
name: "sizeof".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Simply returns the size of type `T` in bytes."),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -340,7 +369,7 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
});
|
});
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "malloc".to_owned(),
|
name: "malloc".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Allocates `T::sizeof() * size` bytes and returns a pointer to `T`."),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -357,7 +386,10 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
|
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "memcpy".to_owned(),
|
name: "memcpy".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!(
|
||||||
|
"Copies `T::sizeof() * size` bytes from pointer `source` to pointer
|
||||||
|
`destination`."
|
||||||
|
),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -386,7 +418,7 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
|
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "null".to_owned(),
|
name: "null".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Returns a null-pointer of type `T`."),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
@ -399,7 +431,7 @@ pub fn get_intrinsic_assoc_functions(ty: &TypeKind) -> Vec<FunctionDefinition> {
|
|||||||
|
|
||||||
intrinsics.push(FunctionDefinition {
|
intrinsics.push(FunctionDefinition {
|
||||||
name: "is_null".to_owned(),
|
name: "is_null".to_owned(),
|
||||||
documentation: Some("temp".to_string()),
|
documentation: doc!("Returns a boolean representing if `val` is a nullptr or not."),
|
||||||
linkage_name: None,
|
linkage_name: None,
|
||||||
is_pub: true,
|
is_pub: true,
|
||||||
is_imported: false,
|
is_imported: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user