|
25 | 25 | SOFTWARE. |
26 | 26 | ============================================================================= *) |
27 | 27 |
|
28 | | -open BCHBCTypes |
| 28 | +(* chlib *) |
| 29 | +open CHPretty |
| 30 | + |
| 31 | +(* chutil *) |
| 32 | +open CHLogger |
29 | 33 |
|
| 34 | +(* bchlib *) |
| 35 | +open BCHBasicTypes |
| 36 | +open BCHBCTypes |
| 37 | +open BCHBCTypePretty |
| 38 | +open BCHBCTypeUtil |
| 39 | +open BCHFtsParameter |
| 40 | +open BCHFunctionInterface |
| 41 | +open BCHLibTypes |
30 | 42 |
|
31 | | -let gcc_attributes_to_precondition_attributes |
32 | | - (attrs: b_attributes_t): precondition_attribute_t list = |
33 | | - List.fold_left (fun acc a -> |
34 | | - match a with |
35 | | - | Attr ("access", params) -> |
36 | | - (match params with |
37 | | - | [ACons ("read_only", []); AInt refindex] -> |
38 | | - (APCReadOnly (refindex, None)) :: acc |
39 | | - | [ACons ("read_only", []); AInt refindex; AInt sizeindex] -> |
40 | | - (APCReadOnly (refindex, Some sizeindex)) :: acc |
41 | | - | [ACons ("write_only", []); AInt refindex] -> |
42 | | - (APCWriteOnly (refindex, None)) :: acc |
43 | | - | [ACons ("write_only", []); AInt refindex; AInt sizeindex] -> |
44 | | - (APCWriteOnly (refindex, Some sizeindex)) :: acc |
45 | | - | [ACons ("read_write", []); AInt refindex] -> |
46 | | - (APCReadWrite (refindex, None)) :: acc |
47 | | - | [ACons ("read_write", []); AInt refindex; AInt sizeindex] -> |
48 | | - (APCReadWrite (refindex, Some sizeindex)) :: acc |
49 | | - | _ -> acc) |
50 | | - | _ -> acc) [] attrs |
51 | 43 |
|
| 44 | +let convert_b_attributes_to_function_conditions |
| 45 | + (name: string) |
| 46 | + (fintf: function_interface_t) |
| 47 | + (attrs: b_attributes_t): |
| 48 | + (xxpredicate_t list * xxpredicate_t list * xxpredicate_t list) = |
| 49 | + let parameters = get_fts_parameters fintf in |
| 50 | + let get_par (n: int) = |
| 51 | + try |
| 52 | + List.find (fun p -> |
| 53 | + match p.apar_index with Some ix -> ix = n | _ -> false) parameters |
| 54 | + with |
| 55 | + | Not_found -> |
| 56 | + raise |
| 57 | + (BCH_failure |
| 58 | + (LBLOCK [ |
| 59 | + STR "No parameter with index "; |
| 60 | + INT n; |
| 61 | + pretty_print_list (List.map (fun p -> p.apar_name) parameters) |
| 62 | + (fun s -> STR s) "[" "," "]"])) in |
| 63 | + let get_derefty (par: fts_parameter_t): btype_t = |
| 64 | + if is_pointer par.apar_type then |
| 65 | + ptr_deref par.apar_type |
| 66 | + else |
| 67 | + raise |
| 68 | + (BCH_failure |
| 69 | + (LBLOCK [ |
| 70 | + STR "parameter is not a pointer type: "; |
| 71 | + fts_parameter_to_pretty par])) in |
| 72 | + List.fold_left (fun ((xpre, xside, xpost) as acc) attr -> |
| 73 | + match attr with |
| 74 | + | Attr (("access" | "chk_access"), params) -> |
| 75 | + let (pre, side) = |
| 76 | + (match params with |
| 77 | + | [ACons ("read_only", []); AInt refindex] -> |
| 78 | + let par = get_par refindex in |
| 79 | + let ty = get_derefty par in |
| 80 | + ([XXBuffer (ty, ArgValue par, RunTimeValue)], []) |
52 | 81 |
|
53 | | -let gcc_attributes_to_srcmapinfo |
54 | | - (attrs: b_attributes_t): srcmapinfo_t option = |
55 | | - let optsrcloc = |
56 | | - List.fold_left (fun acc a -> |
57 | | - match acc with |
58 | | - | Some _ -> acc |
59 | | - | _ -> |
60 | | - match a with |
61 | | - | Attr ("chkc_srcloc", params) -> |
62 | | - (match params with |
63 | | - | [AStr filename; AInt linenumber] -> |
64 | | - Some {srcloc_filename=filename; |
65 | | - srcloc_linenumber=linenumber; |
66 | | - srcloc_notes=[]} |
67 | | - | _ -> None) |
68 | | - | _ -> None) None attrs in |
69 | | - match optsrcloc with |
70 | | - | Some srcloc -> |
71 | | - let binloc = |
72 | | - List.fold_left (fun acc a -> |
73 | | - match acc with |
74 | | - | Some _ -> acc |
75 | | - | _ -> |
76 | | - match a with |
77 | | - | Attr ("chkx_binloc", params) -> |
78 | | - (match params with |
79 | | - | [AStr address] -> Some address |
80 | | - | _ -> None) |
81 | | - | _ -> None) None attrs in |
82 | | - Some {srcmap_srcloc = srcloc; srcmap_binloc = binloc} |
83 | | - | _ -> None |
| 82 | + | [ACons ("read_only", []); AInt refindex; AInt sizeindex] -> |
| 83 | + let rpar = get_par refindex in |
| 84 | + let spar = get_par sizeindex in |
| 85 | + let ty = get_derefty rpar in |
| 86 | + ([XXBuffer (ty, ArgValue rpar, ArgValue spar)], []) |
84 | 87 |
|
| 88 | + | [ACons (("write_only" | "read_write"), []); AInt refindex] -> |
| 89 | + let par = get_par refindex in |
| 90 | + let ty = get_derefty par in |
| 91 | + ([XXBuffer (ty, ArgValue par, RunTimeValue)], |
| 92 | + [XXBlockWrite (ty, ArgValue par, RunTimeValue)]) |
85 | 93 |
|
| 94 | + | [ACons (("write_only" | "read_write"), []); |
| 95 | + AInt refindex; AInt sizeindex] -> |
| 96 | + let rpar = get_par refindex in |
| 97 | + let spar = get_par sizeindex in |
| 98 | + let ty = get_derefty rpar in |
| 99 | + ([XXBuffer (ty, ArgValue rpar, ArgValue spar)], |
| 100 | + [XXBlockWrite (ty, ArgValue rpar, ArgValue spar)]) |
86 | 101 |
|
87 | | -let precondition_attributes_t_to_gcc_attributes |
88 | | - (preattrs: precondition_attribute_t list): b_attributes_t = |
89 | | - let get_params (refindex: int) (optsizeindex: int option) = |
90 | | - match optsizeindex with |
91 | | - | Some sizeindex -> [AInt refindex; AInt sizeindex] |
92 | | - | _ -> [AInt refindex] in |
93 | | - let get_access (mode: string) (params: b_attrparam_t list) = |
94 | | - Attr ("access", [ACons (mode, [])] @ params) in |
95 | | - List.fold_left (fun acc p -> |
96 | | - match p with |
97 | | - | APCReadOnly (refindex, optsizeindex) -> |
98 | | - (get_access "read_only" (get_params refindex optsizeindex)) :: acc |
99 | | - | APCWriteOnly (refindex, optsizeindex) -> |
100 | | - (get_access "write_only" (get_params refindex optsizeindex)) :: acc |
101 | | - | APCReadWrite (refindex, optsizeindex) -> |
102 | | - (get_access "read_write" (get_params refindex optsizeindex)) :: acc |
103 | | - | _ -> acc) [] preattrs |
| 102 | + | _ -> |
| 103 | + begin |
| 104 | + log_error_result |
| 105 | + ~msg:("attribute conversion for " ^ name ^ ": " |
| 106 | + ^ "attribute parameters " |
| 107 | + ^ (String.concat |
| 108 | + ", " (List.map b_attrparam_to_string params))) |
| 109 | + ~tag:"attribute conversion" |
| 110 | + __FILE__ __LINE__ []; |
| 111 | + ([], []) |
| 112 | + end) in |
| 113 | + (pre @ xpre, side @ xside, xpost) |
| 114 | + | _ -> |
| 115 | + acc) ([], [], []) attrs |
0 commit comments