Skip to content

Commit d2fb398

Browse files
committed
CHC: add analysis-info to saved ppo file
1 parent 6f6104d commit d2fb398

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

CodeHawk/CHC/cchpre/cCHProofScaffolding.ml

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ open CHNumerical
3232
open CHPretty
3333

3434
(* chutil *)
35+
open CHLogger
3536
open CHXmlDocument
3637

3738
(* cchlib *)
3839
open CCHBasicTypes
3940
open CCHFileContract
4041
open CCHLibTypes
42+
open CCHTypesToPretty
43+
open CCHTypesUtil
4144
open CCHUtilities
4245

4346
(* cchpre *)
@@ -51,24 +54,37 @@ module H = Hashtbl
5154

5255

5356
let id = CCHInterfaceDictionary.interface_dictionary
57+
let cd = CCHDictionary.cdictionary
58+
let fenv = CCHFileEnvironment.file_environment
5459

5560

5661
class proof_scaffolding_t:proof_scaffolding_int =
5762
object (self)
5863

64+
val analysis_info = H.create 3 (* fname -> analysis_info_t *)
5965
val apis = H.create 3 (* fname -> api_assumption_int *)
6066
val ppos = H.create 3 (* fname -> ppo_manager_int *)
6167
val spos = H.create 3 (* fname -> spo_manager_int *)
6268
val pods = H.create 3 (* fname -> podictionary_int *)
6369

6470
method reset =
6571
begin
72+
H.clear analysis_info;
6673
H.clear apis;
6774
H.clear ppos;
6875
H.clear spos;
6976
H.clear pods;
7077
end
7178

79+
method set_analysis_info (fname: string) (info: analysis_info_t) =
80+
H.replace analysis_info fname info
81+
82+
method get_analysis_info (fname: string): analysis_info_t =
83+
if H.mem analysis_info fname then
84+
H.find analysis_info fname
85+
else
86+
UndefinedBehaviorInfo
87+
7288
method get_function_api (fname:string):function_api_int =
7389
if H.mem apis fname then
7490
H.find apis fname
@@ -217,15 +233,80 @@ object (self)
217233
method read_xml_api (node:xml_element_int) (fname:string) =
218234
(self#get_function_api fname)#read_xml (node#getTaggedChild "api")
219235

236+
method private write_xml_analysis_info (node: xml_element_int) (fname: string) =
237+
let info =
238+
if H.mem analysis_info fname then
239+
H.find analysis_info fname
240+
else
241+
UndefinedBehaviorInfo in
242+
match info with
243+
| UndefinedBehaviorInfo ->
244+
node#setAttribute "name" "undefined-behavior"
245+
| OutputParameterInfo vinfos ->
246+
let ppnode = xmlElement "candidate-parameters" in
247+
begin
248+
node#setAttribute "name" "output-parameters";
249+
List.iter (fun vinfo ->
250+
let offsets =
251+
match fenv#get_type_unrolled vinfo.vtype with
252+
| TPtr (tt, _) when is_integral_type tt ->
253+
string_of_int( cd#index_offset NoOffset)
254+
| TPtr (tt,_) when is_scalar_struct_type tt ->
255+
let offsets = get_scalar_struct_offsets tt in
256+
String.concat
257+
","
258+
(List.map (fun o -> string_of_int (cd#index_offset o)) offsets)
259+
| ty ->
260+
begin
261+
ch_error_log#add
262+
"output parameter type not recognized"
263+
(LBLOCK [STR "type: "; typ_to_pretty ty]);
264+
""
265+
end in
266+
let pnode = xmlElement "vinfo" in
267+
begin
268+
pnode#setAttribute "vname" vinfo.vname;
269+
pnode#setIntAttribute
270+
"xid" (CCHDeclarations.cdeclarations#index_varinfo vinfo);
271+
pnode#setAttribute "offsets" offsets;
272+
ppnode#appendChildren [pnode]
273+
end) vinfos;
274+
node#appendChildren [ppnode]
275+
end
276+
277+
220278
method write_xml_ppos (node:xml_element_int) (fname:string) =
279+
let inode = xmlElement "analysis-info" in
221280
let pnode = xmlElement "ppos" in
222281
begin
282+
(self#write_xml_analysis_info inode fname);
223283
(self#get_ppo_manager fname)#write_xml pnode;
224-
node#appendChildren [ pnode ]
284+
node#appendChildren [inode; pnode]
225285
end
226286

287+
method private read_xml_analysis_info (node: xml_element_int) (fname: string) =
288+
let name = node#getAttribute "name" in
289+
let info =
290+
match name with
291+
| "undefined-behavior" -> UndefinedBehaviorInfo
292+
| "output-parameters" ->
293+
let ppnode = node#getTaggedChild "candidate-parameters" in
294+
let vinfos =
295+
List.map (fun pnode ->
296+
let xid = pnode#getIntAttribute "xid" in
297+
CCHDeclarations.cdeclarations#get_varinfo xid)
298+
(ppnode#getTaggedChildren "vinfo") in
299+
OutputParameterInfo vinfos
300+
| _ ->
301+
raise (CCHFailure (LBLOCK [STR "name not recognized: "; STR name])) in
302+
H.replace analysis_info fname info
303+
227304
method read_xml_ppos (node:xml_element_int) (fname:string) =
228-
(self#get_ppo_manager fname)#read_xml (node#getTaggedChild "ppos")
305+
begin
306+
(if node#hasOneTaggedChild "analysis-info" then
307+
self#read_xml_analysis_info (node#getTaggedChild "analysis-info") fname);
308+
(self#get_ppo_manager fname)#read_xml (node#getTaggedChild "ppos")
309+
end
229310

230311
method write_xml_spos (node:xml_element_int) (fname:string) =
231312
let snode = xmlElement "spos" in

0 commit comments

Comments
 (0)