Struct evmil::util::Interval

source ·
pub struct Interval {
    pub start: usize,
    pub end: usize,
}
Expand description

Represents an interval of values x..y (much like Range<usize>) which supports various arithmetic operations.

Fields§

§start: usize§end: usize

Implementations§

Examples found in repository?
src/util/interval.rs (line 79)
78
79
80
    fn from(r:Range<usize>) -> Interval {
	Interval::new(r.start,r.end)
    }
Examples found in repository?
src/dfa/stack.rs (line 17)
17
pub const EMPTY_STACK : AbstractStack = AbstractStack{lower: Interval::new_const(0,0), upper: Vec::new()};

Check whether this interval represents a constant value. For example, the interval 1..1 represents the constant 1.

Exctract the constant value associated with this interval.

Add a constant to this range.

Examples found in repository?
src/dfa/stack.rs (line 91)
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
169
170
171
172
173
174
175
176
177
178
179
180
181
    pub fn len(&self) -> Interval {
        self.lower.add(self.upper.len())
    }
    /// Determine the minimum length of any stack represented by this
    /// abstract stack.
    pub fn min_len(&self) -> usize {
        self.lower.start + self.upper.len()
    }
    /// Determine the maximum length of any stack represented by this
    /// abstract stack.
    pub fn max_len(&self) -> usize {
        self.lower.end + self.upper.len()
    }
    /// Push an iterm onto this stack.
    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!");
        }
    }

    /// Merge two abstract stacks together.
    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
    }

Subtract a constant from this range.

Examples found in repository?
src/dfa/stack.rs (line 123)
118
119
120
121
122
123
124
125
126
127
128
129
    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
    }

Union this interval with another

Examples found in repository?
src/dfa/stack.rs (line 172)
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
    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
    }

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
Converts to this type from the input type.
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
Compare self to key and return true if they are equal.

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.