futhark_bindgen/
manifest.rs1use crate::*;
2
3#[derive(Clone, Debug, serde::Deserialize)]
5pub enum ElemType {
6 #[serde(rename = "i8")]
8 I8,
9
10 #[serde(rename = "i16")]
12 I16,
13
14 #[serde(rename = "i32")]
16 I32,
17
18 #[serde(rename = "i64")]
20 I64,
21
22 #[serde(rename = "u8")]
24 U8,
25
26 #[serde(rename = "u16")]
28 U16,
29
30 #[serde(rename = "u32")]
32 U32,
33
34 #[serde(rename = "u64")]
36 U64,
37
38 #[serde(rename = "f16")]
40 F16,
41
42 #[serde(rename = "f32")]
44 F32,
45
46 #[serde(rename = "f64")]
48 F64,
49
50 #[serde(rename = "bool")]
52 Bool,
53}
54
55impl ElemType {
56 pub fn to_str(&self) -> &'static str {
57 match self {
58 ElemType::I8 => "i8",
59 ElemType::I16 => "i16",
60 ElemType::I32 => "i32",
61 ElemType::I64 => "i64",
62 ElemType::U8 => "u8",
63 ElemType::U16 => "u16",
64 ElemType::U32 => "u32",
65 ElemType::U64 => "u64",
66 ElemType::F16 => "f16",
67 ElemType::F32 => "f32",
68 ElemType::F64 => "f64",
69 ElemType::Bool => "bool",
70 }
71 }
72}
73
74#[derive(Clone, Debug, serde::Deserialize)]
75pub struct Output {
76 pub r#type: String,
77 pub unique: bool,
78}
79
80#[derive(Clone, Debug, serde::Deserialize)]
81pub struct Input {
82 pub name: String,
83 pub r#type: String,
84 pub unique: bool,
85}
86
87#[derive(Clone, Debug, serde::Deserialize)]
88pub struct Entry {
89 pub cfun: String,
90 pub outputs: Vec<Output>,
91 pub inputs: Vec<Input>,
92}
93
94#[derive(Clone, Debug, serde::Deserialize)]
95pub struct ArrayOps {
96 pub free: String,
97 pub shape: String,
98 pub values: String,
99 pub new: String,
100}
101
102#[derive(Clone, Debug, serde::Deserialize)]
103pub struct ArrayType {
104 pub ctype: String,
105 pub rank: i32,
106 pub elemtype: ElemType,
107 pub ops: ArrayOps,
108}
109
110#[derive(Clone, Debug, serde::Deserialize)]
111pub struct OpaqueOps {
112 pub free: String,
113 pub store: String,
114 pub restore: String,
115}
116
117#[derive(Clone, Debug, serde::Deserialize)]
118pub struct Field {
119 pub name: String,
120 pub project: String,
121 pub r#type: String,
122}
123
124#[derive(Clone, Debug, serde::Deserialize)]
125pub struct Record {
126 pub new: String,
127 pub fields: Vec<Field>,
128}
129
130#[derive(Clone, Debug, serde::Deserialize)]
131pub struct OpaqueType {
132 pub ctype: String,
133 pub ops: OpaqueOps,
134 pub record: Option<Record>,
135}
136
137#[derive(Clone, Debug, serde::Deserialize)]
138#[serde(tag = "kind")]
139pub enum Type {
140 #[serde(rename = "array")]
141 Array(ArrayType),
142 #[serde(rename = "opaque")]
143 Opaque(OpaqueType),
144}
145
146#[derive(Clone, Debug, serde::Deserialize)]
148pub struct Manifest {
149 pub backend: Backend,
150 pub version: String,
151 pub entry_points: BTreeMap<String, Entry>,
152 pub types: BTreeMap<String, Type>,
153}
154
155impl Manifest {
156 pub fn parse_file(filename: impl AsRef<std::path::Path>) -> Result<Manifest, Error> {
158 let r = std::fs::File::open(filename)?;
159 let manifest = serde_json::from_reader(r)?;
160 Ok(manifest)
161 }
162}