Remove the DataContext wrapper around DataDescription (#6170)

* Remove the DataContext wrapper around DataDescription

It doesn't have much of a purpose while making it harder to for example
rewrite the function and data object declarations within it as is
necessary for deserializing a serialized module.

* Derive Debug for DataDescription
This commit is contained in:
bjorn3
2023-04-06 19:13:55 +02:00
committed by GitHub
parent e1812b611b
commit 67c85b883e
5 changed files with 143 additions and 175 deletions

View File

@@ -8,7 +8,7 @@ use cranelift_codegen::{binemit::Reloc, CodegenError};
use cranelift_control::ControlPlane;
use cranelift_entity::SecondaryMap;
use cranelift_module::{
DataContext, DataDescription, DataId, FuncId, Init, Linkage, Module, ModuleCompiledFunction,
DataDescription, DataId, FuncId, Init, Linkage, Module, ModuleCompiledFunction,
ModuleDeclarations, ModuleError, ModuleExtName, ModuleReloc, ModuleResult,
};
use log::info;
@@ -837,7 +837,7 @@ impl Module for JITModule {
Ok(ModuleCompiledFunction { size: total_size })
}
fn define_data(&mut self, id: DataId, data: &DataContext) -> ModuleResult<()> {
fn define_data(&mut self, id: DataId, data: &DataDescription) -> ModuleResult<()> {
let decl = self.declarations.get_data_decl(id);
if !decl.linkage.is_definable() {
return Err(ModuleError::InvalidImportDefinition(decl.name.clone()));
@@ -857,7 +857,7 @@ impl Module for JITModule {
data_relocs: _,
custom_segment_section: _,
align,
} = data.description();
} = data;
let size = init.size();
let ptr = if decl.writable {
@@ -896,10 +896,7 @@ impl Module for JITModule {
PointerWidth::U32 => Reloc::Abs4,
PointerWidth::U64 => Reloc::Abs8,
};
let relocs = data
.description()
.all_relocs(pointer_reloc)
.collect::<Vec<_>>();
let relocs = data.all_relocs(pointer_reloc).collect::<Vec<_>>();
self.compiled_data_objects[id] = Some(CompiledBlob { ptr, size, relocs });
self.data_objects_to_finalize.push(id);