abstraps/dialects/base/
intrinsics.rs

1use crate::core::*;
2use crate::dialects::base::*;
3use crate::dialects::builtin::*;
4use crate::*;
5
6// Constant intrinsic.
7intrinsic!(Constant: ["base", "constant"], [ConstantLike], extern: []);
8
9impl Constant {
10    pub fn get_builder(&self, val: ConstantAttr, loc: LocationInfo) -> OperationBuilder {
11        let intr = Box::new(Constant);
12        let mut b = OperationBuilder::default(intr, loc);
13        b.insert_attr("value", Box::new(val));
14        b
15    }
16}
17
18// Call intrinsic.
19intrinsic!(Call: ["base", "call"], [], extern: []);
20
21impl Call {
22    pub fn get_builder(
23        &self,
24        name: &str,
25        operands: Vec<Var>,
26        loc: LocationInfo,
27    ) -> OperationBuilder {
28        let intr = Box::new(Call);
29        let mut b = OperationBuilder::default(intr, loc);
30        let sym_name = SymbolAttr::new(name);
31        b.set_operands(operands);
32        b.insert_attr("symbol", Box::new(sym_name));
33        b
34    }
35}
36
37// Return intrinsic.
38intrinsic!(Return: ["base", "return"], [Terminator], extern: []);
39
40impl Return {
41    pub fn get_builder(&self, operands: Vec<Var>, loc: LocationInfo) -> OperationBuilder {
42        let intr = Box::new(Return);
43        let mut b = OperationBuilder::default(intr, loc);
44        b.set_operands(operands);
45        b
46    }
47}
48
49// Branch intrinsic.
50intrinsic!(Branch: ["base", "branch"], [Terminator], extern: []);
51
52impl Branch {
53    pub fn get_builder(
54        &self,
55        operands: Vec<Var>,
56        blks: Vec<usize>,
57        loc: LocationInfo,
58    ) -> OperationBuilder {
59        let intr = Box::new(Branch);
60        let mut b = OperationBuilder::default(intr, loc);
61        b.set_operands(operands);
62        b.set_successors(blks);
63        b
64    }
65}
66
67// Conditional branch intrinsic.
68intrinsic!(ConditionalBranch: ["base", "br"], [Terminator], extern: []);
69
70impl ConditionalBranch {
71    pub fn get_builder(
72        &self,
73        operands: Vec<Var>,
74        blks: Vec<usize>,
75        loc: LocationInfo,
76    ) -> OperationBuilder {
77        let intr = Box::new(ConditionalBranch);
78        let mut b = OperationBuilder::default(intr, loc);
79        b.set_operands(operands);
80        b.set_successors(blks);
81        b
82    }
83}