@@ -5,13 +5,16 @@ open HolKernel Parse boolLib bossLib;
55open optionTheory bdd_sptrees_genTheory pairTheory bdd_genTheory tables_specTheory tables_spec_oldTheory policy_specTheory pred_specTheory;
66
77open sptrees_bdd_trans_ProgTheory;
8+ (* open bdd_trans_ProgTheory; *)
89open preamble basis ml_translatorLib ;
910
1011open miscTheory ;
1112open fromSexpTheory;
1213
1314
1415val _ = translation_extends " sptrees_bdd_trans_Prog" ;
16+ (* val _ = translation_extends "bdd_trans_Prog"; *)
17+
1518
1619
1720val _ = type_abbrev(" action_policy_type" , “:((string# num list) action_expr) policy”);
4144val start_cpu_stage2_io = Timer.startCPUTimer ();
4245val start_real_stage2_io = Timer.startRealTimer ();
4346
47+ (* *********************************************************)
48+ (* prepp policy: translation to CakeML *)
49+ (* *********************************************************)
4450
4551Definition policy_order_test_def:
4652 policy_order_test = (^policy_order:string list)
5561val r = translate policy_content_test_def;
5662
5763
64+
5865Definition policy_main_hol4_def:
5966 policy_main_hol4 =
6067 case sp_mk_BDD_policy policy_content_test policy_order_test of
6168 | NONE => NONE
6269 | SOME (r,sp_edges,sp_labels) => SOME (r,
6370 ((toSortedAList sp_edges):edges),
6471 ((toSortedAList sp_labels): (((string#num list) action_expr) policy, (string#num list) action_expr) labelings) )
65- End
66-
67-
72+ End
6873
6974
75+ (* Definition policy_main_hol4_def:
76+ policy_main_hol4 =
77+ mk_BDDPred_opt (policy_structure) (0,[],[(0, non_termn (NONE, policy_content_test))]) [] (policy_order_test) 1n
78+ End *)
7079
7180val r = translate policy_main_hol4_def;
7281
@@ -108,12 +117,11 @@ val prog =
108117 `` |> EVAL |> concl |> rhs;
109118
110119
111-
120+ (* write the translation to an sexp file *)
112121val _ = astToSexprLib.write_ast_to_file " ../../bdd_cake_test/test_bdd_policy.sexp" prog;
113122
114- val _ = time_stage (" Stage 2 from var policy to sexp - cakeML trans " , start_cpu_stage2_io, start_real_stage2_io);
115- val start_cpu_stage2_io2 = Timer.startCPUTimer ();
116- val start_real_stage2_io2 = Timer.startRealTimer ();
123+ val _ = print " AA:finished trans \n " ;
124+
117125
118126val status_compile_sexp = OS.Process.system " cd ../../bdd_cake_test/ && CML_STACK_SIZE=2048 CML_HEAP_SIZE=8192 ./cake --sexp=true --exclude_prelude=true --skip_type_inference=false --jump=false --reg_alg=0 < test_bdd_policy.sexp > test_bdd_policy.cake.S"
119127
@@ -129,42 +137,46 @@ val _ = if OS.Process.isSuccess status_cc
129137 else (print " Nej, policy cc compilation failed\n " ;
130138 OS.Process.exit OS.Process.failure)
131139
140+ val _ = time_stage (" Stage 2 translate var POLICY term to sexp, cc compile, link for cakeML prepp " , start_cpu_stage2_io, start_real_stage2_io);
141+ val start_cpu_stage2_io2 = Timer.startCPUTimer ();
142+ val start_real_stage2_io2 = Timer.startRealTimer ();
143+
144+ (* ***********************************************************)
145+ (* Compile policy's translation using CakeML compiler *)
146+ (* ***********************************************************)
147+
148+
132149val status_exec = OS.Process.system " cd ../../bdd_cake_test/ && time ./test_bdd_policy.cake > bdd_policy_cakeml_export.txt" ;
133150
134151val _ = if OS.Process.isSuccess status_exec
135- then print " Ja, policy cc compilation completed\n "
136- else (print " Nej, policy cc compilation failed\n " ;
152+ then print " Ja, policy BDD compilation completed\n "
153+ else (print " Nej, policy NDD compilation failed\n " ;
137154 OS.Process.exit OS.Process.failure)
138155
139- val _ = time_stage (" Stage 2 cakeML compiliation var policy to bdd " , start_cpu_stage2_io2, start_real_stage2_io2);
156+
157+
158+ val _ = time_stage (" Stage 2 cakeML compilation var policy to BDD " , start_cpu_stage2_io2, start_real_stage2_io2);
159+
140160val start_cpu_stage2_io3 = Timer.startCPUTimer ();
141161val start_real_stage2_io3 = Timer.startRealTimer ();
142162
143163(*
144-
164+ Individual commands:
145165cp test_bdd_policy.sexp ../../bdd_cake_test
146-
147166CML_STACK_SIZE=2048 CML_HEAP_SIZE=8192 ./cake --sexp=true --exclude_prelude=true --skip_type_inference=false --jump=false --reg_alg=0 < test_bdd_policy.sexp > test_bdd_policy.cake.S
148-
149167cc test_bdd_policy.cake.S basis_ffi.c -lm -o test_bdd_policy.cake -lm
150-
151168time ./test_bdd_policy.cake > bdd_policy_cakeml_export.txt
152-
153-
154169*)
155170
156171
157-
158-
159-
160-
161-
172+ (* ***********************************************************)
173+ (* Fetch policy's BDD from the output text file *)
174+ (* ***********************************************************)
162175
163176val ins = TextIO.openIn " ../../bdd_cake_test/bdd_policy_cakeml_export.txt" ;
164177val policy_content_str = TextIO.inputAll ins;
165178val _ = TextIO.closeIn ins;
166179
167- val _ = time_stage (" Stage 2 from Policy to var BDD total " , start_cpu_stage2_io, start_real_stage2_io);
168180
169181(* open Term;*)
170182
@@ -187,15 +199,24 @@ val policy_bdd_content_term =
187199 parsed
188200end ;
189201
202+ val _ = print " AA:finished cleaning input \n " ;
190203
191204
192205
206+ (* ***********************************************************)
207+ (* Generate a table using sml function *)
208+ (* ***********************************************************)
193209
194210val test_groupings = rhs(concl(EVAL policy_full_order));
195211val gen_var_table_auto = bdd_utilsLib.bdd_to_tables_iterative policy_bdd_content_term test_groupings;
196212
213+ val _ = print " AA:finished creating table \n " ;
197214
198215
216+ (* *********************************************************)
217+ (* prepp table: translation to CakeML *)
218+ (* *********************************************************)
219+
199220Definition table_content_test_def:
200221 table_content_test = (^gen_var_table_auto : action_table_type)
201222End
@@ -213,6 +234,13 @@ Definition table_main_hol4_def:
213234End
214235
215236
237+ (*
238+ Definition table_main_hol4_def:
239+ table_main_hol4 =
240+ mk_BDDPred_opt (table_structure) (0,[],[(0, non_termn (NONE, table_content_test))]) [] (policy_order_test) 1n
241+ End *)
242+
243+
216244val r = translate table_main_hol4_def;
217245
218246
@@ -254,33 +282,44 @@ val prog =
254282
255283val _ = astToSexprLib.write_ast_to_file " ../../bdd_cake_test/test_bdd_table.sexp" prog;
256284
257- val _ = time_stage (" Stage 2 prepp out table and recompile cakeml translation " , start_cpu_stage2_io3, start_real_stage2_io3);
258- val start_cpu_stage2_io4 = Timer.startCPUTimer ();
259- val start_real_stage2_io4 = Timer.startRealTimer ();
285+ val _ = print " AA:finished translating table \n " ;
260286
261287
288+ val status = OS.Process.system " cd ../../bdd_cake_test/ && CML_STACK_SIZE=2048 CML_HEAP_SIZE=8192 ./cake --sexp=true --exclude_prelude=true --skip_type_inference=false --jump=false --reg_alg=0 < test_bdd_table.sexp > test_bdd_table.cake.S && cc test_bdd_table.cake.S basis_ffi.c -lm -o test_bdd_table.cake -lm"
262289
263- val status = OS.Process.system " cd ../../bdd_cake_test/ && CML_STACK_SIZE=2048 CML_HEAP_SIZE=8192 ./cake --sexp=true --exclude_prelude=true --skip_type_inference=false --jump=false --reg_alg=0 < test_bdd_table.sexp > test_bdd_table.cake.S && cc test_bdd_table.cake.S basis_ffi.c -lm -o test_bdd_table.cake -lm && time ./test_bdd_table.cake > bdd_table_cakeml_export.txt"
290+ val _ = time_stage (" Stage 2 translate var TABLE term to sexp, cc compile, link for cakeML prepp " , start_cpu_stage2_io3, start_real_stage2_io3);
291+ val start_cpu_stage2_io4 = Timer.startCPUTimer ();
292+ val start_real_stage2_io4 = Timer.startRealTimer ();
264293
265294val _ = if OS.Process.isSuccess status
266- then print " Ja, table cakeML compilation completed\n "
267- else (print " Nej, table cakeML compilation failed\n " ;
295+ then print " Ja, table BDD compilation completed\n "
296+ else (print " Nej, table BDD compilation failed\n " ;
268297 OS.Process.exit OS.Process.failure)
269298
299+ (* ***********************************************************)
300+ (* Compile table's translation using CakeML compiler *)
301+ (* ***********************************************************)
302+
303+ val status = OS.Process.system " cd ../../bdd_cake_test/ && time ./test_bdd_table.cake > bdd_table_cakeml_export.txt"
304+
305+ val _ = time_stage (" Stage 2 cakeML compilation var TABLE to BDD " , start_cpu_stage2_io4, start_real_stage2_io4);
306+
270307
308+ (* ***********************************************************)
309+ (* Fetch table's BDD from the output text file *)
310+ (* ***********************************************************)
271311
272312(*
273313reset_translation
274314val _ = astPP.enable_astPP ();
275315val _ = (max_print_depth := 200);
276316*)
277317
278-
279-
280318val ins = TextIO.openIn " ../../bdd_cake_test/bdd_table_cakeml_export.txt" ;
281319val tbl_content_str = TextIO.inputAll ins;
282320val _ = TextIO.closeIn ins;
283321
322+ val _ = print " AA:finished getting sexp table to hol4 \n " ;
284323
285324
286325
@@ -303,11 +342,7 @@ val table_bdd_content_term =
303342 parsed
304343end ;
305344
306-
307-
308- val _ = time_stage (" Stage 2 cakeML compiliation var table to BDD " , start_cpu_stage2_io4, start_real_stage2_io4);
309-
310- val _ = time_stage (" Stage 2 from TABLE to var BDD total " , start_cpu_stage2_io3, start_real_stage2_io3);
345+ val _ = print " AA:finished cleaning sexp table in hol4 \n " ;
311346
312347in
313348(policy_bdd_content_term, gen_var_table_auto, table_bdd_content_term)
0 commit comments