Merge finalize_definitions into finish

This commit is contained in:
bjorn3
2020-09-30 13:58:13 +02:00
parent 4483c3740a
commit 7608749647
4 changed files with 14 additions and 39 deletions

View File

@@ -146,12 +146,6 @@ where
contents: &ModuleContents<Self>, contents: &ModuleContents<Self>,
); );
/// "Publish" all finalized functions and data objects to their ultimate destinations.
///
/// This method is not relevant for `Backend` implementations that do not provide
/// `Backend::FinalizedFunction` or `Backend::FinalizedData`.
fn publish(&mut self);
/// Consume this `Backend` and return a result. Some implementations may /// Consume this `Backend` and return a result. Some implementations may
/// provide additional functionality through this result. /// provide additional functionality through this result.
fn finish( fn finish(

View File

@@ -682,16 +682,15 @@ where
); );
} }
/// Finalize all functions and data objects that are defined but not yet finalized. /// Return the target isa
/// All symbols referenced in their bodies that are declared as needing a definition pub fn isa(&self) -> &dyn isa::TargetIsa {
/// must be defined by this point. self.backend.isa()
/// }
/// Use `get_finalized_function` and `get_finalized_data` to obtain the final
/// artifacts. /// Consume the module and return the resulting `Product`. Some `Backend`
/// /// implementations may provide additional functionality available after
/// This method is not relevant for `Backend` implementations that do not provide /// a `Module` is complete.
/// `Backend::FinalizedFunction` or `Backend::FinalizedData`. pub fn finish(mut self) -> B::Product {
pub fn finalize_definitions(&mut self) {
for func in self.functions_to_finalize.drain(..) { for func in self.functions_to_finalize.drain(..) {
let info = &self.contents.functions[func]; let info = &self.contents.functions[func];
debug_assert!(info.decl.linkage.is_definable()); debug_assert!(info.decl.linkage.is_definable());
@@ -714,18 +713,6 @@ where
&self.contents, &self.contents,
); );
} }
self.backend.publish();
}
/// Return the target isa
pub fn isa(&self) -> &dyn isa::TargetIsa {
self.backend.isa()
}
/// Consume the module and return the resulting `Product`. Some `Backend`
/// implementations may provide additional functionality available after
/// a `Module` is complete.
pub fn finish(self) -> B::Product {
self.backend.finish(self.names, self.contents) self.backend.finish(self.names, self.contents)
} }
} }

View File

@@ -437,10 +437,6 @@ impl Backend for ObjectBackend {
// Nothing to do. // Nothing to do.
} }
fn publish(&mut self) {
// Nothing to do.
}
fn finish( fn finish(
mut self, mut self,
_names: HashMap<String, FuncOrDataId>, _names: HashMap<String, FuncOrDataId>,

View File

@@ -572,12 +572,6 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
} }
} }
fn publish(&mut self) {
// Now that we're done patching, prepare the memory for execution!
self.memory.readonly.set_readonly();
self.memory.code.set_readable_and_executable();
}
/// SimpleJIT emits code and data into memory as it processes them. This /// SimpleJIT emits code and data into memory as it processes them. This
/// method performs no additional processing, but returns a handle which /// method performs no additional processing, but returns a handle which
/// allows freeing the allocated memory. Otherwise said memory is leaked /// allows freeing the allocated memory. Otherwise said memory is leaked
@@ -586,10 +580,14 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
/// This method does not need to be called when access to the memory /// This method does not need to be called when access to the memory
/// handle is not required. /// handle is not required.
fn finish( fn finish(
self, mut self,
names: HashMap<String, FuncOrDataId>, names: HashMap<String, FuncOrDataId>,
contents: ModuleContents<Self>, contents: ModuleContents<Self>,
) -> Self::Product { ) -> Self::Product {
// Now that we're done patching, prepare the memory for execution!
self.memory.readonly.set_readonly();
self.memory.code.set_readable_and_executable();
SimpleJITProduct { SimpleJITProduct {
memory: self.memory, memory: self.memory,
names, names,