Browse Source

Improve support for `Module` trait objects (#9173)

* Improve support for `Module` trait objects

* Implement `Module` for `Box<M: Module>`
pull/9072/merge
Spartan2909 2 months ago
committed by GitHub
parent
commit
8abaa75f55
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 108
      cranelift/module/src/module.rs

108
cranelift/module/src/module.rs

@ -18,6 +18,7 @@ use cranelift_codegen::{
};
use cranelift_control::ControlPlane;
use std::borrow::{Cow, ToOwned};
use std::boxed::Box;
use std::string::String;
/// A module relocation.
@ -988,7 +989,112 @@ pub trait Module {
fn define_data(&mut self, data_id: DataId, data: &DataDescription) -> ModuleResult<()>;
}
impl<M: Module> Module for &mut M {
impl<M: Module + ?Sized> Module for &mut M {
fn isa(&self) -> &dyn isa::TargetIsa {
(**self).isa()
}
fn declarations(&self) -> &ModuleDeclarations {
(**self).declarations()
}
fn get_name(&self, name: &str) -> Option<FuncOrDataId> {
(**self).get_name(name)
}
fn target_config(&self) -> isa::TargetFrontendConfig {
(**self).target_config()
}
fn make_context(&self) -> Context {
(**self).make_context()
}
fn clear_context(&self, ctx: &mut Context) {
(**self).clear_context(ctx)
}
fn make_signature(&self) -> ir::Signature {
(**self).make_signature()
}
fn clear_signature(&self, sig: &mut ir::Signature) {
(**self).clear_signature(sig)
}
fn declare_function(
&mut self,
name: &str,
linkage: Linkage,
signature: &ir::Signature,
) -> ModuleResult<FuncId> {
(**self).declare_function(name, linkage, signature)
}
fn declare_anonymous_function(&mut self, signature: &ir::Signature) -> ModuleResult<FuncId> {
(**self).declare_anonymous_function(signature)
}
fn declare_data(
&mut self,
name: &str,
linkage: Linkage,
writable: bool,
tls: bool,
) -> ModuleResult<DataId> {
(**self).declare_data(name, linkage, writable, tls)
}
fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {
(**self).declare_anonymous_data(writable, tls)
}
fn declare_func_in_func(&mut self, func: FuncId, in_func: &mut ir::Function) -> ir::FuncRef {
(**self).declare_func_in_func(func, in_func)
}
fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalValue {
(**self).declare_data_in_func(data, func)
}
fn declare_func_in_data(&self, func_id: FuncId, data: &mut DataDescription) -> ir::FuncRef {
(**self).declare_func_in_data(func_id, data)
}
fn declare_data_in_data(&self, data_id: DataId, data: &mut DataDescription) -> ir::GlobalValue {
(**self).declare_data_in_data(data_id, data)
}
fn define_function(&mut self, func: FuncId, ctx: &mut Context) -> ModuleResult<()> {
(**self).define_function(func, ctx)
}
fn define_function_with_control_plane(
&mut self,
func: FuncId,
ctx: &mut Context,
ctrl_plane: &mut ControlPlane,
) -> ModuleResult<()> {
(**self).define_function_with_control_plane(func, ctx, ctrl_plane)
}
fn define_function_bytes(
&mut self,
func_id: FuncId,
func: &ir::Function,
alignment: u64,
bytes: &[u8],
relocs: &[FinalizedMachReloc],
) -> ModuleResult<()> {
(**self).define_function_bytes(func_id, func, alignment, bytes, relocs)
}
fn define_data(&mut self, data_id: DataId, data: &DataDescription) -> ModuleResult<()> {
(**self).define_data(data_id, data)
}
}
impl<M: Module + ?Sized> Module for Box<M> {
fn isa(&self) -> &dyn isa::TargetIsa {
(**self).isa()
}

Loading…
Cancel
Save