@@ -518,14 +518,17 @@ module TestBack : CBackend = struct
518
518
| 0 -> true
519
519
| 1 ->
520
520
let blocks = block_deps_of_deps w_out d in
521
+ (* Format.eprintf "Checking block width...@."; *)
521
522
Array. for_all (fun (_ , d ) ->
522
523
if Map. is_empty d then true
523
524
else
524
525
let _, bits = Map. any d in
525
526
Set. is_empty bits ||
526
527
let base = Set. at_rank_exn 0 bits in
528
+ (* Format.eprintf "Base for current block: %d@." base; *)
527
529
Set. for_all (fun bit ->
528
530
let dist = bit - base in
531
+ (* Format.eprintf "Current bit: %d | Current dist: %d | Limit: %d@." bit dist w_in; *)
529
532
0 < = dist && dist < w_in
530
533
) bits
531
534
) blocks
@@ -595,13 +598,14 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
595
598
596
599
let pp_circ (fmt : Format.formatter ) (c : circ ) : unit =
597
600
match c with
598
- | `CArray _ -> Format. eprintf " Circ(Array)"
599
- | `CBitstring _ -> Format. eprintf " Circ(Bitstring)"
600
- | `CTuple _ -> Format. eprintf " Circ(Tuple)"
601
+ | `CArray (r , w ) -> Format. eprintf " Circ(Array[%d@%d])" (Backend. size_of_reg r) w
602
+ | `CBitstring r -> Format. eprintf " Circ(Bitstring[%d])" (Backend. size_of_reg r)
603
+ | `CTuple (_ , ws ) -> Format. eprintf " Circ(Tuple(%a))" (fun fmt szs ->
604
+ Format. fprintf fmt " %d" (List. hd szs); List. iter (Format. fprintf fmt " , %d" ) (List. tl szs)) ws
601
605
| `CBool _ -> Format. eprintf " Circ(Bool)"
602
606
603
607
let pp_circuit (fmt : Format.formatter ) ((c , inps ) : circuit ) : unit =
604
- Format. eprintf " @[<hov 2>%a: @ \n %a@]@ \n "
608
+ Format. eprintf " @[<hov 2>Circuit:@ \n Out type %a@ \n Inputs: %a@]"
605
609
pp_circ c
606
610
(fun fmt inps -> List. iter (fun inp -> Format. fprintf fmt " %a@\n " pp_cinp inp) inps) inps
607
611
@@ -620,6 +624,13 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
620
624
`List cs
621
625
let arg_of_init f =
622
626
`Init f
627
+ let pp_arg fmt arg : unit =
628
+ match arg with
629
+ | `Circuit c -> Format. fprintf fmt " %a" pp_circuit c
630
+ | `Constant i -> Format. fprintf fmt " Constant: %s" (BI. to_string i)
631
+ | `Init f -> Format. fprintf fmt " Init: Type of f(0): %a" pp_circuit (f 0 )
632
+ | `List cs -> Format. fprintf fmt " @[<hov 2> Circuit list: @\n %a@]"
633
+ (fun fmt cs -> List. iter (Format. fprintf fmt " %a@\n " pp_circuit) cs) cs
623
634
end
624
635
open CArgs
625
636
@@ -931,19 +942,25 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
931
942
in op
932
943
in
933
944
match op with
934
- | { kind = `ASliceGet ((w , n ), m ) } ->
945
+ | { kind = `ASliceGet ((n , w ), m ) } ->
935
946
begin match args with
936
947
| [ `Circuit (`CArray (r, w'), cinps) ; `Constant i ] when w = w' ->
937
- (`CBitstring (Backend. slice r (BI. to_int i) m), cinps)
938
- | _ -> assert false
948
+ (`CBitstring (Backend. slice r (BI. to_int i) m), cinps)
949
+ | args ->
950
+ Format. eprintf " Bad arguments for array slice get: w = %d@.%a@." w
951
+ (fun fmt args -> List. iter (Format. fprintf fmt " %a@\n " pp_arg) args) args;
952
+ assert false
953
+ end
954
+ | { kind = `ASliceSet ((n , w ), m ) } ->
955
+ begin match args with
956
+ | [ `Circuit (`CArray (arr, w'), arrinps) ; `Constant i ; `Circuit (`CBitstring bs, bsinps) ] when w = w' ->
957
+ let i = BI. to_int i in
958
+ (`CArray (Backend. insert arr i bs, w), merge_inputs arrinps bsinps)
959
+ | args ->
960
+ Format. eprintf " Bad arguments for array slice set:@.w=%d@.%a@." w
961
+ (fun fmt args -> List. iter (Format. fprintf fmt " %a@\n " pp_arg) args) args;
962
+ assert false
939
963
end
940
- | { kind = `ASliceSet ((w , n ), m ) } ->
941
- begin match args with
942
- | [ `Circuit (`CArray (arr, w'), arrinps) ; `Circuit (`CBitstring bs, bsinps) ; `Constant i ] when w = w' ->
943
- let i = BI. to_int i in
944
- (`CArray (Backend. insert arr i bs, w), merge_inputs arrinps bsinps)
945
- | _ -> assert false
946
- end
947
964
(* FIXME: what do we want for out of bounds extract? Decide later *)
948
965
| { kind = `Extract (w_in , w_out ) } ->
949
966
begin match args with
@@ -1470,7 +1487,7 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
1470
1487
let decompose (in_w : width ) (out_w : width ) ((`CBitstring r , inps ) as c : cbitstring cfun ) : cbitstring cfun list =
1471
1488
if not (is_decomposable in_w out_w c) then
1472
1489
let deps = Backend.Deps. block_deps_of_reg out_w r in
1473
- Format. eprintf " Failed to decompose. Deps:@.%a" (Backend.Deps. pp_block_deps) deps;
1490
+ Format. eprintf " Failed to decompose. in_w=%d out_w=%d Deps:@.%a" in_w out_w (Backend.Deps. pp_block_deps) deps;
1474
1491
assert false
1475
1492
else
1476
1493
let n = (Backend. size_of_reg r) / out_w in
0 commit comments