1
1
2
2
import front:: ast:: ident;
3
3
import std:: vec;
4
- import std :: bitv ;
4
+ import tritv :: * ;
5
5
6
+ type precond = t ;
6
7
7
- /*
8
- This says: this expression requires the idents in <pre> to be initialized,
9
- and given the precondition, it guarantees that the idents in <post> are
10
- initialized.
11
- */
12
- type precond = bitv:: t ;
8
+ /* 2 means "this constraint may or may not be true after execution"
9
+ 1 means "this constraint is definitely true after execution"
10
+ 0 means "this constraint is definitely false after execution" */
11
+ type postcond = t ;
13
12
14
13
15
- /* 1 means "this variable must be initialized"
16
- 0 means "don't care about this variable" */
17
- type postcond = bitv:: t ;
14
+ /* 2 means "don't know about this constraint"
15
+ 1 means "this constraint is definitely true before entry"
16
+ 0 means "this constraint is definitely false on entry" */
17
+ type prestate = t ;
18
18
19
19
20
- /* 1 means "this variable is initialized"
21
- 0 means "don't know about this variable */
22
- type prestate = bitv:: t ;
20
+ /* similar to postcond */
21
+ type poststate = t ;
23
22
24
23
25
24
/* 1 means "this variable is definitely initialized"
26
25
0 means "don't know whether this variable is
27
26
initialized" */
28
- type poststate = bitv:: t ;
29
-
30
27
31
- /* 1 means "this variable is definitely initialized"
32
- 0 means "don't know whether this variable is
33
- initialized" */
28
+ /*
29
+ This says: this expression requires the constraints whose value is 1 in
30
+ <pre> to be true, and given the precondition, it guarantees that the
31
+ constraints in <post> whose values are 1 are true, and that the constraints
32
+ in <post> whose values are 0 are false.
33
+ */
34
34
35
35
/* named thus so as not to confuse with prestate and poststate */
36
36
type pre_and_post = @rec ( precond precondition , postcond postcondition ) ;
@@ -44,7 +44,7 @@ type pre_and_post_state = rec(prestate prestate, poststate poststate);
44
44
type ts_ann = @rec ( pre_and_post conditions, pre_and_post_state states) ;
45
45
46
46
fn true_precond ( uint num_vars ) -> precond {
47
- be bitv :: create ( num_vars, false ) ;
47
+ be create_tritv ( num_vars) ;
48
48
}
49
49
50
50
fn true_postcond ( uint num_vars ) -> postcond { be true_precond ( num_vars) ; }
@@ -54,7 +54,9 @@ fn empty_prestate(uint num_vars) -> prestate { be true_precond(num_vars); }
54
54
fn empty_poststate ( uint num_vars ) -> poststate { be true_precond ( num_vars) ; }
55
55
56
56
fn false_postcond ( uint num_vars ) -> postcond {
57
- be bitv:: create ( num_vars, true ) ;
57
+ auto res = create_tritv ( num_vars) ;
58
+ tritv_set_all ( res) ;
59
+ ret res;
58
60
}
59
61
60
62
fn empty_pre_post ( uint num_vars ) -> pre_and_post {
@@ -77,12 +79,16 @@ fn get_pre(&pre_and_post p) -> precond { ret p.precondition; }
77
79
fn get_post ( & pre_and_post p) -> postcond { ret p. postcondition ; }
78
80
79
81
fn difference ( & precond p1, & precond p2) -> bool {
80
- be bitv :: difference ( p1, p2) ;
82
+ ret tritv_difference ( p1, p2) ;
81
83
}
82
84
83
- fn union ( & precond p1, & precond p2) -> bool { be bitv:: union ( p1, p2) ; }
85
+ fn union ( & precond p1, & precond p2) -> bool {
86
+ ret tritv_union ( p1, p2) ;
87
+ }
84
88
85
- fn intersect ( & precond p1, & precond p2) -> bool { be bitv:: intersect ( p1, p2) ; }
89
+ fn intersect ( & precond p1, & precond p2) -> bool {
90
+ ret tritv_intersect ( p1, p2) ;
91
+ }
86
92
87
93
fn pps_len ( & pre_and_post p) -> uint {
88
94
// gratuitous check
@@ -93,86 +99,88 @@ fn pps_len(&pre_and_post p) -> uint {
93
99
94
100
fn require ( uint i, & pre_and_post p) {
95
101
// sets the ith bit in p's pre
96
-
97
- bitv:: set ( p. precondition , i, true ) ;
102
+ tritv_set ( i, p. precondition , ttrue) ;
98
103
}
99
104
100
105
fn require_and_preserve ( uint i, & pre_and_post p) {
101
106
// sets the ith bit in p's pre and post
102
-
103
- bitv:: set ( p. precondition , i, true ) ;
104
- bitv:: set ( p. postcondition , i, true ) ;
107
+ tritv_set ( i, p. precondition , ttrue) ;
108
+ tritv_set ( i, p. postcondition , ttrue) ;
105
109
}
106
110
107
111
fn set_in_postcond ( uint i, & pre_and_post p) -> bool {
108
112
// sets the ith bit in p's post
109
-
110
- auto was_set = bitv:: get ( p. postcondition , i) ;
111
- bitv:: set ( p. postcondition , i, true ) ;
112
- ret !was_set;
113
+ auto was_set = tritv_get ( p. postcondition , i) ;
114
+ tritv_set ( i, p. postcondition , ttrue) ;
115
+ ret was_set != ttrue;
113
116
}
114
117
115
118
fn set_in_poststate ( uint i, & pre_and_post_state s) -> bool {
116
119
// sets the ith bit in p's post
117
-
118
- auto was_set = bitv:: get ( s. poststate , i) ;
119
- bitv:: set ( s. poststate , i, true ) ;
120
- ret !was_set;
120
+ auto was_set = tritv_get ( s. poststate , i) ;
121
+ tritv_set ( i, s. poststate , ttrue) ;
122
+ ret was_set != ttrue;
121
123
}
122
124
123
125
fn clear_in_poststate ( uint i, & pre_and_post_state s) -> bool {
124
126
// sets the ith bit in p's post
125
-
126
- auto was_set = bitv:: get ( s. poststate , i) ;
127
- bitv:: set ( s. poststate , i, false ) ;
128
- ret was_set;
127
+ auto was_set = tritv_get ( s. poststate , i) ;
128
+ tritv_set ( i, s. poststate , tfalse) ;
129
+ ret was_set != tfalse;
129
130
}
130
131
132
+ fn clear_in_postcond ( uint i, & pre_and_post s) -> bool {
133
+ // sets the ith bit in p's post
134
+ auto was_set = tritv_get ( s. postcondition , i) ;
135
+ tritv_set ( i, s. postcondition , tfalse) ;
136
+ ret was_set != tfalse;
137
+ }
131
138
132
139
// Sets all the bits in a's precondition to equal the
133
140
// corresponding bit in p's precondition.
134
141
fn set_precondition ( ts_ann a, & precond p) {
135
- bitv :: copy ( a. conditions . precondition , p) ;
142
+ tritv_copy ( a. conditions . precondition , p) ;
136
143
}
137
144
138
145
139
146
// Sets all the bits in a's postcondition to equal the
140
147
// corresponding bit in p's postcondition.
141
148
fn set_postcondition ( ts_ann a, & postcond p) {
142
- bitv :: copy ( a. conditions . postcondition , p) ;
149
+ tritv_copy ( a. conditions . postcondition , p) ;
143
150
}
144
151
145
152
146
153
// Sets all the bits in a's prestate to equal the
147
154
// corresponding bit in p's prestate.
148
155
fn set_prestate ( ts_ann a, & prestate p) -> bool {
149
- ret bitv :: copy ( a. states . prestate , p) ;
156
+ ret tritv_copy ( a. states . prestate , p) ;
150
157
}
151
158
152
159
153
160
// Sets all the bits in a's postcondition to equal the
154
161
// corresponding bit in p's postcondition.
155
162
fn set_poststate ( ts_ann a, & poststate p) -> bool {
156
- ret bitv :: copy ( a. states . poststate , p) ;
163
+ ret tritv_copy ( a. states . poststate , p) ;
157
164
}
158
165
159
166
160
167
// Set all the bits in p that are set in new
161
168
fn extend_prestate ( & prestate p, & poststate new) -> bool {
162
- ret bitv :: union ( p, new) ;
169
+ ret tritv_union ( p, new) ;
163
170
}
164
171
165
172
166
173
// Set all the bits in p that are set in new
167
174
fn extend_poststate ( & poststate p, & poststate new) -> bool {
168
- ret bitv :: union ( p, new) ;
175
+ ret tritv_union ( p, new) ;
169
176
}
170
177
171
- // Clears the given bit in p
178
+ // Sets the given bit in p to "don't care"
179
+ // FIXME: is this correct?
172
180
fn relax_prestate ( uint i, & prestate p) -> bool {
173
- auto was_set = bitv :: get ( p, i) ;
174
- bitv :: set ( p , i , false ) ;
175
- ret was_set;
181
+ auto was_set = tritv_get ( p, i) ;
182
+ tritv_set ( i , p , dont_care ) ;
183
+ ret was_set != dont_care ;
176
184
}
177
185
178
186
// Clears the given bit in p
@@ -185,12 +193,11 @@ fn relax_precond(uint i, &precond p) {
185
193
relax_prestate ( i, p) ;
186
194
}
187
195
188
- // Clears all the bits in p
189
- fn clear ( & precond p) { bitv:: clear ( p) ; }
190
-
196
+ // Sets all the bits in p to "don't care"
197
+ fn clear ( & precond p) { tritv_clear ( p) ; }
191
198
192
- // Sets all the bits in p
193
- fn set ( & precond p) { bitv :: set_all ( p) ; }
199
+ // Sets all the bits in p to true
200
+ fn set ( & precond p) { tritv_set_all ( p) ; }
194
201
195
202
fn ann_precond ( & ts_ann a) -> precond { ret a. conditions . precondition ; }
196
203
@@ -203,16 +210,17 @@ fn pp_clone(&pre_and_post p) -> pre_and_post {
203
210
postcondition=clone ( p. postcondition ) ) ;
204
211
}
205
212
206
- fn clone ( prestate p) -> prestate { ret bitv :: clone ( p) ; }
213
+ fn clone ( prestate p) -> prestate { ret tritv_clone ( p) ; }
207
214
208
215
209
216
// returns true if a implies b
210
217
// that is, returns true except if for some bits c and d,
211
- // c = 1 and d = 0
212
- fn implies ( bitv:: t a, bitv:: t b) -> bool {
213
- auto tmp = bitv:: clone ( b) ;
214
- bitv:: difference ( tmp, a) ;
215
- ret bitv:: is_false ( tmp) ;
218
+ // c = 1 and d = either 0 or "don't know"
219
+ // FIXME: is this correct?
220
+ fn implies ( t a, t b) -> bool {
221
+ auto tmp = tritv_clone ( b) ;
222
+ tritv_difference ( tmp, a) ;
223
+ ret tritv_doesntcare ( tmp) ;
216
224
}
217
225
//
218
226
// Local Variables:
0 commit comments