Refactor stack leak code
This commit is contained in:
parent
bc64734add
commit
5f47092a65
@ -18,11 +18,7 @@ macro_rules! leak_on {
|
|||||||
fn $name(&mut self, id: usize) {
|
fn $name(&mut self, id: usize) {
|
||||||
let read = ReadType::$variant(id);
|
let read = ReadType::$variant(id);
|
||||||
|
|
||||||
for i in 0..self.stack.len() {
|
self.stack.leak_into(&mut self.code, |v| v.has_read(read))
|
||||||
if self.stack.has_read_at(i, read) {
|
|
||||||
self.leak_at(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -172,16 +168,8 @@ impl StatList {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leak_at(&mut self, index: usize) {
|
|
||||||
if let Some(set) = self.stack.leak_at(index) {
|
|
||||||
self.code.push(set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn leak_all(&mut self) {
|
fn leak_all(&mut self) {
|
||||||
for i in 0..self.stack.len() {
|
self.stack.leak_into(&mut self.code, |_| true);
|
||||||
self.leak_at(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leak_on!(leak_local_write, Local);
|
leak_on!(leak_local_write, Local);
|
||||||
|
@ -20,6 +20,10 @@ impl Slot {
|
|||||||
fn is_temporary(&self, id: usize) -> bool {
|
fn is_temporary(&self, id: usize) -> bool {
|
||||||
matches!(self.data, Expression::GetTemporary(ref v) if v.var == id)
|
matches!(self.data, Expression::GetTemporary(ref v) if v.var == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_read(&self, id: ReadType) -> bool {
|
||||||
|
self.read.contains(&id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -97,10 +101,6 @@ impl Stack {
|
|||||||
range
|
range
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_read_at(&self, index: usize, read: ReadType) -> bool {
|
|
||||||
self.var_list[index].read.contains(&read)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the alignment necessary for this block to branch out to a
|
// Return the alignment necessary for this block to branch out to a
|
||||||
// another given stack frame
|
// another given stack frame
|
||||||
pub fn get_br_alignment(&self, par_start: usize, par_result: usize) -> Align {
|
pub fn get_br_alignment(&self, par_start: usize, par_result: usize) -> Align {
|
||||||
@ -115,12 +115,15 @@ impl Stack {
|
|||||||
|
|
||||||
// Try to leak a slot's value to a `SetTemporary` instruction,
|
// Try to leak a slot's value to a `SetTemporary` instruction,
|
||||||
// adjusting the capacity and old index accordingly
|
// adjusting the capacity and old index accordingly
|
||||||
pub fn leak_at(&mut self, index: usize) -> Option<Statement> {
|
pub fn leak_into<P>(&mut self, code: &mut Vec<Statement>, predicate: P)
|
||||||
let old = &mut self.var_list[index];
|
where
|
||||||
let var = self.previous + index;
|
P: Fn(&Slot) -> bool,
|
||||||
|
{
|
||||||
|
for (i, old) in self.var_list.iter_mut().enumerate() {
|
||||||
|
let var = self.previous + i;
|
||||||
|
|
||||||
if old.is_temporary(var) {
|
if old.is_temporary(var) || !predicate(old) {
|
||||||
return None;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
old.read.clear();
|
old.read.clear();
|
||||||
@ -133,6 +136,7 @@ impl Stack {
|
|||||||
|
|
||||||
self.capacity = self.capacity.max(var + 1);
|
self.capacity = self.capacity.max(var + 1);
|
||||||
|
|
||||||
Some(set)
|
code.push(set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user