Introduce DataDescription::all_relocs to dedup some code
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! Defines `DataContext`.
|
||||
|
||||
use cranelift_codegen::binemit::{Addend, CodeOffset};
|
||||
use cranelift_codegen::binemit::{Addend, CodeOffset, Reloc};
|
||||
use cranelift_codegen::entity::PrimaryMap;
|
||||
use cranelift_codegen::ir;
|
||||
use std::borrow::ToOwned;
|
||||
@@ -8,6 +8,8 @@ use std::boxed::Box;
|
||||
use std::string::String;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::RelocRecord;
|
||||
|
||||
/// This specifies how data is to be initialized.
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum Init {
|
||||
@@ -55,6 +57,34 @@ pub struct DataDescription {
|
||||
pub align: Option<u64>,
|
||||
}
|
||||
|
||||
impl DataDescription {
|
||||
/// An iterator over all relocations of the data object.
|
||||
pub fn all_relocs<'a>(
|
||||
&'a self,
|
||||
pointer_reloc: Reloc,
|
||||
) -> impl Iterator<Item = RelocRecord> + 'a {
|
||||
let func_relocs = self
|
||||
.function_relocs
|
||||
.iter()
|
||||
.map(move |&(offset, id)| RelocRecord {
|
||||
reloc: pointer_reloc,
|
||||
offset,
|
||||
name: self.function_decls[id].clone(),
|
||||
addend: 0,
|
||||
});
|
||||
let data_relocs = self
|
||||
.data_relocs
|
||||
.iter()
|
||||
.map(move |&(offset, id, addend)| RelocRecord {
|
||||
reloc: pointer_reloc,
|
||||
offset,
|
||||
name: self.data_decls[id].clone(),
|
||||
addend,
|
||||
});
|
||||
func_relocs.chain(data_relocs)
|
||||
}
|
||||
}
|
||||
|
||||
/// This is to data objects what cranelift_codegen::Context is to functions.
|
||||
pub struct DataContext {
|
||||
description: DataDescription,
|
||||
|
||||
Reference in New Issue
Block a user