Skip to content

Commit f12f9af

Browse files
committed
CHC: add diagnostics log
1 parent 83bc815 commit f12f9af

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

CodeHawk/CHC/cchanalyze/cCHAssignmentTranslator.ml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2019 Kestrel Technology LLC
88
Copyright (c) 2020-2023 Henny B. Sipma
9-
Copyright (c) 2024 Aarno Labs LLC
9+
Copyright (c) 2024-2025 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -56,6 +56,8 @@ open CCHUtilities
5656
open CCHAnalysisTypes
5757
open CCHCommand
5858

59+
let p2s = CHPrettyUtil.pretty_to_string
60+
5961

6062
class num_assignment_translator_t
6163
(env:c_environment_int)
@@ -235,12 +237,17 @@ end
235237
class sym_pointersets_assignment_translator_t
236238
(env:c_environment_int)
237239
(exp_translator:exp_translator_int):assignment_translator_int =
238-
object
240+
object (self)
239241

240242
val fdecls = env#get_fdecls
241243

244+
method private dmsg (ctxt: program_context_int) (loc: location): string =
245+
env#get_functionname ^ ":"
246+
^ (ctxt#to_string)
247+
^ " (line: " ^ (string_of_int loc.line) ^ ")"
248+
242249
method translate
243-
(context:program_context_int) (_loc:location) (lhs:lval) (rhs:exp) =
250+
(context:program_context_int) (loc:location) (lhs:lval) (rhs:exp) =
244251
try
245252
let chifVar = exp_translator#translate_lhs context lhs in
246253
let rhsExpr = exp_translator#translate_exp context rhs in
@@ -262,6 +269,14 @@ object
262269
| _ -> make_c_cmd (ASSIGN_SYM (chifVar, SYM (new symbol_t "unknown")))
263270
else
264271
make_c_cmd SKIP in
272+
let _ =
273+
log_diagnostics_result
274+
~msg:(self#dmsg context loc)
275+
~tag:"sym_pointersets:translate assignment"
276+
__FILE__ __LINE__
277+
["lhs: " ^ (p2s (lval_to_pretty lhs));
278+
"rhs: " ^ (p2s (exp_to_pretty rhs));
279+
"result: " ^ (p2s (c_cmd_to_pretty assign))] in
265280
[assign]
266281
with
267282
| CCHFailure p ->

CodeHawk/CHC/cchanalyze/cCHExpTranslator.ml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2019 Kestrel Technology LLC
88
Copyright (c) 2020-2023 Henny B. Sipma
9-
Copyright (c) 2024 Aarno Labs LLC
9+
Copyright (c) 2024-2025 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -33,6 +33,9 @@ open CHLanguage
3333
open CHNumerical
3434
open CHPretty
3535

36+
(* chutil *)
37+
open CHLogger
38+
3639
(* xprlib *)
3740
open Xprt
3841
open XprTypes
@@ -58,7 +61,10 @@ open CCHCommand
5861

5962
module B = Big_int_Z
6063

61-
let pr2s = CHPrettyUtil.pretty_to_string
64+
let p2s = CHPrettyUtil.pretty_to_string
65+
let x2p = XprToPretty.xpr_formatter#pr_expr
66+
let x2s x = p2s (x2p x)
67+
6268
let fenv = CCHFileEnvironment.file_environment
6369

6470

@@ -318,6 +324,9 @@ object (self)
318324
val memregmgr = env#get_variable_manager#memregmgr
319325
val fdecls = env#get_fdecls
320326

327+
method private dmsg (ctxt: program_context_int): string =
328+
env#get_functionname ^ ":" ^ ctxt#to_string
329+
321330
(* --------------------------- lhs translation ---------------------------- *)
322331

323332
method translate_lhs (ctxt:program_context_int) (lval:lval):variable_t =
@@ -523,8 +532,17 @@ object (self)
523532

524533
(* --------------------------- rhs translation ---------------------------- *)
525534

526-
method translate_exp (ctxt:program_context_int) (e:exp) =
527-
begin context <- ctxt; self#translate_rhs_expr e end
535+
method translate_exp (ctxt:program_context_int) (e:exp): xpr_t =
536+
let _ = context <- ctxt in
537+
let result = self#translate_rhs_expr e in
538+
let _ =
539+
log_diagnostics_result
540+
~msg:(self#dmsg ctxt)
541+
~tag:"sym_pointersets:translate_exp"
542+
__FILE__ __LINE__
543+
["exp: " ^ (p2s (exp_to_pretty e));
544+
"result: " ^ (x2s result)] in
545+
result
528546

529547
method private translate_rhs_const_expr (c:constant) =
530548
match c with
@@ -535,7 +553,7 @@ object (self)
535553
let null_sym = memregmgr#mk_null_sym (-1) in
536554
let null_constant_expr = XConst (SymSet [null_sym]) in
537555
let default () =
538-
let s = memregmgr#mk_uninterpreted_sym (pr2s (exp_to_pretty x)) in
556+
let s = memregmgr#mk_uninterpreted_sym (p2s (exp_to_pretty x)) in
539557
sym_constant_expr s in
540558
let xpr =
541559
try

CodeHawk/CHC/cchcmdline/cCHXCAnalyzer.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ let speclist = [
125125
"base filename of c source code file without extension");
126126
("-cfilepath", Arg.String system_settings#set_cfilepath,
127127
"path relative to project path");
128+
("-diagnostics", Arg.Unit (fun () -> activate_diagnostics ()),
129+
"collect diagnostics messages and save in diagnostics log");
128130
("-verbose", Arg.Unit (fun () -> system_settings#set_verbose true),
129131
"print status on proof obligations and invariants");
130132
("-projectname", Arg.String system_settings#set_projectname,
@@ -149,7 +151,9 @@ let save_log_files (contenttype:string) =
149151
begin
150152
save_logfile ch_info_log contenttype "infolog";
151153
append_to_logfile ch_error_log contenttype "errorlog";
152-
save_logfile chlog contenttype "chlog"
154+
save_logfile chlog contenttype "chlog";
155+
(if collect_diagnostics () then
156+
save_logfile ch_diagnostics_log contenttype "ch_diagnostics_log")
153157
end
154158

155159

0 commit comments

Comments
 (0)