1 //! Defines `Module` and related types. 2 3 // TODO: Should `ir::Function` really have a `name`? 4 5 // TODO: Factor out `ir::Function`'s `ext_funcs` and `global_values` into a struct 6 // shared with `DataContext`? 7 8 use super::HashMap; 9 use crate::data_context::DataContext; 10 use core::fmt::Display; 11 use cranelift_codegen::binemit::{CodeOffset, Reloc}; 12 use cranelift_codegen::entity::{entity_impl, PrimaryMap}; 13 use cranelift_codegen::ir::Function; 14 use cranelift_codegen::settings::SetError; 15 use cranelift_codegen::{binemit, MachReloc}; 16 use cranelift_codegen::{ir, isa, CodegenError, CompileError, Context}; 17 use std::borrow::ToOwned; 18 use std::string::String; 19 20 /// A module relocation. 21 #[derive(Clone)] 22 pub struct ModuleReloc { 23 /// The offset at which the relocation applies, *relative to the 24 /// containing section*. 25 pub offset: CodeOffset, 26 /// The kind of relocation. 27 pub kind: Reloc, 28 /// The external symbol / name to which this relocation refers. 29 pub name: ModuleExtName, 30 /// The addend to add to the symbol value. 31 pub addend: i64, 32 } 33 34 impl ModuleReloc { 35 /// Converts a `MachReloc` produced from a `Function` into a `ModuleReloc`. 36 pub fn from_mach_reloc(mach_reloc: &MachReloc, func: &Function) -> Self { 37 let name = match mach_reloc.name { 38 ir::ExternalName::User(reff) => { 39 let name = &func.params.user_named_funcs()[reff]; 40 ModuleExtName::user(name.namespace, name.index) 41 } 42 ir::ExternalName::TestCase(_) => unimplemented!(), 43 ir::ExternalName::LibCall(libcall) => ModuleExtName::LibCall(libcall), 44 ir::ExternalName::KnownSymbol(ks) => ModuleExtName::KnownSymbol(ks), 45 }; 46 Self { 47 offset: mach_reloc.offset, 48 kind: mach_reloc.kind, 49 name, 50 addend: mach_reloc.addend, 51 } 52 } 53 } 54 55 /// A function identifier for use in the `Module` interface. 56 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] 57 pub struct FuncId(u32); 58 entity_impl!(FuncId, "funcid"); 59 60 /// Function identifiers are namespace 0 in `ir::ExternalName` 61 impl From<FuncId> for ModuleExtName { 62 fn from(id: FuncId) -> Self { 63 Self::User { 64 namespace: 0, 65 index: id.0, 66 } 67 } 68 } 69 70 impl FuncId { 71 /// Get the `FuncId` for the function named by `name`. 72 pub fn from_name(name: &ModuleExtName) -> FuncId { 73 if let ModuleExtName::User { namespace, index } = name { 74 debug_assert_eq!(*namespace, 0); 75 FuncId::from_u32(*index) 76 } else { 77 panic!("unexpected name in DataId::from_name") 78 } 79 } 80 } 81 82 /// A data object identifier for use in the `Module` interface. 83 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] 84 pub struct DataId(u32); 85 entity_impl!(DataId, "dataid"); 86 87 /// Data identifiers are namespace 1 in `ir::ExternalName` 88 impl From<DataId> for ModuleExtName { 89 fn from(id: DataId) -> Self { 90 Self::User { 91 namespace: 1, 92 index: id.0, 93 } 94 } 95 } 96 97 impl DataId { 98 /// Get the `DataId` for the data object named by `name`. 99 pub fn from_name(name: &ModuleExtName) -> DataId { 100 if let ModuleExtName::User { namespace, index } = name { 101 debug_assert_eq!(*namespace, 1); 102 DataId::from_u32(*index) 103 } else { 104 panic!("unexpected name in DataId::from_name") 105 } 106 } 107 } 108 109 /// Linkage refers to where an entity is defined and who can see it. 110 #[derive(Copy, Clone, Debug, PartialEq, Eq)] 111 pub enum Linkage { 112 /// Defined outside of a module. 113 Import, 114 /// Defined inside the module, but not visible outside it. 115 Local, 116 /// Defined inside the module, visible outside it, and may be preempted. 117 Preemptible, 118 /// Defined inside the module, visible inside the current static linkage unit, but not outside. 119 /// 120 /// A static linkage unit is the combination of all object files passed to a linker to create 121 /// an executable or dynamic library. 122 Hidden, 123 /// Defined inside the module, and visible outside it. 124 Export, 125 } 126 127 impl Linkage { 128 fn merge(a: Self, b: Self) -> Self { 129 match a { 130 Self::Export => Self::Export, 131 Self::Hidden => match b { 132 Self::Export => Self::Export, 133 Self::Preemptible => Self::Preemptible, 134 _ => Self::Hidden, 135 }, 136 Self::Preemptible => match b { 137 Self::Export => Self::Export, 138 _ => Self::Preemptible, 139 }, 140 Self::Local => match b { 141 Self::Export => Self::Export, 142 Self::Hidden => Self::Hidden, 143 Self::Preemptible => Self::Preemptible, 144 Self::Local | Self::Import => Self::Local, 145 }, 146 Self::Import => b, 147 } 148 } 149 150 /// Test whether this linkage can have a definition. 151 pub fn is_definable(self) -> bool { 152 match self { 153 Self::Import => false, 154 Self::Local | Self::Preemptible | Self::Hidden | Self::Export => true, 155 } 156 } 157 158 /// Test whether this linkage will have a definition that cannot be preempted. 159 pub fn is_final(self) -> bool { 160 match self { 161 Self::Import | Self::Preemptible => false, 162 Self::Local | Self::Hidden | Self::Export => true, 163 } 164 } 165 } 166 167 /// A declared name may refer to either a function or data declaration 168 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] 169 pub enum FuncOrDataId { 170 /// When it's a FuncId 171 Func(FuncId), 172 /// When it's a DataId 173 Data(DataId), 174 } 175 176 /// Mapping to `ModuleExtName` is trivial based on the `FuncId` and `DataId` mapping. 177 impl From<FuncOrDataId> for ModuleExtName { 178 fn from(id: FuncOrDataId) -> Self { 179 match id { 180 FuncOrDataId::Func(funcid) => Self::from(funcid), 181 FuncOrDataId::Data(dataid) => Self::from(dataid), 182 } 183 } 184 } 185 186 /// Information about a function which can be called. 187 #[derive(Debug)] 188 pub struct FunctionDeclaration { 189 #[allow(missing_docs)] 190 pub name: String, 191 #[allow(missing_docs)] 192 pub linkage: Linkage, 193 #[allow(missing_docs)] 194 pub signature: ir::Signature, 195 } 196 197 impl FunctionDeclaration { 198 fn merge(&mut self, linkage: Linkage, sig: &ir::Signature) -> Result<(), ModuleError> { 199 self.linkage = Linkage::merge(self.linkage, linkage); 200 if &self.signature != sig { 201 return Err(ModuleError::IncompatibleSignature( 202 self.name.clone(), 203 self.signature.clone(), 204 sig.clone(), 205 )); 206 } 207 Ok(()) 208 } 209 } 210 211 /// Error messages for all `Module` methods 212 #[derive(Debug)] 213 pub enum ModuleError { 214 /// Indicates an identifier was used before it was declared 215 Undeclared(String), 216 217 /// Indicates an identifier was used as data/function first, but then used as the other 218 IncompatibleDeclaration(String), 219 220 /// Indicates a function identifier was declared with a 221 /// different signature than declared previously 222 IncompatibleSignature(String, ir::Signature, ir::Signature), 223 224 /// Indicates an identifier was defined more than once 225 DuplicateDefinition(String), 226 227 /// Indicates an identifier was defined, but was declared as an import 228 InvalidImportDefinition(String), 229 230 /// Wraps a `cranelift-codegen` error 231 Compilation(CodegenError), 232 233 /// Memory allocation failure from a backend 234 Allocation { 235 /// Tell where the allocation came from 236 message: &'static str, 237 /// Io error the allocation failed with 238 err: std::io::Error, 239 }, 240 241 /// Wraps a generic error from a backend 242 Backend(anyhow::Error), 243 244 /// Wraps an error from a flag definition. 245 Flag(SetError), 246 } 247 248 impl<'a> From<CompileError<'a>> for ModuleError { 249 fn from(err: CompileError<'a>) -> Self { 250 Self::Compilation(err.inner) 251 } 252 } 253 254 // This is manually implementing Error and Display instead of using thiserror to reduce the amount 255 // of dependencies used by Cranelift. 256 impl std::error::Error for ModuleError { 257 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { 258 match self { 259 Self::Undeclared { .. } 260 | Self::IncompatibleDeclaration { .. } 261 | Self::IncompatibleSignature { .. } 262 | Self::DuplicateDefinition { .. } 263 | Self::InvalidImportDefinition { .. } => None, 264 Self::Compilation(source) => Some(source), 265 Self::Allocation { err: source, .. } => Some(source), 266 Self::Backend(source) => Some(&**source), 267 Self::Flag(source) => Some(source), 268 } 269 } 270 } 271 272 impl std::fmt::Display for ModuleError { 273 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 274 match self { 275 Self::Undeclared(name) => { 276 write!(f, "Undeclared identifier: {}", name) 277 } 278 Self::IncompatibleDeclaration(name) => { 279 write!(f, "Incompatible declaration of identifier: {}", name,) 280 } 281 Self::IncompatibleSignature(name, prev_sig, new_sig) => { 282 write!( 283 f, 284 "Function {} signature {:?} is incompatible with previous declaration {:?}", 285 name, new_sig, prev_sig, 286 ) 287 } 288 Self::DuplicateDefinition(name) => { 289 write!(f, "Duplicate definition of identifier: {}", name) 290 } 291 Self::InvalidImportDefinition(name) => { 292 write!( 293 f, 294 "Invalid to define identifier declared as an import: {}", 295 name, 296 ) 297 } 298 Self::Compilation(err) => { 299 write!(f, "Compilation error: {}", err) 300 } 301 Self::Allocation { message, err } => { 302 write!(f, "Allocation error: {}: {}", message, err) 303 } 304 Self::Backend(err) => write!(f, "Backend error: {}", err), 305 Self::Flag(err) => write!(f, "Flag error: {}", err), 306 } 307 } 308 } 309 310 impl std::convert::From<CodegenError> for ModuleError { 311 fn from(source: CodegenError) -> Self { 312 Self::Compilation { 0: source } 313 } 314 } 315 316 impl std::convert::From<SetError> for ModuleError { 317 fn from(source: SetError) -> Self { 318 Self::Flag { 0: source } 319 } 320 } 321 322 /// A convenient alias for a `Result` that uses `ModuleError` as the error type. 323 pub type ModuleResult<T> = Result<T, ModuleError>; 324 325 /// Information about a data object which can be accessed. 326 #[derive(Debug)] 327 pub struct DataDeclaration { 328 #[allow(missing_docs)] 329 pub name: String, 330 #[allow(missing_docs)] 331 pub linkage: Linkage, 332 #[allow(missing_docs)] 333 pub writable: bool, 334 #[allow(missing_docs)] 335 pub tls: bool, 336 } 337 338 impl DataDeclaration { 339 fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool) { 340 self.linkage = Linkage::merge(self.linkage, linkage); 341 self.writable = self.writable || writable; 342 assert_eq!( 343 self.tls, tls, 344 "Can't change TLS data object to normal or in the opposite way", 345 ); 346 } 347 } 348 349 /// A translated `ExternalName` into something global we can handle. 350 #[derive(Clone)] 351 pub enum ModuleExtName { 352 /// User defined function, converted from `ExternalName::User`. 353 User { 354 /// Arbitrary. 355 namespace: u32, 356 /// Arbitrary. 357 index: u32, 358 }, 359 /// Call into a library function. 360 LibCall(ir::LibCall), 361 /// Symbols known to the linker. 362 KnownSymbol(ir::KnownSymbol), 363 } 364 365 impl ModuleExtName { 366 /// Creates a user-defined external name. 367 pub fn user(namespace: u32, index: u32) -> Self { 368 Self::User { namespace, index } 369 } 370 } 371 372 impl Display for ModuleExtName { 373 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 374 match self { 375 Self::User { namespace, index } => write!(f, "u{}:{}", namespace, index), 376 Self::LibCall(lc) => write!(f, "%{}", lc), 377 Self::KnownSymbol(ks) => write!(f, "{}", ks), 378 } 379 } 380 } 381 382 /// This provides a view to the state of a module which allows `ir::ExternalName`s to be translated 383 /// into `FunctionDeclaration`s and `DataDeclaration`s. 384 #[derive(Debug, Default)] 385 pub struct ModuleDeclarations { 386 names: HashMap<String, FuncOrDataId>, 387 functions: PrimaryMap<FuncId, FunctionDeclaration>, 388 data_objects: PrimaryMap<DataId, DataDeclaration>, 389 } 390 391 impl ModuleDeclarations { 392 /// Get the module identifier for a given name, if that name 393 /// has been declared. 394 pub fn get_name(&self, name: &str) -> Option<FuncOrDataId> { 395 self.names.get(name).copied() 396 } 397 398 /// Get an iterator of all function declarations 399 pub fn get_functions(&self) -> impl Iterator<Item = (FuncId, &FunctionDeclaration)> { 400 self.functions.iter() 401 } 402 403 /// Return whether `name` names a function, rather than a data object. 404 pub fn is_function(name: &ModuleExtName) -> bool { 405 match name { 406 ModuleExtName::User { namespace, .. } => *namespace == 0, 407 ModuleExtName::LibCall(_) | ModuleExtName::KnownSymbol(_) => { 408 panic!("unexpected module ext name") 409 } 410 } 411 } 412 413 /// Get the `FunctionDeclaration` for the function named by `name`. 414 pub fn get_function_decl(&self, func_id: FuncId) -> &FunctionDeclaration { 415 &self.functions[func_id] 416 } 417 418 /// Get an iterator of all data declarations 419 pub fn get_data_objects(&self) -> impl Iterator<Item = (DataId, &DataDeclaration)> { 420 self.data_objects.iter() 421 } 422 423 /// Get the `DataDeclaration` for the data object named by `name`. 424 pub fn get_data_decl(&self, data_id: DataId) -> &DataDeclaration { 425 &self.data_objects[data_id] 426 } 427 428 /// Declare a function in this module. 429 pub fn declare_function( 430 &mut self, 431 name: &str, 432 linkage: Linkage, 433 signature: &ir::Signature, 434 ) -> ModuleResult<(FuncId, Linkage)> { 435 // TODO: Can we avoid allocating names so often? 436 use super::hash_map::Entry::*; 437 match self.names.entry(name.to_owned()) { 438 Occupied(entry) => match *entry.get() { 439 FuncOrDataId::Func(id) => { 440 let existing = &mut self.functions[id]; 441 existing.merge(linkage, signature)?; 442 Ok((id, existing.linkage)) 443 } 444 FuncOrDataId::Data(..) => { 445 Err(ModuleError::IncompatibleDeclaration(name.to_owned())) 446 } 447 }, 448 Vacant(entry) => { 449 let id = self.functions.push(FunctionDeclaration { 450 name: name.to_owned(), 451 linkage, 452 signature: signature.clone(), 453 }); 454 entry.insert(FuncOrDataId::Func(id)); 455 Ok((id, self.functions[id].linkage)) 456 } 457 } 458 } 459 460 /// Declare an anonymous function in this module. 461 pub fn declare_anonymous_function( 462 &mut self, 463 signature: &ir::Signature, 464 ) -> ModuleResult<FuncId> { 465 let id = self.functions.push(FunctionDeclaration { 466 name: String::new(), 467 linkage: Linkage::Local, 468 signature: signature.clone(), 469 }); 470 self.functions[id].name = format!(".L{:?}", id); 471 Ok(id) 472 } 473 474 /// Declare a data object in this module. 475 pub fn declare_data( 476 &mut self, 477 name: &str, 478 linkage: Linkage, 479 writable: bool, 480 tls: bool, 481 ) -> ModuleResult<(DataId, Linkage)> { 482 // TODO: Can we avoid allocating names so often? 483 use super::hash_map::Entry::*; 484 match self.names.entry(name.to_owned()) { 485 Occupied(entry) => match *entry.get() { 486 FuncOrDataId::Data(id) => { 487 let existing = &mut self.data_objects[id]; 488 existing.merge(linkage, writable, tls); 489 Ok((id, existing.linkage)) 490 } 491 492 FuncOrDataId::Func(..) => { 493 Err(ModuleError::IncompatibleDeclaration(name.to_owned())) 494 } 495 }, 496 Vacant(entry) => { 497 let id = self.data_objects.push(DataDeclaration { 498 name: name.to_owned(), 499 linkage, 500 writable, 501 tls, 502 }); 503 entry.insert(FuncOrDataId::Data(id)); 504 Ok((id, self.data_objects[id].linkage)) 505 } 506 } 507 } 508 509 /// Declare an anonymous data object in this module. 510 pub fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> { 511 let id = self.data_objects.push(DataDeclaration { 512 name: String::new(), 513 linkage: Linkage::Local, 514 writable, 515 tls, 516 }); 517 self.data_objects[id].name = format!(".L{:?}", id); 518 Ok(id) 519 } 520 } 521 522 /// Information about the compiled function. 523 pub struct ModuleCompiledFunction { 524 /// The size of the compiled function. 525 pub size: binemit::CodeOffset, 526 } 527 528 /// A `Module` is a utility for collecting functions and data objects, and linking them together. 529 pub trait Module { 530 /// Return the `TargetIsa` to compile for. 531 fn isa(&self) -> &dyn isa::TargetIsa; 532 533 /// Get all declarations in this module. 534 fn declarations(&self) -> &ModuleDeclarations; 535 536 /// Get the module identifier for a given name, if that name 537 /// has been declared. 538 fn get_name(&self, name: &str) -> Option<FuncOrDataId> { 539 self.declarations().get_name(name) 540 } 541 542 /// Return the target information needed by frontends to produce Cranelift IR 543 /// for the current target. 544 fn target_config(&self) -> isa::TargetFrontendConfig { 545 self.isa().frontend_config() 546 } 547 548 /// Create a new `Context` initialized for use with this `Module`. 549 /// 550 /// This ensures that the `Context` is initialized with the default calling 551 /// convention for the `TargetIsa`. 552 fn make_context(&self) -> Context { 553 let mut ctx = Context::new(); 554 ctx.func.signature.call_conv = self.isa().default_call_conv(); 555 ctx 556 } 557 558 /// Clear the given `Context` and reset it for use with a new function. 559 /// 560 /// This ensures that the `Context` is initialized with the default calling 561 /// convention for the `TargetIsa`. 562 fn clear_context(&self, ctx: &mut Context) { 563 ctx.clear(); 564 ctx.func.signature.call_conv = self.isa().default_call_conv(); 565 } 566 567 /// Create a new empty `Signature` with the default calling convention for 568 /// the `TargetIsa`, to which parameter and return types can be added for 569 /// declaring a function to be called by this `Module`. 570 fn make_signature(&self) -> ir::Signature { 571 ir::Signature::new(self.isa().default_call_conv()) 572 } 573 574 /// Clear the given `Signature` and reset for use with a new function. 575 /// 576 /// This ensures that the `Signature` is initialized with the default 577 /// calling convention for the `TargetIsa`. 578 fn clear_signature(&self, sig: &mut ir::Signature) { 579 sig.clear(self.isa().default_call_conv()); 580 } 581 582 /// Declare a function in this module. 583 fn declare_function( 584 &mut self, 585 name: &str, 586 linkage: Linkage, 587 signature: &ir::Signature, 588 ) -> ModuleResult<FuncId>; 589 590 /// Declare an anonymous function in this module. 591 fn declare_anonymous_function(&mut self, signature: &ir::Signature) -> ModuleResult<FuncId>; 592 593 /// Declare a data object in this module. 594 fn declare_data( 595 &mut self, 596 name: &str, 597 linkage: Linkage, 598 writable: bool, 599 tls: bool, 600 ) -> ModuleResult<DataId>; 601 602 /// Declare an anonymous data object in this module. 603 fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId>; 604 605 /// Use this when you're building the IR of a function to reference a function. 606 /// 607 /// TODO: Coalesce redundant decls and signatures. 608 /// TODO: Look into ways to reduce the risk of using a FuncRef in the wrong function. 609 fn declare_func_in_func(&mut self, func_id: FuncId, func: &mut ir::Function) -> ir::FuncRef { 610 let decl = &self.declarations().functions[func_id]; 611 let signature = func.import_signature(decl.signature.clone()); 612 let user_name_ref = func.declare_imported_user_function(ir::UserExternalName { 613 namespace: 0, 614 index: func_id.as_u32(), 615 }); 616 let colocated = decl.linkage.is_final(); 617 func.import_function(ir::ExtFuncData { 618 name: ir::ExternalName::user(user_name_ref), 619 signature, 620 colocated, 621 }) 622 } 623 624 /// Use this when you're building the IR of a function to reference a data object. 625 /// 626 /// TODO: Same as above. 627 fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalValue { 628 let decl = &self.declarations().data_objects[data]; 629 let colocated = decl.linkage.is_final(); 630 let user_name_ref = func.declare_imported_user_function(ir::UserExternalName { 631 namespace: 1, 632 index: data.as_u32(), 633 }); 634 func.create_global_value(ir::GlobalValueData::Symbol { 635 name: ir::ExternalName::user(user_name_ref), 636 offset: ir::immediates::Imm64::new(0), 637 colocated, 638 tls: decl.tls, 639 }) 640 } 641 642 /// TODO: Same as above. 643 fn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> ir::FuncRef { 644 ctx.import_function(ModuleExtName::user(0, func.as_u32())) 645 } 646 647 /// TODO: Same as above. 648 fn declare_data_in_data(&self, data: DataId, ctx: &mut DataContext) -> ir::GlobalValue { 649 ctx.import_global_value(ModuleExtName::user(1, data.as_u32())) 650 } 651 652 /// Define a function, producing the function body from the given `Context`. 653 /// 654 /// Returns the size of the function's code and constant data. 655 /// 656 /// Note: After calling this function the given `Context` will contain the compiled function. 657 fn define_function( 658 &mut self, 659 func: FuncId, 660 ctx: &mut Context, 661 ) -> ModuleResult<ModuleCompiledFunction>; 662 663 /// Define a function, taking the function body from the given `bytes`. 664 /// 665 /// This function is generally only useful if you need to precisely specify 666 /// the emitted instructions for some reason; otherwise, you should use 667 /// `define_function`. 668 /// 669 /// Returns the size of the function's code. 670 fn define_function_bytes( 671 &mut self, 672 func_id: FuncId, 673 func: &ir::Function, 674 alignment: u64, 675 bytes: &[u8], 676 relocs: &[MachReloc], 677 ) -> ModuleResult<ModuleCompiledFunction>; 678 679 /// Define a data object, producing the data contents from the given `DataContext`. 680 fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()>; 681 } 682 683 impl<M: Module> Module for &mut M { 684 fn isa(&self) -> &dyn isa::TargetIsa { 685 (**self).isa() 686 } 687 688 fn declarations(&self) -> &ModuleDeclarations { 689 (**self).declarations() 690 } 691 692 fn get_name(&self, name: &str) -> Option<FuncOrDataId> { 693 (**self).get_name(name) 694 } 695 696 fn target_config(&self) -> isa::TargetFrontendConfig { 697 (**self).target_config() 698 } 699 700 fn make_context(&self) -> Context { 701 (**self).make_context() 702 } 703 704 fn clear_context(&self, ctx: &mut Context) { 705 (**self).clear_context(ctx) 706 } 707 708 fn make_signature(&self) -> ir::Signature { 709 (**self).make_signature() 710 } 711 712 fn clear_signature(&self, sig: &mut ir::Signature) { 713 (**self).clear_signature(sig) 714 } 715 716 fn declare_function( 717 &mut self, 718 name: &str, 719 linkage: Linkage, 720 signature: &ir::Signature, 721 ) -> ModuleResult<FuncId> { 722 (**self).declare_function(name, linkage, signature) 723 } 724 725 fn declare_anonymous_function(&mut self, signature: &ir::Signature) -> ModuleResult<FuncId> { 726 (**self).declare_anonymous_function(signature) 727 } 728 729 fn declare_data( 730 &mut self, 731 name: &str, 732 linkage: Linkage, 733 writable: bool, 734 tls: bool, 735 ) -> ModuleResult<DataId> { 736 (**self).declare_data(name, linkage, writable, tls) 737 } 738 739 fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> { 740 (**self).declare_anonymous_data(writable, tls) 741 } 742 743 fn declare_func_in_func(&mut self, func: FuncId, in_func: &mut ir::Function) -> ir::FuncRef { 744 (**self).declare_func_in_func(func, in_func) 745 } 746 747 fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalValue { 748 (**self).declare_data_in_func(data, func) 749 } 750 751 fn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> ir::FuncRef { 752 (**self).declare_func_in_data(func, ctx) 753 } 754 755 fn declare_data_in_data(&self, data: DataId, ctx: &mut DataContext) -> ir::GlobalValue { 756 (**self).declare_data_in_data(data, ctx) 757 } 758 759 fn define_function( 760 &mut self, 761 func: FuncId, 762 ctx: &mut Context, 763 ) -> ModuleResult<ModuleCompiledFunction> { 764 (**self).define_function(func, ctx) 765 } 766 767 fn define_function_bytes( 768 &mut self, 769 func_id: FuncId, 770 func: &ir::Function, 771 alignment: u64, 772 bytes: &[u8], 773 relocs: &[MachReloc], 774 ) -> ModuleResult<ModuleCompiledFunction> { 775 (**self).define_function_bytes(func_id, func, alignment, bytes, relocs) 776 } 777 778 fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()> { 779 (**self).define_data(data, data_ctx) 780 } 781 } 782