Rename define_function to define_function_with_control_plane (#6165)
And add a define_function convenience function which uses a default control plane.
This commit is contained in:
@@ -234,8 +234,11 @@ impl TestFileCompiler {
|
|||||||
.ok_or(anyhow!("Undeclared function {} found!", &func.name))?;
|
.ok_or(anyhow!("Undeclared function {} found!", &func.name))?;
|
||||||
|
|
||||||
self.ctx.func = self.apply_func_rename(func, defined_func)?;
|
self.ctx.func = self.apply_func_rename(func, defined_func)?;
|
||||||
self.module
|
self.module.define_function_with_control_plane(
|
||||||
.define_function(defined_func.func_id, &mut self.ctx, ctrl_plane)?;
|
defined_func.func_id,
|
||||||
|
&mut self.ctx,
|
||||||
|
ctrl_plane,
|
||||||
|
)?;
|
||||||
self.module.clear_context(&mut self.ctx);
|
self.module.clear_context(&mut self.ctx);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,7 @@ fn main() {
|
|||||||
bcx.seal_all_blocks();
|
bcx.seal_all_blocks();
|
||||||
bcx.finalize();
|
bcx.finalize();
|
||||||
}
|
}
|
||||||
let ctrl_plane = &mut Default::default();
|
module.define_function(func_a, &mut ctx).unwrap();
|
||||||
module
|
|
||||||
.define_function(func_a, &mut ctx, ctrl_plane)
|
|
||||||
.unwrap();
|
|
||||||
module.clear_context(&mut ctx);
|
module.clear_context(&mut ctx);
|
||||||
|
|
||||||
ctx.func.signature = sig_b;
|
ctx.func.signature = sig_b;
|
||||||
@@ -77,9 +74,7 @@ fn main() {
|
|||||||
bcx.seal_all_blocks();
|
bcx.seal_all_blocks();
|
||||||
bcx.finalize();
|
bcx.finalize();
|
||||||
}
|
}
|
||||||
module
|
module.define_function(func_b, &mut ctx).unwrap();
|
||||||
.define_function(func_b, &mut ctx, ctrl_plane)
|
|
||||||
.unwrap();
|
|
||||||
module.clear_context(&mut ctx);
|
module.clear_context(&mut ctx);
|
||||||
|
|
||||||
// Perform linking.
|
// Perform linking.
|
||||||
|
|||||||
@@ -679,7 +679,7 @@ impl Module for JITModule {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn define_function(
|
fn define_function_with_control_plane(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: FuncId,
|
id: FuncId,
|
||||||
ctx: &mut cranelift_codegen::Context,
|
ctx: &mut cranelift_codegen::Context,
|
||||||
|
|||||||
@@ -57,9 +57,7 @@ fn define_simple_function(module: &mut JITModule) -> FuncId {
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
.define_function(func_id, &mut ctx, &mut Default::default())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
func_id
|
func_id
|
||||||
}
|
}
|
||||||
@@ -210,7 +208,7 @@ fn libcall_function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module
|
module
|
||||||
.define_function(func_id, &mut ctx, &mut Default::default())
|
.define_function_with_control_plane(func_id, &mut ctx, &mut Default::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
module.finalize_definitions().unwrap();
|
module.finalize_definitions().unwrap();
|
||||||
|
|||||||
@@ -654,11 +654,29 @@ pub trait Module {
|
|||||||
///
|
///
|
||||||
/// Returns the size of the function's code and constant data.
|
/// Returns the size of the function's code and constant data.
|
||||||
///
|
///
|
||||||
|
/// Unlike [`define_function_with_control_plane`] this uses a default [`ControlPlane`] for
|
||||||
|
/// convenience.
|
||||||
|
///
|
||||||
/// Note: After calling this function the given `Context` will contain the compiled function.
|
/// Note: After calling this function the given `Context` will contain the compiled function.
|
||||||
|
///
|
||||||
|
/// [`define_function_with_control_plane`]: Self::define_function_with_control_plane
|
||||||
fn define_function(
|
fn define_function(
|
||||||
&mut self,
|
&mut self,
|
||||||
func: FuncId,
|
func: FuncId,
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
|
self.define_function_with_control_plane(func, ctx, &mut ControlPlane::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Define a function, producing the function body from the given `Context`.
|
||||||
|
///
|
||||||
|
/// 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_with_control_plane(
|
||||||
|
&mut self,
|
||||||
|
func: FuncId,
|
||||||
|
ctx: &mut Context,
|
||||||
ctrl_plane: &mut ControlPlane,
|
ctrl_plane: &mut ControlPlane,
|
||||||
) -> ModuleResult<ModuleCompiledFunction>;
|
) -> ModuleResult<ModuleCompiledFunction>;
|
||||||
|
|
||||||
@@ -762,9 +780,17 @@ impl<M: Module> Module for &mut M {
|
|||||||
&mut self,
|
&mut self,
|
||||||
func: FuncId,
|
func: FuncId,
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
|
(**self).define_function(func, ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn define_function_with_control_plane(
|
||||||
|
&mut self,
|
||||||
|
func: FuncId,
|
||||||
|
ctx: &mut Context,
|
||||||
ctrl_plane: &mut ControlPlane,
|
ctrl_plane: &mut ControlPlane,
|
||||||
) -> ModuleResult<ModuleCompiledFunction> {
|
) -> ModuleResult<ModuleCompiledFunction> {
|
||||||
(**self).define_function(func, ctx, ctrl_plane)
|
(**self).define_function_with_control_plane(func, ctx, ctrl_plane)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn define_function_bytes(
|
fn define_function_bytes(
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ impl Module for ObjectModule {
|
|||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn define_function(
|
fn define_function_with_control_plane(
|
||||||
&mut self,
|
&mut self,
|
||||||
func_id: FuncId,
|
func_id: FuncId,
|
||||||
ctx: &mut cranelift_codegen::Context,
|
ctx: &mut cranelift_codegen::Context,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use cranelift_codegen::ir::*;
|
|||||||
use cranelift_codegen::isa::CallConv;
|
use cranelift_codegen::isa::CallConv;
|
||||||
use cranelift_codegen::settings;
|
use cranelift_codegen::settings;
|
||||||
use cranelift_codegen::{ir::types::I16, Context};
|
use cranelift_codegen::{ir::types::I16, Context};
|
||||||
use cranelift_control::ControlPlane;
|
|
||||||
use cranelift_entity::EntityRef;
|
use cranelift_entity::EntityRef;
|
||||||
use cranelift_frontend::*;
|
use cranelift_frontend::*;
|
||||||
use cranelift_module::*;
|
use cranelift_module::*;
|
||||||
@@ -32,7 +31,7 @@ fn error_on_incompatible_sig_in_declare_function() {
|
|||||||
.unwrap(); // Make sure this is an error
|
.unwrap(); // Make sure this is an error
|
||||||
}
|
}
|
||||||
|
|
||||||
fn define_simple_function(module: &mut ObjectModule, ctrl_plane: &mut ControlPlane) -> FuncId {
|
fn define_simple_function(module: &mut ObjectModule) -> FuncId {
|
||||||
let sig = Signature {
|
let sig = Signature {
|
||||||
params: vec![],
|
params: vec![],
|
||||||
returns: vec![],
|
returns: vec![],
|
||||||
@@ -53,9 +52,7 @@ fn define_simple_function(module: &mut ObjectModule, ctrl_plane: &mut ControlPla
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
.define_function(func_id, &mut ctx, ctrl_plane)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
func_id
|
func_id
|
||||||
}
|
}
|
||||||
@@ -63,7 +60,6 @@ fn define_simple_function(module: &mut ObjectModule, ctrl_plane: &mut ControlPla
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "Result::unwrap()` on an `Err` value: DuplicateDefinition(\"abc\")")]
|
#[should_panic(expected = "Result::unwrap()` on an `Err` value: DuplicateDefinition(\"abc\")")]
|
||||||
fn panic_on_define_after_finalize() {
|
fn panic_on_define_after_finalize() {
|
||||||
let ctrl_plane = &mut ControlPlane::default();
|
|
||||||
let flag_builder = settings::builder();
|
let flag_builder = settings::builder();
|
||||||
let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap();
|
let isa_builder = cranelift_codegen::isa::lookup_by_name("x86_64-unknown-linux-gnu").unwrap();
|
||||||
let isa = isa_builder
|
let isa = isa_builder
|
||||||
@@ -72,8 +68,8 @@ fn panic_on_define_after_finalize() {
|
|||||||
let mut module =
|
let mut module =
|
||||||
ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap());
|
ObjectModule::new(ObjectBuilder::new(isa, "foo", default_libcall_names()).unwrap());
|
||||||
|
|
||||||
define_simple_function(&mut module, ctrl_plane);
|
define_simple_function(&mut module);
|
||||||
define_simple_function(&mut module, ctrl_plane);
|
define_simple_function(&mut module);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -196,9 +192,7 @@ fn libcall_function() {
|
|||||||
bcx.ins().return_(&[]);
|
bcx.ins().return_(&[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module
|
module.define_function(func_id, &mut ctx).unwrap();
|
||||||
.define_function(func_id, &mut ctx, &mut ControlPlane::default())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
module.finish();
|
module.finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,11 @@ fn handle_module(
|
|||||||
cranelift_module::Linkage::Export,
|
cranelift_module::Linkage::Export,
|
||||||
&context.func.signature,
|
&context.func.signature,
|
||||||
)?;
|
)?;
|
||||||
module.define_function(fid, &mut context, &mut Default::default())?;
|
module.define_function_with_control_plane(
|
||||||
|
fid,
|
||||||
|
&mut context,
|
||||||
|
&mut Default::default(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.print {
|
if options.print {
|
||||||
|
|||||||
Reference in New Issue
Block a user