Skip to content

Commit 98c0c49

Browse files
yavZippeyKeys12
authored andcommitted
Instrument after pre-processor
1 parent 8cc65c1 commit 98c0c49

40 files changed

+494
-525
lines changed

.github/workflows/proof.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
# version: [4.12.0, 4.14.1]
2323
version: [4.14.1]
2424

25-
runs-on: ubuntu-22.04
25+
runs-on: ubuntu-latest
2626

2727
steps:
2828

@@ -46,7 +46,7 @@ jobs:
4646
opam init --yes --no-setup --shell=sh --compiler=${{ matrix.version }}
4747
eval $(opam env --switch=${{ matrix.version }})
4848
opam repo add --yes --this-switch coq-released https://coq.inria.fr/opam/released
49-
opam install --deps-only --yes ./cn.opam
49+
opam install --deps-only --yes ./cn.opam z3
5050
5151
- name: Save OPAM cache
5252
uses: actions/cache/save@v4

.github/workflows/spec-testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
opam init --yes --no-setup --shell=sh --compiler=${{ matrix.version }}
4747
eval $(opam env --switch=${{ matrix.version }})
4848
opam repo add --yes --this-switch coq-released https://coq.inria.fr/opam/released
49-
opam install --deps-only --yes ./cn.opam
49+
opam install --deps-only --yes ./cn.opam z3
5050
5151
- name: Save OPAM cache
5252
uses: actions/cache/save@v4

bin/instrument.ml

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ module CF = Cerb_frontend
22
module CB = Cerb_backend
33
open Cn
44

5-
let pick_cpp_file_name outdir filename =
6-
let cpp_name = Filename.remove_extension filename ^ "-preproc.c" in
7-
match outdir with None -> cpp_name | Some d -> Filename.concat d cpp_name
8-
9-
105
let run_instrumented_file ~filename ~output ~output_dir ~print_steps =
116
let instrumented_filename =
127
Option.value ~default:(Fulminate.get_instrumented_filename filename) output
138
in
14-
let cn_helper_filename = Fulminate.get_cn_helper_filename filename in
159
let output_dir = Option.value ~default:"." output_dir in
1610
let in_folder ?ext fn =
1711
Filename.concat
@@ -25,21 +19,6 @@ let run_instrumented_file ~filename ~output ~output_dir ~print_steps =
2519
print_endline
2620
("Could not find CN's runtime directory (looked at: '" ^ runtime_prefix ^ "')");
2721
exit 1);
28-
if
29-
Sys.command
30-
("cc -c "
31-
^ includes
32-
^ " -o "
33-
^ in_folder ~ext:".o" cn_helper_filename
34-
^ " "
35-
^ in_folder cn_helper_filename)
36-
== 0
37-
then (
38-
if print_steps then
39-
print_endline ("Compiled '" ^ cn_helper_filename ^ "'"))
40-
else (
41-
print_endline ("Failed to compile '" ^ cn_helper_filename ^ "'");
42-
exit 1);
4322
if
4423
Sys.command
4524
("cc -c "
@@ -64,8 +43,6 @@ let run_instrumented_file ~filename ~output ~output_dir ~print_steps =
6443
^ " "
6544
^ in_folder ~ext:".o" instrumented_filename
6645
^ " "
67-
^ in_folder ~ext:".o" cn_helper_filename
68-
^ " "
6946
^ Filename.concat runtime_prefix "libcn_exec.a")
7047
== 0
7148
then (
@@ -105,7 +82,6 @@ let generate_executable_specs
10582
without_loop_invariants
10683
with_loop_leak_checks
10784
with_test_gen
108-
copy_source_dir
10985
run
11086
print_steps
11187
=
@@ -126,16 +102,10 @@ let generate_executable_specs
126102
Pp.error e.loc report.short (Option.to_list report.descr);
127103
match e.msg with TypeErrors.Unsupported _ -> exit 2 | _ -> exit 1
128104
in
129-
(* XXX temporary: should we inject in the pre-processed file or original one *)
130105
let filename = Common.there_can_only_be_one filename in
131-
let use_preproc = false in
132-
let exec_spec_file, save =
133-
if use_preproc then (
134-
let pp_file = pick_cpp_file_name output_dir filename in
135-
(pp_file, Some pp_file))
136-
else
137-
(filename, None)
138-
in
106+
let basefile = Filename.basename filename in
107+
let pp_file = Filename.temp_file "cn_" basefile in
108+
let out_file = Fulminate.get_output_filename output_dir output basefile in
139109
Common.with_well_formedness_check (* CLI arguments *)
140110
~filename
141111
~macros
@@ -150,7 +120,7 @@ let generate_executable_specs
150120
~astprints
151121
~no_inherit_loc
152122
~magic_comment_char_dollar (* Callbacks *)
153-
~save_cpp:save
123+
~save_cpp:(Some pp_file)
154124
~handle_error
155125
~f:(fun ~cabs_tunit:_ ~prog5 ~ail_prog ~statement_locs:_ ~paused:_ ->
156126
Cerb_colour.without_colour
@@ -161,12 +131,9 @@ let generate_executable_specs
161131
~without_loop_invariants
162132
~with_loop_leak_checks
163133
~with_test_gen
164-
~copy_source_dir
165-
exec_spec_file
166-
~use_preproc
134+
pp_file
135+
out_file
167136
ail_prog
168-
output
169-
output_dir
170137
prog5
171138
with
172139
| e -> Common.handle_error_with_user_guidance ~label:"CN-Exec" e);
@@ -224,11 +191,6 @@ module Flags = struct
224191
Arg.(value & flag & info [ "with-test-gen" ] ~doc)
225192

226193

227-
let copy_source_dir =
228-
let doc = "Copy non-CN annotated files into output_dir for CN runtime testing" in
229-
Arg.(value & flag & info [ "copy-source-dir" ] ~doc)
230-
231-
232194
let run =
233195
let doc = "Run the instrumented program" in
234196
Arg.(value & flag & info [ "run" ] ~doc)
@@ -281,7 +243,6 @@ let cmd =
281243
$ Flags.without_loop_invariants
282244
$ Flags.with_loop_leak_checks
283245
$ Flags.with_test_gen
284-
$ Flags.copy_source_dir
285246
$ Flags.run
286247
$ Flags.print_steps
287248
in

bin/seqTest.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ let run_seq_tests
3636
match e.msg with TypeErrors.Unsupported _ -> exit 2 | _ -> exit 1
3737
in
3838
let filename = Common.there_can_only_be_one filename in
39+
let basefile = Filename.basename filename in
40+
let pp_file = Filename.temp_file "cn_" basefile in
41+
let output_dir =
42+
let dir, mk = output_dir in
43+
mk dir
44+
in
45+
let out_file = Fulminate.get_output_filename (Some output_dir) None basefile in
3946
Common.with_well_formedness_check (* CLI arguments *)
4047
~filename
4148
~macros
@@ -50,7 +57,7 @@ let run_seq_tests
5057
~astprints
5158
~no_inherit_loc
5259
~magic_comment_char_dollar (* Callbacks *)
53-
~save_cpp:None (* XXX *)
60+
~save_cpp:(Some pp_file)
5461
~handle_error
5562
~f:(fun ~cabs_tunit ~prog5 ~ail_prog ~statement_locs:_ ~paused:_ ->
5663
Cerb_colour.without_colour
@@ -67,22 +74,15 @@ let run_seq_tests
6774
print_endline "No testable functions, trivially passing";
6875
exit 0);
6976
let _, sigma = ail_prog in
70-
let output_dir =
71-
let dir, mk = output_dir in
72-
mk dir
73-
in
7477
Fulminate.Cn_to_ail.augment_record_map (BaseTypes.Record []);
7578
Fulminate.main
7679
~without_ownership_checking
7780
~without_loop_invariants:true
7881
~with_loop_leak_checks:false
7982
~with_test_gen:true
80-
~copy_source_dir:false
81-
filename
82-
~use_preproc:false
83+
pp_file
84+
out_file
8385
ail_prog
84-
None
85-
(Some output_dir)
8686
prog5;
8787
let config : SeqTests.seq_config =
8888
{ print_steps;

bin/test.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ let run_tests
6565
match e.msg with TypeErrors.Unsupported _ -> exit 2 | _ -> exit 1
6666
in
6767
let filename = Common.there_can_only_be_one filename in
68+
let basefile = Filename.basename filename in
69+
let output_dir =
70+
let dir, mk = output_dir in
71+
mk dir
72+
in
73+
let pp_file = Filename.temp_file "cn_" basefile in
74+
let out_file = Fulminate.get_output_filename (Some output_dir) None basefile in
6875
Common.with_well_formedness_check (* CLI arguments *)
6976
~filename
7077
~macros
@@ -79,7 +86,7 @@ let run_tests
7986
~astprints
8087
~no_inherit_loc
8188
~magic_comment_char_dollar (* Callbacks *)
82-
~save_cpp:None (* XXX *)
89+
~save_cpp:(Some pp_file)
8390
~handle_error
8491
~f:(fun ~cabs_tunit ~prog5 ~ail_prog ~statement_locs:_ ~paused:_ ->
8592
let config : TestGeneration.config =
@@ -125,23 +132,16 @@ let run_tests
125132
exit 0);
126133
Cerb_colour.without_colour
127134
(fun () ->
128-
let output_dir =
129-
let dir, mk = output_dir in
130-
mk dir
131-
in
132135
Fulminate.Cn_to_ail.augment_record_map (BaseTypes.Record []);
133136
(try
134137
Fulminate.main
135138
~without_ownership_checking
136139
~without_loop_invariants:true
137140
~with_loop_leak_checks:false
138141
~with_test_gen:true
139-
~copy_source_dir:false
140-
filename
141-
~use_preproc:false (* XXX *)
142+
pp_file
143+
out_file
142144
ail_prog
143-
None
144-
(Some output_dir)
145145
prog5
146146
with
147147
| e -> Common.handle_error_with_user_guidance ~label:"CN-Exec" e);

lib/fulminate/cn_to_ail.ml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ let create_id_from_sym ?(lowercase = false) sym =
100100

101101
let create_sym_from_id id = Sym.fresh (Id.get_string id)
102102

103+
let ail_null = A.(AilEconst (ConstantInteger (IConstant (Z.zero, Decimal, None))))
104+
103105
let generate_error_msg_info_update_stats ?(cn_source_loc_opt = None) () =
104106
let cn_source_loc_arg =
105107
match cn_source_loc_opt with
@@ -120,7 +122,7 @@ let generate_error_msg_info_update_stats ?(cn_source_loc_opt = None) () =
120122
(None, [ (Cerb_location.unknown, [ loc_str_2_escaped ^ loc_str_escaped ]) ]))
121123
in
122124
cn_source_loc_str
123-
| None -> mk_expr A.(AilEconst ConstantNull)
125+
| None -> mk_expr ail_null
124126
in
125127
let update_fn_sym = Sym.fresh "update_cn_error_message_info" in
126128
[ A.(
@@ -542,11 +544,7 @@ let cn_to_ail_const const basetype =
542544
| MemByte { alloc_id = _; value = i } ->
543545
wrap (A.AilEconst (ConstantInteger (IConstant (i, Decimal, None))))
544546
| Bits ((sgn, sz), i) ->
545-
let z_min, z_max = BT.bits_range (sgn, sz) in
546-
let ity =
547-
let ibt = CF.IntegerType.IntN_t sz in
548-
match sgn with Signed -> C.Signed ibt | Unsigned -> C.Unsigned ibt
549-
in
547+
let z_min, _ = BT.bits_range (sgn, sz) in
550548
let suffix =
551549
let size_of = Memory.size_of_integer_type in
552550
match sgn with
@@ -566,14 +564,17 @@ let cn_to_ail_const const basetype =
566564
Some A.LL
567565
in
568566
let ail_const =
569-
if Z.equal i z_max then
570-
A.ConstantInteger (IConstantMax ity)
571-
else if Z.equal i z_min && BT.equal_sign sgn BT.Signed then
572-
A.ConstantInteger (IConstantMin ity)
567+
let k a = A.(AilEconst (ConstantInteger (IConstant (a, Decimal, suffix)))) in
568+
if Z.equal i z_min && BT.equal_sign sgn BT.Signed then
569+
A.(
570+
AilEbinary
571+
( mk_expr (k (Z.neg (Z.sub (Z.neg i) Z.one))),
572+
Arithmetic Sub,
573+
mk_expr (k Z.one) ))
573574
else
574-
ConstantInteger (IConstant (i, Decimal, suffix))
575+
k i
575576
in
576-
wrap (A.AilEconst ail_const)
577+
wrap ail_const
577578
| Q q -> wrap (A.AilEconst (ConstantFloating (Q.to_string q, None)))
578579
| Pointer z ->
579580
let ail_const' =
@@ -584,9 +585,8 @@ let cn_to_ail_const const basetype =
584585
| Bool b ->
585586
wrap
586587
(A.AilEconst (ConstantPredefined (if b then PConstantTrue else PConstantFalse)))
587-
| Unit ->
588-
wrap (A.AilEconst ConstantNull) (* Gets overridden by dest_with_unit_check *)
589-
| Null -> wrap (A.AilEconst ConstantNull)
588+
| Unit -> wrap ail_null (* Gets overridden by dest_with_unit_check *)
589+
| Null -> wrap ail_null
590590
| CType_const _ -> failwith (__LOC__ ^ ": TODO CType_const")
591591
| Default bt -> cn_to_ail_default bt
592592
in
@@ -705,10 +705,10 @@ let generate_get_or_put_ownership_function ~without_ownership_checking ctype
705705
if without_ownership_checking then
706706
([], [])
707707
else (
708-
let uintptr_t_type = C.uintptr_t in
709-
let generic_c_ptr_binding = create_binding generic_c_ptr_sym uintptr_t_type in
708+
let void_ptr = C.mk_ctype_pointer C.no_qualifiers C.void in
709+
let generic_c_ptr_binding = create_binding generic_c_ptr_sym void_ptr in
710710
let uintptr_t_cast_expr =
711-
mk_expr A.(AilEcast (C.no_qualifiers, uintptr_t_type, cast_expr))
711+
mk_expr A.(AilEcast (C.no_qualifiers, void_ptr, cast_expr))
712712
in
713713
let generic_c_ptr_assign_stat_ =
714714
A.(AilSdeclaration [ (generic_c_ptr_sym, Some uintptr_t_cast_expr) ])
@@ -2634,7 +2634,6 @@ let cn_to_ail_resource
26342634
let matching_preds =
26352635
List.filter (fun (pred_sym', _def) -> Sym.equal pname pred_sym') preds
26362636
in
2637-
Printf.printf "Pred sym: %s\n" (Sym.pp_string pname);
26382637
let pred_sym', pred_def' =
26392638
match matching_preds with
26402639
| [] ->

0 commit comments

Comments
 (0)