Declares a function an registers it as a linkable and callable target internally
(&mut self, func: &Function)
| 182 | |
| 183 | /// Declares a function an registers it as a linkable and callable target internally |
| 184 | pub fn declare_function(&mut self, func: &Function) -> Result<()> { |
| 185 | let next_id = self.defined_functions.len() as u32; |
| 186 | match self.defined_functions.entry(func.name.clone()) { |
| 187 | Entry::Occupied(_) => { |
| 188 | anyhow::bail!("Duplicate function with name {} found!", &func.name) |
| 189 | } |
| 190 | Entry::Vacant(v) => { |
| 191 | let name = func.name.to_string(); |
| 192 | let func_id = |
| 193 | self.module |
| 194 | .declare_function(&name, Linkage::Local, &func.signature)?; |
| 195 | |
| 196 | v.insert(DefinedFunction { |
| 197 | new_name: UserExternalName::new(TESTFILE_NAMESPACE, next_id), |
| 198 | signature: func.signature.clone(), |
| 199 | func_id, |
| 200 | }); |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | Ok(()) |
| 205 | } |
| 206 | |
| 207 | /// Renames the function to its new [UserExternalName], as well as any other function that |
| 208 | /// it may reference. |