@@ -10,7 +10,7 @@ open Bap_primus.Std
1010module KB = Knowledge
1111open KB.Let
1212
13- let provide_bir (tgt : Theory.target ) (patch : Data.Patch.t ) : unit KB.t =
13+ let provide_sem (tgt : Theory.target ) (patch : Data.Patch.t ) : unit KB.t =
1414 Theory. instance () >> =
1515 Theory. require >> = fun (module Core) ->
1616 let module CParser = Core_c. Eval (Core ) in
@@ -19,30 +19,32 @@ let provide_bir (tgt : Theory.target) (patch : Data.Patch.t) : unit KB.t =
1919 Events. (send @@ Info (Printf. sprintf " Patch %s" name));
2020 Data.Patch. get_patch_code_exn patch >> = fun code ->
2121 (* Get the patch (as BIR). *)
22- let * bir = match code with
23- | CCode code -> begin
22+ let * sem = match code with
23+ | CCode code ->
24+ begin
2425 let code_str = Utils. print_c Cprint. print_def code in
2526 Events. (send @@ Info (Printf. sprintf " %s" code_str));
2627 CParser. c_patch_to_eff tgt code
27- end
28- | PrimusCode name -> begin
29- Primus.Lisp.Unit. create tgt >> = fun unit ->
30- KB.Object. scoped Theory.Program. cls @@ fun obj ->
31- KB. sequence [
32- KB. provide Theory.Label. unit obj (Some unit );
33- (* KB.provide Theory.Label.addr obj addr; *)
34- KB. provide Primus.Lisp.Semantics. name obj (Some (KB.Name. create name));
35- ] >> = fun () ->
36- KB. collect Theory.Semantics. slot obj
37- end
38- | ASMCode _asm -> Kb_error. fail (Kb_error. Not_implemented " yolo" )
28+ end
29+ | PrimusCode name ->
30+ begin
31+ Primus.Lisp.Unit. create tgt >> = fun unit ->
32+ KB.Object. scoped Theory.Program. cls @@ fun obj ->
33+ KB. sequence [
34+ KB. provide Theory.Label. unit obj (Some unit );
35+ KB. provide Primus.Lisp.Semantics. name obj (Some (KB.Name. create name));
36+ ] >> = fun () ->
37+ KB. collect Theory.Semantics. slot obj
38+ end
39+ | ASMCode _asm -> Kb_error. fail (Kb_error. Not_implemented
40+ " [Patch_ingester.provide_sem] called on assembly patch" )
3941 in
4042 Events. (send @@ Info " The patch has the following BIL:" );
4143 Events. (send @@ Rule );
42- let bir_str = Format. asprintf " %a" Bil. pp (KB.Value. get Bil. slot bir ) in
44+ let bir_str = Format. asprintf " %a" Bil. pp (KB.Value. get Bil. slot sem ) in
4345 Events. (send @@ Info bir_str);
4446 Events. (send @@ Rule );
45- Data.Patch. set_bir patch bir
47+ Data.Patch. set_sem patch sem
4648
4749(* Ingests a single patch, populating the relevant fields of the KB,
4850 most notably the semantics field of the corresponding patch (and
@@ -51,10 +53,10 @@ let ingest_one (tgt : Theory.target) (patch_num : int KB.t) (patch : Data.Patch.
5153 : int KB.t =
5254 patch_num >> = fun patch_num ->
5355 Events. (send @@ Info (Printf. sprintf " \n Ingesting patch %d." patch_num));
54- (Data.Patch. get_assembly patch >> = fun asm ->
55- match asm with
56- | Some _asm -> KB. return () (* Assembly is user provided *)
57- | None -> provide_bir tgt patch) >> = fun () ->
56+ (Data.Patch. get_patch_code_exn patch >> = fun code ->
57+ match code with
58+ | ASMCode _asm -> KB. return () (* Assembly is user provided *)
59+ | PrimusCode _ | CCode _ -> provide_sem tgt patch) >> = fun () ->
5860 KB. return @@ patch_num+ 1
5961
6062(* Processes the whole patch associated with [obj], populating all the
0 commit comments