Browse Source
Merge pull request #2674 from bjorn3/module_improvements
Make Module object safe
pull/2685/head
Pat Hickey
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
12 additions and
23 deletions
-
cranelift/jit/src/backend.rs
-
cranelift/module/src/module.rs
-
cranelift/object/src/backend.rs
|
|
@ -596,15 +596,12 @@ impl Module for JITModule { |
|
|
|
ctx.import_global_value(ir::ExternalName::user(1, data.as_u32())) |
|
|
|
} |
|
|
|
|
|
|
|
fn define_function<TS>( |
|
|
|
fn define_function( |
|
|
|
&mut self, |
|
|
|
id: FuncId, |
|
|
|
ctx: &mut cranelift_codegen::Context, |
|
|
|
trap_sink: &mut TS, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> |
|
|
|
where |
|
|
|
TS: TrapSink, |
|
|
|
{ |
|
|
|
trap_sink: &mut dyn TrapSink, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> { |
|
|
|
info!("defining function {}: {}", id, ctx.func.display(self.isa())); |
|
|
|
let CodeInfo { |
|
|
|
total_size: code_size, |
|
|
|
|
|
@ -464,14 +464,12 @@ pub trait Module { |
|
|
|
/// Returns the size of the function's code and constant data.
|
|
|
|
///
|
|
|
|
/// Note: After calling this function the given `Context` will contain the compiled function.
|
|
|
|
fn define_function<TS>( |
|
|
|
fn define_function( |
|
|
|
&mut self, |
|
|
|
func: FuncId, |
|
|
|
ctx: &mut Context, |
|
|
|
trap_sink: &mut TS, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> |
|
|
|
where |
|
|
|
TS: binemit::TrapSink; |
|
|
|
trap_sink: &mut dyn binemit::TrapSink, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction>; |
|
|
|
|
|
|
|
/// Define a function, taking the function body from the given `bytes`.
|
|
|
|
///
|
|
|
@ -559,15 +557,12 @@ impl<M: Module> Module for &mut M { |
|
|
|
(**self).declare_data_in_data(data, ctx) |
|
|
|
} |
|
|
|
|
|
|
|
fn define_function<TS>( |
|
|
|
fn define_function( |
|
|
|
&mut self, |
|
|
|
func: FuncId, |
|
|
|
ctx: &mut Context, |
|
|
|
trap_sink: &mut TS, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> |
|
|
|
where |
|
|
|
TS: binemit::TrapSink, |
|
|
|
{ |
|
|
|
trap_sink: &mut dyn binemit::TrapSink, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> { |
|
|
|
(**self).define_function(func, ctx, trap_sink) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -243,15 +243,12 @@ impl Module for ObjectModule { |
|
|
|
Ok(id) |
|
|
|
} |
|
|
|
|
|
|
|
fn define_function<TS>( |
|
|
|
fn define_function( |
|
|
|
&mut self, |
|
|
|
func_id: FuncId, |
|
|
|
ctx: &mut cranelift_codegen::Context, |
|
|
|
trap_sink: &mut TS, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> |
|
|
|
where |
|
|
|
TS: TrapSink, |
|
|
|
{ |
|
|
|
trap_sink: &mut dyn TrapSink, |
|
|
|
) -> ModuleResult<ModuleCompiledFunction> { |
|
|
|
info!( |
|
|
|
"defining function {}: {}", |
|
|
|
func_id, |
|
|
|