11use std:: cmp:: Ordering ;
22
3- use jingle:: modeling:: ModeledBlock ;
4- use jingle:: sleigh:: { GeneralizedVarNode , IndirectVarNode , Instruction , VarNode } ;
5-
63use crate :: gadget:: Gadget ;
4+ use jingle:: modeling:: ModeledBlock ;
5+ use jingle:: sleigh:: { GeneralizedVarNode , IndirectVarNode , Instruction , SpaceManager , SpaceType , VarNode } ;
6+ use tracing:: trace;
77
88#[ derive( Clone , Debug ) ]
99pub struct GadgetSignature {
1010 outputs : Vec < GeneralizedVarNode > ,
11- #[ allow( unused) ]
12- inputs : Vec < GeneralizedVarNode > ,
1311}
1412
1513impl GadgetSignature {
1614 /// For now this is very naive; just want a very rough filter to make sure we aren't
1715 /// throwing completely pointless work at z3
1816 pub fn covers ( & self , other : & GadgetSignature ) -> bool {
17+ trace ! ( "{:?} vs {:?}" , self . outputs, other. outputs) ;
1918 varnode_set_covers ( & self . outputs , & other. outputs )
2019 }
2120
@@ -45,18 +44,24 @@ impl PartialOrd<GadgetSignature> for GadgetSignature {
4544 }
4645 }
4746}
48- impl From < & Instruction > for GadgetSignature {
49- fn from ( value : & Instruction ) -> Self {
47+ impl GadgetSignature {
48+ pub ( crate ) fn from_instr < T : SpaceManager > ( value : & Instruction , t : & T ) -> Self {
5049 let mut outputs = Vec :: new ( ) ;
51- let mut inputs = Vec :: new ( ) ;
5250
5351 for op in & value. ops {
5452 if let Some ( op) = op. output ( ) {
55- outputs. push ( op) ;
53+ if let GeneralizedVarNode :: Direct ( v) = & op {
54+ if let Some ( h) = t. get_space_info ( v. space_index ) {
55+ if h. _type == SpaceType :: IPTR_PROCESSOR {
56+ outputs. push ( op) ;
57+ }
58+ }
59+ } else {
60+ outputs. push ( op) ;
61+ }
5662 }
57- inputs. extend ( op. inputs ( ) )
5863 }
59- Self { outputs, inputs }
64+ Self { outputs }
6065 }
6166}
6267
@@ -72,21 +77,27 @@ impl<'ctx> From<&ModeledBlock<'ctx>> for GadgetSignature {
7277 inputs. extend ( op. inputs ( ) )
7378 }
7479 }
75- Self { outputs, inputs }
80+ Self { outputs }
7681 }
7782}
7883
7984impl From < & Gadget > for GadgetSignature {
8085 fn from ( value : & Gadget ) -> Self {
8186 let mut outputs = Vec :: new ( ) ;
82- let mut inputs = Vec :: new ( ) ;
8387 for op in value. instructions . iter ( ) . flat_map ( |i| & i. ops ) {
8488 if let Some ( op) = op. output ( ) {
85- outputs. push ( op) ;
89+ if let GeneralizedVarNode :: Direct ( v) = & op {
90+ if let Some ( h) = value. get_space_info ( v. space_index ) {
91+ if h. _type == SpaceType :: IPTR_PROCESSOR {
92+ outputs. push ( op) ;
93+ }
94+ }
95+ } else {
96+ outputs. push ( op) ;
97+ }
8698 }
87- inputs. extend ( op. inputs ( ) )
8899 }
89- Self { outputs, inputs }
100+ Self { outputs }
90101 }
91102}
92103
@@ -139,23 +150,13 @@ mod tests {
139150 space_index: 0 ,
140151 offset: 0 ,
141152 } ) ] ,
142- inputs : vec ! [ Direct ( VarNode {
143- size: 4 ,
144- space_index: 0 ,
145- offset: 0 ,
146- } ) ] ,
147153 } ;
148154 let o2 = GadgetSignature {
149155 outputs : vec ! [ Direct ( VarNode {
150156 size: 4 ,
151157 space_index: 0 ,
152158 offset: 0 ,
153159 } ) ] ,
154- inputs : vec ! [ Direct ( VarNode {
155- size: 4 ,
156- space_index: 0 ,
157- offset: 0 ,
158- } ) ] ,
159160 } ;
160161 assert ! ( o1. covers( & o2) ) ;
161162 assert ! ( o2. covers( & o1) ) ;
@@ -172,23 +173,13 @@ mod tests {
172173 space_index: 0 ,
173174 offset: 0 ,
174175 } ) ] ,
175- inputs : vec ! [ Direct ( VarNode {
176- size: 4 ,
177- space_index: 0 ,
178- offset: 0 ,
179- } ) ] ,
180176 } ;
181177 let o2 = GadgetSignature {
182178 outputs : vec ! [ Direct ( VarNode {
183179 size: 4 ,
184180 space_index: 0 ,
185181 offset: 3 ,
186182 } ) ] ,
187- inputs : vec ! [ Direct ( VarNode {
188- size: 4 ,
189- space_index: 0 ,
190- offset: 0 ,
191- } ) ] ,
192183 } ;
193184 assert_ne ! ( o1, o2) ;
194185 assert ! ( !o1. covers( & o2) ) ;
@@ -203,23 +194,13 @@ mod tests {
203194 space_index: 0 ,
204195 offset: 0 ,
205196 } ) ] ,
206- inputs : vec ! [ Direct ( VarNode {
207- size: 4 ,
208- space_index: 0 ,
209- offset: 0 ,
210- } ) ] ,
211197 } ;
212198 let o2 = GadgetSignature {
213199 outputs : vec ! [ Direct ( VarNode {
214200 size: 4 ,
215201 space_index: 0 ,
216202 offset: 4 ,
217203 } ) ] ,
218- inputs : vec ! [ Direct ( VarNode {
219- size: 4 ,
220- space_index: 0 ,
221- offset: 0 ,
222- } ) ] ,
223204 } ;
224205 assert ! ( !o1. covers( & o2) ) ;
225206 assert ! ( !o2. covers( & o1) ) ;
@@ -233,11 +214,6 @@ mod tests {
233214 space_index: 0 ,
234215 offset: 7 ,
235216 } ) ] ,
236- inputs : vec ! [ Direct ( VarNode {
237- size: 4 ,
238- space_index: 0 ,
239- offset: 0 ,
240- } ) ] ,
241217 } ;
242218 let o2 = GadgetSignature {
243219 outputs : vec ! [
@@ -262,11 +238,6 @@ mod tests {
262238 offset: 16 ,
263239 } ) ,
264240 ] ,
265- inputs : vec ! [ Direct ( VarNode {
266- size: 4 ,
267- space_index: 0 ,
268- offset: 0 ,
269- } ) ] ,
270241 } ;
271242 assert ! ( o2. covers( & o1) ) ;
272243 assert ! ( !o1. covers( & o2) ) ;
0 commit comments