Move alignment config from declare_data to define_data
This commit is contained in:
@@ -62,7 +62,6 @@ where
|
||||
linkage: Linkage,
|
||||
writable: bool,
|
||||
tls: bool,
|
||||
align: Option<u8>,
|
||||
) -> ModuleResult<DataId>;
|
||||
|
||||
/// Define a function, producing the function body from the given `Context`.
|
||||
|
||||
@@ -50,6 +50,8 @@ pub struct DataDescription {
|
||||
pub data_relocs: Vec<(CodeOffset, ir::GlobalValue, Addend)>,
|
||||
/// Object file section
|
||||
pub custom_segment_section: Option<(String, String)>,
|
||||
/// Alignment
|
||||
pub align: Option<u64>,
|
||||
}
|
||||
|
||||
/// This is to data objects what cranelift_codegen::Context is to functions.
|
||||
@@ -68,6 +70,7 @@ impl DataContext {
|
||||
function_relocs: vec![],
|
||||
data_relocs: vec![],
|
||||
custom_segment_section: None,
|
||||
align: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -79,6 +82,8 @@ impl DataContext {
|
||||
self.description.data_decls.clear();
|
||||
self.description.function_relocs.clear();
|
||||
self.description.data_relocs.clear();
|
||||
self.description.custom_segment_section = None;
|
||||
self.description.align = None;
|
||||
}
|
||||
|
||||
/// Define a zero-initialized object with the given size.
|
||||
@@ -100,6 +105,12 @@ impl DataContext {
|
||||
self.description.custom_segment_section = Some((seg.to_owned(), sec.to_owned()))
|
||||
}
|
||||
|
||||
/// Set the alignment for data. The alignment must be a power of two.
|
||||
pub fn set_align(&mut self, align: u64) {
|
||||
assert!(align.is_power_of_two());
|
||||
self.description.align = Some(align);
|
||||
}
|
||||
|
||||
/// Declare an external function import.
|
||||
///
|
||||
/// Users of the `Module` API generally should call
|
||||
|
||||
@@ -182,14 +182,12 @@ pub struct DataDeclaration {
|
||||
pub linkage: Linkage,
|
||||
pub writable: bool,
|
||||
pub tls: bool,
|
||||
pub align: Option<u8>,
|
||||
}
|
||||
|
||||
impl DataDeclaration {
|
||||
fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool, align: Option<u8>) {
|
||||
fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool) {
|
||||
self.linkage = Linkage::merge(self.linkage, linkage);
|
||||
self.writable = self.writable || writable;
|
||||
self.align = self.align.max(align);
|
||||
assert_eq!(
|
||||
self.tls, tls,
|
||||
"Can't change TLS data object to normal or in the opposite way",
|
||||
@@ -291,7 +289,6 @@ impl ModuleDeclarations {
|
||||
linkage: Linkage,
|
||||
writable: bool,
|
||||
tls: bool,
|
||||
align: Option<u8>, // An alignment bigger than 128 is unlikely
|
||||
) -> ModuleResult<(DataId, &DataDeclaration)> {
|
||||
// TODO: Can we avoid allocating names so often?
|
||||
use super::hash_map::Entry::*;
|
||||
@@ -299,7 +296,7 @@ impl ModuleDeclarations {
|
||||
Occupied(entry) => match *entry.get() {
|
||||
FuncOrDataId::Data(id) => {
|
||||
let existing = &mut self.data_objects[id];
|
||||
existing.merge(linkage, writable, tls, align);
|
||||
existing.merge(linkage, writable, tls);
|
||||
Ok((id, existing))
|
||||
}
|
||||
|
||||
@@ -313,7 +310,6 @@ impl ModuleDeclarations {
|
||||
linkage,
|
||||
writable,
|
||||
tls,
|
||||
align,
|
||||
});
|
||||
entry.insert(FuncOrDataId::Data(id));
|
||||
Ok((id, &self.data_objects[id]))
|
||||
@@ -410,10 +406,9 @@ where
|
||||
linkage: Linkage,
|
||||
writable: bool,
|
||||
tls: bool,
|
||||
align: Option<u8>, // An alignment bigger than 128 is unlikely
|
||||
) -> ModuleResult<DataId> {
|
||||
self.backend
|
||||
.declare_data(name, linkage, writable, tls, align)
|
||||
.declare_data(name, linkage, writable, tls)
|
||||
}
|
||||
|
||||
/// Use this when you're building the IR of a function to reference a function.
|
||||
|
||||
Reference in New Issue
Block a user