Skip to content

Commit 13509a4

Browse files
Adding the necessary fixes for the specific V1Model externs in the symbexec tests
1 parent 9ed9f40 commit 13509a4

File tree

5 files changed

+47
-39
lines changed

5 files changed

+47
-39
lines changed

hol/p4_v1modelScript.sml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,8 @@ Definition get_oracle_calls_array_def:
292292
End
293293

294294
Definition v1model_register_construct_inner_def:
295-
(v1model_register_construct_inner size width oracle_index random_oracle =
295+
v1model_register_construct_inner size width oracle_index random_oracle =
296296
get_oracle_calls_array width oracle_index random_oracle size
297-
)
298297
End
299298

300299
Definition register_construct_def:
@@ -304,7 +303,7 @@ Definition register_construct_def:
304303
(case lookup_lval scope_list (lval_varname (varn_name "targ1")) of
305304
| SOME (v_bit (bl', n')) =>
306305
let size = v2n bl in
307-
let width = v2n bl' in
306+
let width = n' in
308307
let ext_obj_map' = AUPDATE ext_obj_map (counter, INR (v1model_v_ext_register (v1model_register_construct_inner size width oracle_index random_oracle))) in
309308
(case assign scope_list (v_ext_ref counter) (lval_varname (varn_name "this")) of
310309
| SOME scope_list' =>

hol/symb_exec/p4_symb_execLib.sml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -729,26 +729,6 @@ fun p4_should_branch (fty_map, b_fty_map, pblock_action_names_map) const_actions
729729
(*
730730
val apply (tbl_name, e) = apply (“"t2"”, “[e_v (v_bit ([e1; e2; e3; e4; e5; e6; e7; T],8))]”);
731731
732-
basic:
733-
val apply (tbl_name, e) = apply
734-
(“"spd"”,
735-
“[e_v
736-
(v_bit
737-
([ip128; ip129; ip130; ip131; ip132; ip133; ip134; ip135; ip136;
738-
ip137; ip138; ip139; ip140; ip141; ip142; ip143; ip144; ip145;
739-
ip146; ip147; ip148; ip149; ip150; ip151; ip152; ip153; ip154;
740-
ip155; ip156; ip157; ip158; ip159],32));
741-
e_v (v_bit ([ip72; ip73; ip74; ip75; ip76; ip77; ip78; ip79],8))]”);
742-
743-
ARBs:
744-
val apply (tbl_name, e) = apply
745-
(“"forward"”,
746-
“[e_v
747-
(v_bit
748-
([ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB;
749-
ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB;
750-
ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB],32))]”);
751-
752732
*)
753733
if (hurdUtils.forall is_e_v) (fst $ dest_list e) andalso
754734
(* Perform a symbolic branch if the apply expression (list) contains
@@ -805,7 +785,7 @@ basic:
805785
*)
806786
val i = #1 $ dest_aenv $ #1 $ dest_astate astate
807787
(* TODO: Unify with the syntactic function obtaining the state above? *)
808-
val (ab_list, pblock_map, _, _, _, _, _, _, _, _, _, _, _) = dest_actx $ rhs $ concl ctx_def
788+
val (ab_list, pblock_map, _, _, _, _, _, _, _, _, _, _, _) = dest_actx $ rhs $ snd $ strip_forall $ concl ctx_def
809789
val (curr_block, _) = dest_arch_block_pbl $ rhs $ concl $ HOL4P4_CONV $ mk_el (i, ab_list)
810790

811791
(* TODO: All of the information extracted from the ctx below could be
@@ -3027,7 +3007,7 @@ fun p4_debug_symb_exec arch_ty ctx_data (fty_map, b_fty_map, pblock_action_names
30273007
(ctx_tm, hd $ Defn.eqns_of $ Defn.mk_defn ctx_name (mk_eq(mk_var(ctx_name, type_of ctx_tm), ctx_tm)))
30283008
end
30293009
| def_thm ctx_def =>
3030-
(rhs $ concl ctx_def, ctx_def)
3010+
(snd $ strip_forall $ rhs $ concl ctx_def, ctx_def)
30313011

30323012
val (path_tree, state_list) = p4_symb_exec 1 true arch_ty (ctx_def, ctx) (fty_map, b_fty_map, pblock_action_names_map) const_actions_tables path_cond_defs init_astate stop_consts_rewr stop_consts_never thms_to_add path_cond NONE fuel
30333013
val state_list_tms = map (fn (path_id, path_cond, step_thm) => (path_id, path_cond, dest_step_thm step_thm)) state_list

hol/symb_exec/p4_symb_exec_v1modelLib.sml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,25 @@ fun approx_v1model_register_construct p4_symb_arg_prefix fv_index scope_list asc
3838
val array_size = fst $ dest_pair $ dest_v_bit $ lookup_var "size" scope_list
3939
val targ1_width = snd $ dest_pair $ dest_v_bit $ lookup_var "targ1" scope_list
4040
val oracle_index = #5 $ dest_v1model_ascope ascope
41-
val tm1 = mk_v1model_register_construct_inner (array_size, targ1_width, oracle_index, random_oracle_tm)
4241

4342
(* TODO: HOL4P4_CONV? *)
4443
val array_size_num = rhs $ concl $ EVAL (mk_v2n array_size)
4544

45+
val tm1 = mk_v1model_register_construct_inner (array_size_num, targ1_width, oracle_index, random_oracle_tm)
46+
4647
(* TODO: Hacky... *)
4748
val rhs_tm = hd $ fst $ dest_list $ fixedwidth_freevars_fromindex_ty (p4_symb_arg_prefix, fv_index, 1, mk_list_type $ mk_prod (mk_list_type bool, num))
4849
val goal_tm = mk_disj_list [boolSyntax.mk_exists (rhs_tm, mk_conj (mk_eq (tm1, rhs_tm), (mk_wellformed_register_array (targ1_width, rhs_tm))))]
4950

5051
val approx_thm =
5152
(* “^goal_tm” *)
52-
(* TODO: Fix this *)
5353
prove(goal_tm,
54-
SIMP_TAC std_ss [disj_list_def, v1model_register_construct_inner_def (*, wellformed_register_array_replicate_arb *)]
54+
(*
55+
SIMP_TAC std_ss [disj_list_def, v1model_register_construct_inner_def, get_oracle_calls_array_def] >>
56+
*)
57+
(* TODO: Why doesn't just the above work? Make more efficient solution... *)
58+
SIMP_TAC bool_ss [disj_list_def] >>
59+
EVAL_TAC
5560
);
5661
in
5762
SOME (approx_thm, [fv_index+1])
@@ -83,8 +88,23 @@ fun approx_v1model_register_read p4_symb_arg_prefix fv_index scope_list ascope =
8388
rpt (goal_term (fn tm => tmCases_on (fst $ dest_eq $ snd $ strip_exists tm) []) >> FULL_SIMP_TAC list_ss [])
8489
);
8590

91+
val oracle_index_int = int_of_term oracle_index
92+
val w = (int_of_term entry_width)-1
93+
94+
(* TODO: Move? *)
95+
fun provide_oracle_witnesses oracle_index_int 0 =
96+
exists_tac (mk_comb (random_oracle_tm, term_of_int oracle_index_int))
97+
| provide_oracle_witnesses oracle_index_int w =
98+
let
99+
val curr_index = oracle_index_int + w
100+
in
101+
provide_oracle_witnesses oracle_index_int (w-1) >>
102+
exists_tac (mk_comb (random_oracle_tm, term_of_int curr_index))
103+
end
104+
;
105+
86106
val approx_thm =
87-
(* “^goal_tm” *)
107+
(* “^(mk_imp (mk_wellformed_register_array (entry_width, array), goal_tm))*)
88108
prove(mk_imp (mk_wellformed_register_array (entry_width, array), goal_tm),
89109
(* As soon as possible, hide the array, which may be big *)
90110
markerLib.ABBREV_TAC (mk_eq (mk_var("array", mk_list_type (mk_prod (mk_list_type bool, num))) ,array)) >>
@@ -94,7 +114,10 @@ fun approx_v1model_register_read p4_symb_arg_prefix fv_index scope_list ascope =
94114
CASE_TAC >- (
95115
(* TODO: HOL4P4_TAC or other solution? *)
96116
EVAL_TAC >>
117+
(*
97118
ntac (int_of_term entry_width) (exists_tac (mk_arb bool)) >>
119+
*)
120+
provide_oracle_witnesses oracle_index_int w >>
98121
REWRITE_TAC []
99122
) >>
100123
Cases_on ‘x’ >>

hol/symb_exec/tests/register_readScript.sml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ val symb_exec7_astate_symb =
265265
("action_run",v_bit (REPLICATE 32 F,32))],NONE)]],
266266
arch_frame_list_empty,status_running):v1model_ascope astate``;
267267

268-
val fty_map' = optionSyntax.dest_some $ rhs $ concl $ EVAL “deparameterise_ftymap_entries ^symb_exec7_ftymap”
268+
val fty_map' = optionSyntax.dest_some $ rhs $ concl $ EVAL “deparameterise_ftymap_entries ^symb_exec7_ftymap”
269269
val b_fty_map' = optionSyntax.dest_some $ rhs $ concl $ EVAL “deparameterise_b_ftymap_entries ^symb_exec7_blftymap”
270270

271271
val symb_exec7_ctx_tm = “(^fty_map', ^b_fty_map', ^symb_exec7_pblock_action_names_map)”
@@ -297,6 +297,12 @@ val fuel = 1;
297297
val postcond_rewr_thms = []
298298
val postcond_simpset = pure_ss
299299

300+
(*
301+
#3 $ el 1 $ snd $ p4_symb_exec 1 debug_flag arch_ty (ctx_def, ctx) (fty_map, b_fty_map, pblock_action_names_map) const_actions_tables path_cond_defs init_astate stop_consts_rewr stop_consts_never thms_to_add path_cond p4_is_finished_alt_opt 20;
302+
303+
#3 $ el 1 $ snd $ p4_symb_exec 1 debug_flag arch_ty (ctx_def, ctx) (fty_map, b_fty_map, pblock_action_names_map) const_actions_tables path_cond_defs init_astate stop_consts_rewr stop_consts_never thms_to_add path_cond p4_is_finished_alt_opt 21;
304+
*)
305+
300306
val time_start = Time.now();
301307
(*
302308
val p4_symb_exec_fun = (p4_symb_exec 1)

hol/symb_exec/tests/table_unknownScript.sml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ val symb_exec6_actx = ``([arch_block_inp;
135135
v1model_input_f
136136
(v_struct
137137
[("h",
138-
v_header ARB
138+
v_header F
139139
[("row",
140140
v_struct
141-
[("e",v_bit ([ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB],8));
141+
[("e",v_bit ([F; F; F; F; F; F; F; F],8));
142142
("t",
143143
v_bit
144-
([ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB;
145-
ARB; ARB; ARB; ARB; ARB],16));
146-
("l",v_bit ([ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB],8));
147-
("r",v_bit ([ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB],8));
148-
("v",v_bit ([ARB; ARB; ARB; ARB; ARB; ARB; ARB; ARB],8))])])],
144+
([F; F; F; F; F; F; F; F; F; F; F;
145+
F; F; F; F; F],16));
146+
("l",v_bit ([F; F; F; F; F; F; F; F],8));
147+
("r",v_bit ([F; F; F; F; F; F; F; F],8));
148+
("v",v_bit ([F; F; F; F; F; F; F; F],8))])])],
149149
v_struct []),v1model_output_f,v1model_copyin_pbl,v1model_copyout_pbl,
150150
v1model_apply_table_f,
151151
[("header",NONE,
@@ -231,8 +231,8 @@ val symb_exec6_astate_symb = rhs $ concl $ EVAL ``p4_append_input_list [([e1; e2
231231
e_v (v_bit ([F; F; F; F; F; T; T; F; T],9))])])],0),
232232
[[(varn_name "gen_apply_result",
233233
v_struct
234-
[("hit",v_bool ARB); ("miss",v_bool ARB);
235-
("action_run",v_bit (REPLICATE 32 ARB,32))],NONE)]],
234+
[("hit",v_bool F); ("miss",v_bool T);
235+
("action_run",v_bit (REPLICATE 32 F,32))],NONE)]],
236236
arch_frame_list_empty,status_running):v1model_ascope astate``;
237237

238238
(* Additional parts of the context relevant only to symbolic execution *)

0 commit comments

Comments
 (0)