Struct evmil::dfa::AbstractStack

source ·
pub struct AbstractStack { /* private fields */ }

Implementations§

Examples found in repository?
src/dfa/stack.rs (line 179)
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    pub fn merge(self, other: &AbstractStack) -> Self {
        let slen = self.upper.len();
        let olen = other.upper.len();
        // Determine common upper length
        let n = cmp::min(slen,olen);
        // Normalise lower segments
        let lself = self.lower.add(slen - n);
        let lother = other.lower.add(olen - n);
        let mut merger = AbstractStack::new(lself.union(&lother),Vec::new());
        // Push merged items from upper segment
        for i in (0..n).rev() {
            let ithself = self.peek(i);
            let ithother = other.peek(i);
            merger = merger.push(ithself.merge(ithother));
        }
        // Done
        merger
    }
Examples found in repository?
src/cfa.rs (line 37)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    pub fn is_bottom(&self) -> bool {
        self.stack.is_bottom()
    }
    pub fn len(&self) -> Interval {
        self.stack.len()
    }
    pub fn push(self, val: AbstractValue) -> Self {
        CfaState::new(self.stack.push(val))
    }
    pub fn pop(mut self, n: usize) -> Self {
        assert!(n > 0);
        let mut stack = self.stack;
        for i in 0..n {
            stack = stack.pop();
        }
        CfaState::new(stack)
    }
    pub fn set(self, n:usize, val: AbstractValue) -> Self {
        CfaState::new(self.stack.set(n,val))
    }
}

impl Clone for CfaState {
    fn clone(&self) -> Self {
        CfaState::new(self.stack.clone())
    }
}

impl fmt::Display for CfaState {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f,"{}",self.stack)
    }
}

impl AbstractState for CfaState {
    fn is_reachable(&self) -> bool { !self.stack.is_bottom() }
More examples
Hide additional examples
src/dfa/stack.rs (line 113)
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    pub fn push(mut self, val: AbstractValue) -> Self {
        // Should never be called on bottom
        assert!(!self.is_bottom());
        //
        if val == AbstractValue::Unknown && self.upper.len() == 0 {
            self.lower = self.lower.add(1);
        } else {
            // Pop target address off the stack.
            self.upper.push(val);
        }
        // Done
        self
    }
    /// Pop an item of this stack, producing an updated state.
    pub fn pop(mut self) -> Self {
        // Should never be called on bottom
        assert!(!self.is_bottom());
        // Pop target address off the stack.
        if self.upper.is_empty() {
            self.lower = self.lower.sub(1);
        } else {
            self.upper.pop();
        }
        // Done
        self
    }
    /// Perk nth item on the stack (where `0` is top).
    pub fn peek(&self, n: usize) -> AbstractValue {
        // Should never be called on bottom
        assert!(!self.is_bottom());
        // Get the nth value!
        if n < self.upper.len() {
            // Determine stack index
            let i = self.upper.len() - (1+n);
            // Extract value
            self.upper[i]
        } else {
            AbstractValue::Unknown
        }
    }
    /// Set specific item on this stack.
    pub fn set(mut self, n: usize, val: AbstractValue) -> Self {
        // Should never be called on bottom
        assert!(!self.is_bottom());
        if n < self.upper.len() {
            // Determine stack index
            let i = self.upper.len() - (1+n);
            // Set value
            self.upper[i] = val;
            // Done
            self
        } else {
            // This case is complicated because we need to expand the
            // upper portion to include the new value (where
            // possible).
            todo!("Implement me!");
        }
    }

Determine possible lengths of the stack as an interval

Examples found in repository?
src/cfa.rs (line 40)
39
40
41
    pub fn len(&self) -> Interval {
        self.stack.len()
    }

Determine the minimum length of any stack represented by this abstract stack.

Determine the maximum length of any stack represented by this abstract stack.

Push an iterm onto this stack.

Examples found in repository?
src/cfa.rs (line 43)
42
43
44
    pub fn push(self, val: AbstractValue) -> Self {
        CfaState::new(self.stack.push(val))
    }
More examples
Hide additional examples
src/dfa/stack.rs (line 184)
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    pub fn merge(self, other: &AbstractStack) -> Self {
        let slen = self.upper.len();
        let olen = other.upper.len();
        // Determine common upper length
        let n = cmp::min(slen,olen);
        // Normalise lower segments
        let lself = self.lower.add(slen - n);
        let lother = other.lower.add(olen - n);
        let mut merger = AbstractStack::new(lself.union(&lother),Vec::new());
        // Push merged items from upper segment
        for i in (0..n).rev() {
            let ithself = self.peek(i);
            let ithother = other.peek(i);
            merger = merger.push(ithself.merge(ithother));
        }
        // Done
        merger
    }

Pop an item of this stack, producing an updated state.

Examples found in repository?
src/cfa.rs (line 49)
45
46
47
48
49
50
51
52
    pub fn pop(mut self, n: usize) -> Self {
        assert!(n > 0);
        let mut stack = self.stack;
        for i in 0..n {
            stack = stack.pop();
        }
        CfaState::new(stack)
    }

Perk nth item on the stack (where 0 is top).

Examples found in repository?
src/cfa.rs (line 84)
83
84
85
    fn peek(&self, n: usize) -> AbstractValue {
        self.stack.peek(n)
    }
More examples
Hide additional examples
src/dfa/stack.rs (line 182)
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    pub fn merge(self, other: &AbstractStack) -> Self {
        let slen = self.upper.len();
        let olen = other.upper.len();
        // Determine common upper length
        let n = cmp::min(slen,olen);
        // Normalise lower segments
        let lself = self.lower.add(slen - n);
        let lother = other.lower.add(olen - n);
        let mut merger = AbstractStack::new(lself.union(&lother),Vec::new());
        // Push merged items from upper segment
        for i in (0..n).rev() {
            let ithself = self.peek(i);
            let ithother = other.peek(i);
            merger = merger.push(ithself.merge(ithother));
        }
        // Done
        merger
    }

Set specific item on this stack.

Examples found in repository?
src/cfa.rs (line 54)
53
54
55
    pub fn set(self, n:usize, val: AbstractValue) -> Self {
        CfaState::new(self.stack.set(n,val))
    }

Merge two abstract stacks together.

Examples found in repository?
src/dfa/stack.rs (line 199)
192
193
194
195
196
197
198
199
200
201
202
    pub fn merge_into(&mut self, other: &AbstractStack) -> bool {
        // NOTE: this could be done more efficiently.
        let old = self.clone();
        let mut tmp = EMPTY_STACK;
        // Install dummy value to keep self alive
        mem::swap(self, &mut tmp);
        // Perform merge
        *self = tmp.merge(other);
        // Check for change
        *self != old
    }

Merge an abstract stack into this stack, whilst reporting whether this stack changed or not.

Examples found in repository?
src/cfa.rs (line 94)
87
88
89
90
91
92
93
94
95
96
97
98
99
    fn merge(&mut self, other: Self) -> bool {
        if *self != other {
            if !other.is_bottom() {
                if self.is_bottom() {
                    *self = other;
                    return true;
                } else {
                    return self.stack.merge_into(&other.stack);
                }
            }
        }
        false
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.