Revision 355b543d src/backends/Riny/riny_backend.ml
src/backends/Riny/riny_backend.ml  

130  130  
131  131 
let pp_randomized_input fmt v = 
132  132 
Format.fprintf fmt "%s = rand(1, 1);" v.var_id 
133 


133  
134  
135 
(* We iterate through instructions. Boolean constants are kept are used to 

136 
simplify branches *) 

137 
let rec simplify_instrs instrs boolcsts = 

138 
match instrs with 

139 
 MLocalAssign(i, (Cst(Const_tag tag) as cst))::tl 

140 
 MStateAssign(i, (Cst(Const_tag tag) as cst))::tl 

141 
when tag = tag_true  tag = tag_false 

142 
> 

143 
let boolcsts' = 

144 
if List.mem_assoc i boolcsts then 

145 
((i, cst)::(List.remove_assoc i boolcsts)) 

146 
else 

147 
((i, cst)::boolcsts) 

148 
in 

149 
simplify_instrs tl boolcsts' 

150 
 (MBranch (g, branches))::tl > ( 

151 
(* Check whether we can simplify these binary branches *) 

152 
let g' = Machine_code.partial_eval boolcsts g in 

153 
match g' with 

154 
 Cst (Const_tag t) > simplify_instrs ((List.assoc t branches)@tl) boolcsts 

155 
 _ > 

156 
let branches' = List.map (fun (l, instrs_l) > l, simplify_instrs instrs_l boolcsts) branches in 

157 
MBranch(g', branches')::(simplify_instrs tl boolcsts) 

158  
159 
) 

160 
 hd::tl > hd::(simplify_instrs tl boolcsts) 

161 
 [] > [] 

162 


134  163 
let translate fmt basename normalized_prog machines = 
135  164 
(* No modular compilation: require a main node *) 
136  165 
let main_node = 
...  ...  
148  177 

149  178 
(* Project instrs to init and step versions *) 
150  179 
let init, step = extract_init_step main_node main_node.mstep.step_instrs in 
151 
let init = Optimize_machine.instrs_fusion init in


152 
let step = Optimize_machine.instrs_fusion step in


180 
let init = simplify_instrs init [] in


181 
let step = simplify_instrs step [] in


153  182 
(* Removing bool assigns that remain from _arrow *) 
154  183 
let init = filter_bool_assigns init in 
155  184 
let step = filter_bool_assigns step in 
Also available in: Unified diff