Defines the body of a function
(
&mut self,
mut func: Function,
ctrl_plane: &mut ControlPlane,
)
| 253 | |
| 254 | /// Defines the body of a function |
| 255 | pub fn define_function( |
| 256 | &mut self, |
| 257 | mut func: Function, |
| 258 | ctrl_plane: &mut ControlPlane, |
| 259 | ) -> Result<()> { |
| 260 | Self::replace_hostcall_references(&mut func); |
| 261 | |
| 262 | let defined_func = self |
| 263 | .defined_functions |
| 264 | .get(&func.name) |
| 265 | .ok_or(anyhow!("Undeclared function {} found!", &func.name))?; |
| 266 | |
| 267 | self.ctx.func = self.apply_func_rename(func, defined_func)?; |
| 268 | self.module.define_function_with_control_plane( |
| 269 | defined_func.func_id, |
| 270 | &mut self.ctx, |
| 271 | ctrl_plane, |
| 272 | )?; |
| 273 | self.module.clear_context(&mut self.ctx); |
| 274 | Ok(()) |
| 275 | } |
| 276 | |
| 277 | fn replace_hostcall_references(func: &mut Function) { |
| 278 | // For every `func_addr` referring to a hostcall that we |