Skip to content

Commit 5810925

Browse files
committed
CHB: rename methods that convert var/xpr into cvar/cxpr
1 parent ff13a62 commit 5810925

File tree

3 files changed

+134
-140
lines changed

3 files changed

+134
-140
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ object (self)
13031303
| XOp (XPlus, [XOp ((Xf "addressofvar"), [XVar v]); xoff])
13041304
when self#f#env#is_global_variable v ->
13051305
let gvaddr_r = self#f#env#get_global_variable_address v in
1306-
let cxoff_r = self#convert_xpr_to_c_expr xoff in
1306+
let cxoff_r = self#xpr_to_cxpr xoff in
13071307
TR.tbind
13081308
~msg:(eloc __LINE__)
13091309
(fun gvaddr ->
@@ -1352,6 +1352,35 @@ object (self)
13521352
self#f#env#mk_offset_memory_variable memref memoff)
13531353
memref_r memoff_r
13541354

1355+
(* deprecated. to be merged with get_var_at_address *)
1356+
method get_lhs_from_address (xpr:xpr_t) =
1357+
let xpr = self#inv#rewrite_expr xpr in
1358+
let default () =
1359+
self#env#mk_memory_variable
1360+
(self#env#mk_unknown_memory_reference "lhs-from-address")
1361+
numerical_zero in
1362+
match xpr with
1363+
| XConst (IntConst n) when n#gt numerical_zero ->
1364+
log_tfold_default
1365+
(mk_tracelog_spec
1366+
~tag:"get_lhs_from_address"
1367+
(self#cia ^ ": constant: " ^ n#toString))
1368+
(fun base ->
1369+
if system_info#get_image_base#le base then
1370+
log_tfold_default
1371+
(log_error
1372+
"get_lhs_from_address"
1373+
(self#cia ^ ": constant: " ^ n#toString))
1374+
(fun v -> v)
1375+
(default ())
1376+
(self#env#mk_global_variable self#l n)
1377+
else
1378+
default ())
1379+
(default ())
1380+
(numerical_to_doubleword n)
1381+
| _ ->
1382+
default ()
1383+
13551384
method get_variable_type (v: variable_t): btype_t traceresult =
13561385
let is_zero (x: xpr_t) =
13571386
match x with
@@ -1504,12 +1533,12 @@ object (self)
15041533
| None -> Error [(elocm __LINE__) ^ "variable: " ^ (x2s (XVar v))]
15051534
| Some t -> Ok t
15061535

1507-
method convert_xpr_to_c_expr
1536+
method xpr_to_cxpr
15081537
?(size=None) ?(xtype=None) (x: xpr_t): xpr_t traceresult =
15091538
let _ =
15101539
log_diagnostics_result
15111540
~msg:(p2s self#l#toPretty)
1512-
~tag:"convert_xpr_to_c_expr"
1541+
~tag:"xpr_to_cxpr"
15131542
__FILE__ __LINE__
15141543
["size: " ^ (opti2s size);
15151544
"xtype: " ^ (optty2s xtype);
@@ -1523,7 +1552,7 @@ object (self)
15231552
Ok (int_constant_expr (-1))
15241553
| _ -> self#convert_xpr_offsets ~xtype ~size x
15251554

1526-
method convert_addr_to_c_pointed_to_expr
1555+
method addr_to_ctgt_xpr
15271556
?(size=None) ?(xtype=None) (a: xpr_t): xpr_t traceresult =
15281557
let vars = vars_as_positive_terms a in
15291558
let knownpointers =
@@ -1533,7 +1562,7 @@ object (self)
15331562
) vars in
15341563
let _ =
15351564
log_diagnostics_result
1536-
~tag:"convert_addr_to_c_pointed_to_expr"
1565+
~tag:"addr_to_ctgt_xpr"
15371566
__FILE__ __LINE__
15381567
[(p2s self#l#toPretty);
15391568
"known pointers: ";
@@ -1597,7 +1626,7 @@ object (self)
15971626
^ "addr: " ^ (x2s a)
15981627
^ ": Not yet handled"]
15991628

1600-
method convert_var_to_c_variable
1629+
method var_to_cvar
16011630
?(size=None) ?(vtype=None) (v: variable_t): variable_t traceresult =
16021631
match vtype with
16031632
| None -> self#convert_variable_offsets ~size v
@@ -2137,34 +2166,6 @@ object (self)
21372166
default ()
21382167
end
21392168

2140-
method get_lhs_from_address (xpr:xpr_t) =
2141-
let xpr = self#inv#rewrite_expr xpr in
2142-
let default () =
2143-
self#env#mk_memory_variable
2144-
(self#env#mk_unknown_memory_reference "lhs-from-address")
2145-
numerical_zero in
2146-
match xpr with
2147-
| XConst (IntConst n) when n#gt numerical_zero ->
2148-
log_tfold_default
2149-
(mk_tracelog_spec
2150-
~tag:"get_lhs_from_address"
2151-
(self#cia ^ ": constant: " ^ n#toString))
2152-
(fun base ->
2153-
if system_info#get_image_base#le base then
2154-
log_tfold_default
2155-
(log_error
2156-
"get_lhs_from_address"
2157-
(self#cia ^ ": constant: " ^ n#toString))
2158-
(fun v -> v)
2159-
(default ())
2160-
(self#env#mk_global_variable self#l n)
2161-
else
2162-
default ())
2163-
(default ())
2164-
(numerical_to_doubleword n)
2165-
| _ ->
2166-
default ()
2167-
21682169
method get_bridge_variable_value (par_index:int) (var:variable_t) =
21692170
if self#f#has_constant var then
21702171
num_constant_expr (self#f#get_constant var )

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6111,41 +6111,6 @@ class type floc_int =
61116111
*)
61126112
method decompose_address: xpr_t -> (memory_reference_int * memory_offset_t)
61136113

6114-
method convert_xpr_to_c_expr:
6115-
?size:int option -> ?xtype:btype_t option -> xpr_t -> xpr_t traceresult
6116-
6117-
method convert_addr_to_c_pointed_to_expr:
6118-
?size:int option -> ?xtype:btype_t option -> xpr_t -> xpr_t traceresult
6119-
6120-
method convert_var_to_c_variable:
6121-
?size:int option
6122-
-> ?vtype:btype_t option
6123-
-> variable_t
6124-
-> variable_t traceresult
6125-
6126-
(*
6127-
method convert_addr_to_c_pointed_to_variable:
6128-
?size:int option
6129-
-> ?vtype:btype_t option
6130-
-> xpr_t
6131-
-> variable_t traceresult
6132-
*)
6133-
6134-
method convert_value_offsets:
6135-
?size:int option -> variable_t -> variable_t traceresult
6136-
6137-
method convert_variable_offsets:
6138-
?vtype:btype_t option
6139-
-> ?size:int option
6140-
-> variable_t
6141-
-> variable_t traceresult
6142-
6143-
method convert_xpr_offsets:
6144-
?xtype:btype_t option -> ?size:int option -> xpr_t -> xpr_t traceresult
6145-
6146-
(* returns the variable associated with the address expression *)
6147-
method get_lhs_from_address: xpr_t -> variable_t
6148-
61496114
(* returns the value of the bridge variable for a given stack
61506115
parameter at this instruction *)
61516116
method get_bridge_variable_value: int -> variable_t -> xpr_t
@@ -6163,10 +6128,17 @@ class type floc_int =
61636128
-> xpr_t (** address value *)
61646129
-> variable_t traceresult
61656130

6131+
(* returns the variable associated with the address expression
6132+
Deprecated. To be merged with get_var_at_address
6133+
*)
6134+
method get_lhs_from_address: xpr_t -> variable_t
6135+
61666136
method get_variable_type: variable_t -> btype_t traceresult
61676137

61686138
method get_xpr_type: xpr_t -> btype_t traceresult
61696139

6140+
6141+
61706142
(** {2 Predicates on variables}*)
61716143

61726144
(* returns true if the given variable evaluates to a constant at this
@@ -6187,6 +6159,33 @@ class type floc_int =
61876159
method has_initial_value: variable_t -> bool
61886160

61896161

6162+
(** {1 Conversion to c expressions / variables}*)
6163+
6164+
method xpr_to_cxpr:
6165+
?size:int option -> ?xtype:btype_t option -> xpr_t -> xpr_t traceresult
6166+
6167+
method addr_to_ctgt_xpr:
6168+
?size:int option -> ?xtype:btype_t option -> xpr_t -> xpr_t traceresult
6169+
6170+
method var_to_cvar:
6171+
?size:int option
6172+
-> ?vtype:btype_t option
6173+
-> variable_t
6174+
-> variable_t traceresult
6175+
6176+
method convert_value_offsets:
6177+
?size:int option -> variable_t -> variable_t traceresult
6178+
6179+
method convert_variable_offsets:
6180+
?vtype:btype_t option
6181+
-> ?size:int option
6182+
-> variable_t
6183+
-> variable_t traceresult
6184+
6185+
method convert_xpr_offsets:
6186+
?xtype:btype_t option -> ?size:int option -> xpr_t -> xpr_t traceresult
6187+
6188+
61906189
(** {1 Conditional jumps}*)
61916190

61926191
(* sets the test expression for this instruction *)

0 commit comments

Comments
 (0)