Skip to content

Commit 7a24fb2

Browse files
according to this commit, we decided to ignore the sptrees implementation and focus on alists
1 parent 3f013f6 commit 7a24fb2

37 files changed

+6215
-655
lines changed

hol/policy_to_table/bdd_cake_trans/apply_trans_to_IOLib.sml

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ open HolKernel Parse boolLib bossLib;
55
open optionTheory bdd_sptrees_genTheory pairTheory bdd_genTheory tables_specTheory tables_spec_oldTheory policy_specTheory pred_specTheory;
66

77
open sptrees_bdd_trans_ProgTheory;
8+
(* open bdd_trans_ProgTheory; *)
89
open preamble basis ml_translatorLib ;
910

1011
open miscTheory ;
1112
open fromSexpTheory;
1213

1314

1415
val _ = translation_extends "sptrees_bdd_trans_Prog";
16+
(* val _ = translation_extends "bdd_trans_Prog"; *)
17+
1518

1619

1720
val _ = type_abbrev("action_policy_type", “:((string# num list) action_expr) policy”);
@@ -41,6 +44,9 @@ let
4144
val start_cpu_stage2_io = Timer.startCPUTimer ();
4245
val start_real_stage2_io = Timer.startRealTimer ();
4346

47+
(**********************************************************)
48+
(* prepp policy: translation to CakeML *)
49+
(**********************************************************)
4450

4551
Definition policy_order_test_def:
4652
policy_order_test = (^policy_order:string list)
@@ -55,18 +61,21 @@ End
5561
val r = translate policy_content_test_def;
5662

5763

64+
5865
Definition 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

7180
val 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 *)
112121
val _ = 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

118126
val 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+
132149
val status_exec = OS.Process.system "cd ../../bdd_cake_test/ && time ./test_bdd_policy.cake > bdd_policy_cakeml_export.txt";
133150

134151
val _ = 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+
140160
val start_cpu_stage2_io3 = Timer.startCPUTimer ();
141161
val start_real_stage2_io3 = Timer.startRealTimer ();
142162

143163
(*
144-
164+
Individual commands:
145165
cp test_bdd_policy.sexp ../../bdd_cake_test
146-
147166
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
148-
149167
cc test_bdd_policy.cake.S basis_ffi.c -lm -o test_bdd_policy.cake -lm
150-
151168
time ./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

163176
val ins = TextIO.openIn "../../bdd_cake_test/bdd_policy_cakeml_export.txt";
164177
val policy_content_str = TextIO.inputAll ins;
165178
val _ = 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
188200
end;
189201

202+
val _ = print "AA:finished cleaning input \n";
190203

191204

192205

206+
(************************************************************)
207+
(* Generate a table using sml function *)
208+
(************************************************************)
193209

194210
val test_groupings = rhs(concl(EVAL policy_full_order));
195211
val 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+
199220
Definition table_content_test_def:
200221
table_content_test = (^gen_var_table_auto : action_table_type)
201222
End
@@ -213,6 +234,13 @@ Definition table_main_hol4_def:
213234
End
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+
216244
val r = translate table_main_hol4_def;
217245

218246

@@ -254,33 +282,44 @@ val prog =
254282

255283
val _ = 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

265294
val _ = 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
(*
273313
reset_translation
274314
val _ = astPP.enable_astPP ();
275315
val _ = (max_print_depth := 200);
276316
*)
277317

278-
279-
280318
val ins = TextIO.openIn "../../bdd_cake_test/bdd_table_cakeml_export.txt";
281319
val tbl_content_str = TextIO.inputAll ins;
282320
val _ = 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
304343
end;
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

312347
in
313348
(policy_bdd_content_term, gen_var_table_auto, table_bdd_content_term)

0 commit comments

Comments
 (0)