Skip to content

Commit fd88aae

Browse files
authoredMar 13, 2025··
Add --asm-node-reveal-depth (#2055)
1 parent 45d5829 commit fd88aae

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
 

‎src/Assembly/Symbolic.v

+12-1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ Module Export Options.
404404
Class rewriting_passes_opt := rewriting_passes : list rewrite_pass.
405405
(** Should we symex the assembly first, even though this may be more inefficient? *)
406406
Class debug_symex_asm_first_opt := debug_symex_asm_first : bool.
407+
(** How deep should we reveal nodes? *)
408+
Class node_reveal_depth_opt := node_reveal_depth : nat.
407409
Definition default_rewriting_passes
408410
{rewriting_pipeline : rewriting_pipeline_opt}
409411
{rewriting_pass_filter : rewriting_pass_filter_opt}
@@ -414,19 +416,24 @@ Module Export Options.
414416
{ asm_rewriting_pipeline : rewriting_pipeline_opt
415417
; asm_rewriting_pass_filter : rewriting_pass_filter_opt
416418
; asm_debug_symex_asm_first : debug_symex_asm_first_opt
419+
; asm_node_reveal_depth : node_reveal_depth_opt
417420
}.
418421

422+
Definition default_node_reveal_depth := 3%nat.
423+
419424
(* This holds the list of computed options, which are passed around between methods *)
420425
Class symbolic_options_computed_opt :=
421426
{ asm_rewriting_passes : rewriting_passes_opt
422427
; asm_debug_symex_asm_first_computed : debug_symex_asm_first_opt
428+
; asm_node_reveal_depth_computed : node_reveal_depth_opt
423429
}.
424430

425431
(* N.B. The default rewriting pass filter should not be changed here, but instead changed in CLI.v where it is derived from a default string *)
426432
Definition default_symbolic_options : symbolic_options_opt
427433
:= {| asm_rewriting_pipeline := default_rewrite_pass_order
428434
; asm_rewriting_pass_filter := fun _ => true
429435
; asm_debug_symex_asm_first := false
436+
; asm_node_reveal_depth := default_node_reveal_depth
430437
|}.
431438
End Options.
432439
Module Export Hints.
@@ -439,6 +446,8 @@ Module Export Hints.
439446
asm_rewriting_passes
440447
asm_debug_symex_asm_first
441448
asm_debug_symex_asm_first_computed
449+
asm_node_reveal_depth
450+
asm_node_reveal_depth_computed
442451
.
443452
#[global]
444453
Hint Cut [
@@ -448,6 +457,8 @@ Module Export Hints.
448457
| asm_rewriting_passes
449458
| asm_debug_symex_asm_first
450459
| asm_debug_symex_asm_first_computed
460+
| asm_node_reveal_depth
461+
| asm_node_reveal_depth_computed
451462
) ( _ * )
452463
(Build_symbolic_options_opt
453464
| Build_symbolic_options_computed_opt
@@ -3808,7 +3819,7 @@ Qed.
38083819
End Rewrite.
38093820

38103821
Definition simplify {opts : symbolic_options_computed_opt} (dag : dag) (e : node idx) :=
3811-
Rewrite.expr dag (reveal_node_at_least dag 3 e).
3822+
Rewrite.expr dag (reveal_node_at_least dag node_reveal_depth e).
38123823

38133824
Lemma eval_simplify {opts : symbolic_options_computed_opt} G d n v : gensym_dag_ok G d -> eval_node G d n v -> eval G d (simplify d n) v.
38143825
Proof using Type. eauto using Rewrite.eval_expr, eval_node_reveal_node_at_least. Qed.

‎src/CLI.v

+10
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ Module ForExtraction.
519519
Arg.Custom (parse_string_and parse_callee_saved_registers) "REG",
520520
["Either '" ++ show System_V_AMD64 ++ "' (indicating " ++ String.concat "," (List.map show system_v_amd64_assembly_callee_saved_registers) ++ "), '" ++ show Microsoft_x64 ++ "' (indicating " ++ String.concat "," (List.map show microsoft_x64_assembly_callee_saved_registers) ++ "), or a comma-separated list of registers which are callee-saved / non-volatile. Only relevant when --hints-file is specified."
521521
; "Defaults to " ++ show default_assembly_callee_saved_registers ++ "."]).
522+
Definition asm_node_reveal_depth_spec : named_argT
523+
:= ([Arg.long_key "asm-node-reveal-depth"],
524+
Arg.Custom (parse_string_and parse_nat) "ℕ",
525+
["The depth of nodes to reveal in the assembly equivalence checker. Only relevant when --hints-file is specified. In most situations, this should not have to be changed. Defaults to " ++ show default_node_reveal_depth ++ "."]).
522526
Definition asm_stack_size_spec : named_argT
523527
:= ([Arg.long_key "asm-stack-size"],
524528
Arg.Custom (parse_string_and parse_N) "ℕ",
@@ -734,6 +738,7 @@ Module ForExtraction.
734738
; asm_error_on_unique_names_mismatch_spec
735739
; asm_rewriting_pipeline_spec
736740
; asm_rewriting_passes_spec
741+
; asm_node_reveal_depth_spec
737742
; asm_debug_symex_asm_first_spec
738743
; doc_text_before_function_name_spec
739744
; doc_text_before_type_name_spec
@@ -793,6 +798,7 @@ Module ForExtraction.
793798
, asm_error_on_unique_names_mismatchv
794799
, asm_rewriting_pipelinev
795800
, asm_rewriting_passesv
801+
, asm_node_reveal_depthv
796802
, asm_debug_symex_asm_firstv
797803
, doc_text_before_function_namev
798804
, doc_text_before_type_namev
@@ -806,6 +812,7 @@ Module ForExtraction.
806812
let to_bool ls := (0 <? List.length ls)%nat in
807813
let to_string_list ls := List.map (@snd _ _) ls in
808814
let to_N_list ls := List.map (@snd _ _) (List.map (@snd _ _) ls) in
815+
let to_nat_list ls := List.map (@snd _ _) (List.map (@snd _ _) ls) in
809816
let to_Z_flat_list ls := List.flat_map (@snd _ _) (List.map (@snd _ _) ls) in
810817
let to_reg_list ls := match List.map (@snd _ _) (List.map (@snd _ _) ls) with
811818
| nil => None
@@ -820,6 +827,8 @@ Module ForExtraction.
820827
let to_assembly_callee_saved_registers_default ls default := Option.value (to_assembly_callee_saved_registers_opt ls) default in
821828
let to_N_opt ls := choose_one_of_many (to_N_list ls) in
822829
let to_N_default ls default := Option.value (to_N_opt ls) default in
830+
let to_nat_opt ls := choose_one_of_many (to_nat_list ls) in
831+
let to_nat_default ls default := Option.value (to_nat_opt ls) default in
823832
let to_string_opt ls := choose_one_of_many (to_string_list ls) in
824833
let to_string_default ls default := Option.value (to_string_opt ls) default in
825834
let to_capitalization_data_opt ls := choose_one_of_many (List.map (fun '(_, (_, v)) => v) ls) in
@@ -882,6 +891,7 @@ Module ForExtraction.
882891
{| asm_rewriting_pipeline := to_rewriting_pipeline_list asm_rewriting_pipelinev
883892
; asm_rewriting_pass_filter := fun p => asm_rewriting_pass_filterv (show_rewrite_pass p)
884893
; asm_debug_symex_asm_first := to_bool asm_debug_symex_asm_firstv
894+
; asm_node_reveal_depth := to_nat_default asm_node_reveal_depthv default_node_reveal_depth
885895
|}
886896
|}
887897
; ignore_unique_asm_names := negb (to_bool asm_error_on_unique_names_mismatchv)

0 commit comments

Comments
 (0)
Please sign in to comment.