mirror of https://github.com/rust-lang/rust.git
Simplify define_global_for_alloc_id
This commit is contained in:
parent
1031c659e0
commit
c40788c1b2
|
@ -133,22 +133,17 @@ fn trans_const_place<'a, 'tcx: 'a>(
|
||||||
// If ret.1 is true, then the global didn't exist before
|
// If ret.1 is true, then the global didn't exist before
|
||||||
fn define_global_for_alloc_id<'a, 'tcx: 'a, B: Backend>(
|
fn define_global_for_alloc_id<'a, 'tcx: 'a, B: Backend>(
|
||||||
module: &mut Module<B>,
|
module: &mut Module<B>,
|
||||||
cx: &mut ConstantCx,//<'a, 'tcx>,
|
cx: &mut ConstantCx,
|
||||||
alloc_id: AllocId,
|
alloc_id: AllocId,
|
||||||
todo: &mut HashMap<AllocId, DataId>,
|
todo: &mut HashMap<AllocId, DataId>,
|
||||||
) -> (DataId, bool) {
|
) -> DataId {
|
||||||
use std::collections::hash_map::Entry;
|
*cx.constants.entry(alloc_id).or_insert_with(|| {
|
||||||
match cx.constants.entry(alloc_id) {
|
let data_id = module
|
||||||
Entry::Occupied(mut occ) => (*occ.get_mut(), false),
|
.declare_data(&alloc_id.0.to_string(), Linkage::Local, false)
|
||||||
Entry::Vacant(vac) => {
|
.unwrap();
|
||||||
let data_id = module
|
todo.insert(alloc_id, data_id);
|
||||||
.declare_data(&alloc_id.0.to_string(), Linkage::Local, false)
|
data_id
|
||||||
.unwrap();
|
})
|
||||||
todo.insert(alloc_id, data_id);
|
|
||||||
vac.insert(data_id);
|
|
||||||
(data_id, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_global_for_alloc_id<'a, 'tcx: 'a, B: Backend + 'a>(
|
fn get_global_for_alloc_id<'a, 'tcx: 'a, B: Backend + 'a>(
|
||||||
|
@ -185,7 +180,7 @@ fn get_global_for_alloc_id<'a, 'tcx: 'a, B: Backend + 'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
for &(offset, reloc) in alloc.relocations.iter() {
|
for &(offset, reloc) in alloc.relocations.iter() {
|
||||||
let data_id = define_global_for_alloc_id(module, cx, reloc, &mut todo).0;
|
let data_id = define_global_for_alloc_id(module, cx, reloc, &mut todo);
|
||||||
|
|
||||||
let reloc_offset = {
|
let reloc_offset = {
|
||||||
let endianness = memory.endianness();
|
let endianness = memory.endianness();
|
||||||
|
|
Loading…
Reference in New Issue