Skip to content

Commit 51d1547

Browse files
committed
CHB: updates for changes in global variables
1 parent 616854d commit 51d1547

15 files changed

+743
-751
lines changed

CodeHawk/CHB/bchlib/bCHBCDictionary.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ object (self)
432432
let r =
433433
List.mapi (fun i (name, typ, attrs) ->
434434
let name =
435-
if name = "" then "$par$" ^ (string_of_int (i+1)) else name in
436-
(name,typ,attrs)) r in
435+
if name = "" then "x" ^ (string_of_int (i+1)) else name in
436+
(name, typ, attrs)) r in
437437
funargs_table#add ([], List.map self#index_funarg r)
438438

439439
method get_funargs (index: int): bfunarg_t list =

CodeHawk/CHB/bchlib/bCHBCTypeUtil.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,3 +1231,8 @@ let struct_offset_field_categories (ty: btype_t): (int * string) list =
12311231
STR "Struct definition has no field layout: ";
12321232
STR (btype_to_string ty)]))) compinfo.bcfields
12331233
| _ -> [(0, btype_to_string ty)]
1234+
1235+
1236+
let bexp_intconstant ?(ikind=IInt) (n: int) =
1237+
let i64 = Int64.of_int n in
1238+
Const (CInt (i64, ikind, None))

CodeHawk/CHB/bchlib/bCHBCTypeUtil.mli

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,10 @@ val struct_field_categories: btype_t -> string list
295295
If [ty] is not a struct it returns the regular string representation of
296296
[ty] with offset 0.*)
297297
val struct_offset_field_categories: btype_t -> (int * string) list
298+
299+
300+
(** {1 Bexpressions} *)
301+
302+
(** {2 Constants} *)
303+
304+
val bexp_intconstant: ?ikind:ikind_t -> int -> bexp_t

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 14 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ let x2s x = p2s (x2p x)
9393
let log_error (tag: string) (msg: string): tracelogspec_t =
9494
mk_tracelog_spec ~tag:("floc:" ^ tag) msg
9595

96+
let memmap = BCHGlobalMemoryMap.global_memory_map
97+
9698

9799
let unknown_write_symbol = new symbol_t "unknown write"
98100

@@ -690,23 +692,6 @@ object (self)
690692
default ())
691693
(default ())
692694
(numerical_to_doubleword n)
693-
| XVar v when self#f#env#is_memory_address_variable v ->
694-
log_tfold_default
695-
(log_error
696-
"get_memory_variable_1"
697-
(self#cia ^ ": memory address variable: " ^ (p2s var#toPretty)))
698-
(fun v -> v)
699-
(default ())
700-
(self#env#mk_memory_address_deref_variable v)
701-
| XOp (XPlus, [XVar v; XConst (IntConst n)])
702-
when self#f#env#is_memory_address_variable v ->
703-
log_tfold_default
704-
(log_error
705-
"get_memory_variable_1"
706-
(self#cia ^ ": memory address variable: " ^ (p2s var#toPretty)))
707-
(fun v -> v)
708-
(default ())
709-
(self#env#mk_memory_address_deref_variable ~offset:n#toInt v)
710695
| _ ->
711696
let (memref, memoffset) = self#decompose_address address in
712697
if is_constant_offset memoffset then
@@ -1120,82 +1105,18 @@ object (self)
11201105

11211106
method get_fts_parameter_expr (_p: fts_parameter_t) = None
11221107

1123-
method decompose_memvar_address
1124-
(x: xpr_t): (memory_reference_int * memory_offset_t) option =
1125-
let _ = chlog#add "decompose_array_address" (LBLOCK [STR "xpr: "; x2p x]) in
1126-
let vars = vars_as_positive_terms x in
1127-
let memaddrs = List.filter self#f#env#is_memory_address_variable vars in
1128-
let optbase =
1129-
match memaddrs with
1130-
| [base] ->
1131-
let (_, _, _, optty) =
1132-
TR.tget_ok (self#f#env#varmgr#get_memory_address_meminfo base) in
1133-
let offset = simplify_xpr (XOp (XMinus, [x; XVar base])) in
1134-
Some (XVar base, offset, optty)
1135-
| _ ->
1136-
None in
1137-
match optbase with
1138-
| None -> None
1139-
| Some (_, _, None) -> None
1140-
| Some (XVar base, xoffset, Some ty) when is_array_type ty ->
1141-
let _ =
1142-
chlog#add
1143-
"decompose_array_address" (LBLOCK [STR "xoffset: "; x2p xoffset]) in
1144-
let eltty = get_element_type ty in
1145-
let elttysize_r = size_of_btype eltty in
1146-
(match elttysize_r with
1147-
| Error e ->
1148-
begin
1149-
CHTimingLog.log_error
1150-
"Unable to obtain array element size for %s: %s [%s:%d]"
1151-
(x2s (XVar base))
1152-
(String.concat "; " e)
1153-
__FILE__ __LINE__;
1154-
None
1155-
end
1156-
| Ok elttysize ->
1157-
let optmemref = TR.to_option (self#env#mk_base_variable_reference base) in
1158-
let optindex = get_array_index_offset xoffset elttysize in
1159-
let memoffset =
1160-
match optindex with
1161-
| None ->
1162-
let _ =
1163-
chlog#add
1164-
"decompose_array_address"
1165-
(LBLOCK [
1166-
STR "Unable to get array index offset for ";
1167-
x2p xoffset;
1168-
STR " with size ";
1169-
INT elttysize]) in
1170-
UnknownOffset
1171-
| Some (indexxpr, rem) ->
1172-
let remoffset = mk_maximal_memory_offset rem eltty in
1173-
ArrayIndexOffset (indexxpr, remoffset) in
1174-
(match (optmemref, memoffset) with
1175-
| (_, UnknownOffset) -> None
1176-
| (Some memref, memoffset) -> Some (memref, memoffset)
1177-
| _ ->
1178-
None))
1179-
| Some (XVar base, xoffset, Some ty) when is_struct_type ty ->
1180-
let _ =
1181-
chlog#add
1182-
"decompose_struct_address" (LBLOCK [STR "xoffset: "; x2p xoffset]) in
1183-
let optmemref = TR.to_option (self#env#mk_base_variable_reference base) in
1184-
let cinfo = get_struct_type_compinfo ty in
1185-
(match xoffset with
1186-
| XConst (IntConst n) ->
1187-
let optfinfo = get_struct_field_at_offset cinfo n#toInt in
1188-
(match optfinfo with
1189-
| None -> None
1190-
| Some (finfo, rem) when rem = 0 ->
1191-
let memoffset = FieldOffset ((finfo.bfname, cinfo.bckey), NoOffset) in
1192-
(match optmemref with
1193-
| Some memref -> Some (memref, memoffset)
1194-
| _ -> None)
1195-
| _ -> None)
1196-
| _ -> None)
1197-
| _ -> None
1198-
1108+
method get_var_at_address
1109+
?(size=None)
1110+
?(btype=t_unknown)
1111+
(addrvalue: xpr_t): variable_t traceresult =
1112+
match memmap#xpr_containing_location addrvalue with
1113+
| Some gloc ->
1114+
(TR.tmap
1115+
(fun offset -> self#f#env#mk_gloc_variable gloc offset)
1116+
(gloc#address_memory_offset ~tgtsize:size ~tgtbtype:btype addrvalue))
1117+
| _ ->
1118+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
1119+
^ "Unable to create global variable for " ^ (x2s addrvalue)]
11991120

12001121
(* the objective is to extract a base pointer and an offset expression
12011122
* first check whether the expression contains any variables that are known

0 commit comments

Comments
 (0)