Skip to content

Commit 6b03359

Browse files
committed
CHB: change base variable into base expression for array and struct
1 parent 2cedce5 commit 6b03359

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ object (self)
15691569
val constant_table = new VariableCollections.table_t (* constants *)
15701570
val calltargets = H.create 5 (* call-targets *)
15711571

1572-
val mutable base_pointers = new VariableCollections.set_t (* base-pointers *)
1572+
val base_pointers = new VariableCollections.set_t (* base-pointers *)
15731573
val mutable stack_adjustment = None (* stack-adjustment *)
15741574
val saved_registers = H.create 3 (* saved-registers -- not read *)
15751575

@@ -2161,8 +2161,6 @@ object (self)
21612161
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *)
21622162

21632163
method add_base_pointer (var:variable_t) =
2164-
let _ = track_function
2165-
self#a (LBLOCK [ STR "add base pointer: " ; var#toPretty ]) in
21662164
base_pointers#add var
21672165

21682166
method get_base_pointers = base_pointers#toList

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,7 @@ class type type_constraint_store_int =
32603260
[BaseArray (v, t)] and [BaseStruct (v, t)] on the other hand is that the
32613261
variable [v] referenced in [BaseVar] refers to a variable that is a
32623262
pointer, that is, its value is the address of the base, while the
3263-
variable [v] in [BaseArray] and [BaseStruct] is a symbolic representation
3263+
expression [x] in [BaseArray] and [BaseStruct] is a symbolic representation
32643264
of the address itself, that is, there is no associated variable in the
32653265
code. The latter two are applicable to global or stack-allocated arrays
32663266
and structs that can be referenced directly via their address without
@@ -3277,10 +3277,10 @@ type memory_base_t =
32773277
(** base provided by an externally controlled variable,
32783278
e.g., argument to the function, or return value from malloc *)
32793279

3280-
| BaseArray of variable_t * btype_t
3280+
| BaseArray of xpr_t * btype_t
32813281
(** base provided by a typed array address *)
32823282

3283-
| BaseStruct of variable_t * btype_t
3283+
| BaseStruct of xpr_t * btype_t
32843284
(** base provided by a typed struct address *)
32853285

32863286
| BaseUnknown of string (** address without interpretation *)
@@ -3290,7 +3290,10 @@ type memory_base_t =
32903290
type memory_offset_t =
32913291
| NoOffset
32923292
| ConstantOffset of numerical_t * memory_offset_t
3293-
(** typically used when the type of the variable is not known*)
3293+
(** typically used when the type of the variable is not known, or for
3294+
global offsets (the absolute address of a global variable), or for
3295+
stack offsets (the difference between the stack pointer and the value
3296+
of the stack pointer at function entry *)
32943297

32953298
| FieldOffset of fielduse_t * memory_offset_t
32963299
(** offset in a struct variable with [(fieldname, struct key)] *)
@@ -3332,13 +3335,13 @@ object ('a)
33323335
memory reference.
33333336
33343337
Returns [Error] if this memory reference does not have a [BaseArray] base.*)
3335-
method get_array_base: (variable_t * btype_t) traceresult
3338+
method get_array_base: (xpr_t * btype_t) traceresult
33363339

33373340
(** Returns the memory address variable and type of the base address of this
33383341
memory reference.
33393342
33403343
Returns [Error] if this memory reference does not have a [BaseStruct] base.*)
3341-
method get_struct_base: (variable_t * btype_t) traceresult
3344+
method get_struct_base: (xpr_t * btype_t) traceresult
33423345

33433346
(** {1 Predicates} *)
33443347

@@ -3377,8 +3380,8 @@ object
33773380
method mk_allocated_stack_reference: memory_reference_int
33783381
method mk_realigned_stack_reference: memory_reference_int
33793382
method mk_basevar_reference: variable_t -> memory_reference_int
3380-
method mk_base_array_reference: variable_t -> btype_t -> memory_reference_int
3381-
method mk_base_struct_reference: variable_t -> btype_t -> memory_reference_int
3383+
method mk_base_array_reference: xpr_t -> btype_t -> memory_reference_int
3384+
method mk_base_struct_reference: xpr_t -> btype_t -> memory_reference_int
33823385
method mk_unknown_reference: string -> memory_reference_int
33833386

33843387
(** {1 Accessors} *)

CodeHawk/CHB/bchlib/bCHMemoryReference.ml

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ open CHTraceResult
3939

4040
(* xprlib *)
4141
open Xprt
42+
open XprTypes
4243
open XprToPretty
4344

4445
(* bchlib *)
@@ -64,8 +65,8 @@ let memory_base_to_string (b: memory_base_t): string =
6465
| BAllocatedStackFrame -> "allocated-stack"
6566
| BGlobal -> "global"
6667
| BaseVar v -> "var-" ^ v#getName#getBaseName
67-
| BaseArray (v, _) -> "array-" ^ v#getName#getBaseName
68-
| BaseStruct (v, _) -> "struct-" ^ v#getName#getBaseName
68+
| BaseArray (x, _) -> "array-" ^ (x2s x)
69+
| BaseStruct (x, _) -> "struct-" ^ (x2s x)
6970
| BaseUnknown s -> "unknown-" ^ s
7071

7172

@@ -322,11 +323,11 @@ object (self:'a)
322323

323324
method get_base = base
324325

325-
method get_name =
326+
method get_name: string =
326327
match base with
327328
| BaseVar v -> v#getName#getBaseName
328-
| BaseArray (v, _) -> v#getName#getBaseName
329-
| BaseStruct (v, _) -> v#getName#getBaseName
329+
| BaseArray (x, _) -> (x2s x)
330+
| BaseStruct (x, _) -> (x2s x)
330331
| BLocalStackFrame -> "var"
331332
| BRealignedStackFrame -> "varr"
332333
| BAllocatedStackFrame -> "vara"
@@ -343,25 +344,25 @@ object (self:'a)
343344
match base with
344345
| BaseVar v -> Ok v
345346
| _ ->
346-
Error [
347-
"get_external_base: not an external base: "
348-
^ (memory_base_to_string base)]
347+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
348+
^ "Not an external base: "
349+
^ (memory_base_to_string base)]
349350

350-
method get_array_base: (variable_t * btype_t) traceresult =
351+
method get_array_base: (xpr_t * btype_t) traceresult =
351352
match base with
352-
| BaseArray (v, t) -> Ok (v, t)
353+
| BaseArray (x, t) -> Ok (x, t)
353354
| _ ->
354-
Error [
355-
"get_array_base: not an array base: "
356-
^ (memory_base_to_string base)]
355+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
356+
^ "Not an array base: "
357+
^ (memory_base_to_string base)]
357358

358-
method get_struct_base: (variable_t * btype_t) traceresult =
359+
method get_struct_base: (xpr_t * btype_t) traceresult =
359360
match base with
360-
| BaseStruct (v, t) -> Ok (v, t)
361+
| BaseStruct (x, t) -> Ok (x, t)
361362
| _ ->
362-
Error [
363-
"get_struct_base: not a struct base: "
364-
^ (memory_base_to_string base)]
363+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
364+
^ "Not a struct base: "
365+
^ (memory_base_to_string base)]
365366

366367
method has_external_base =
367368
match base with BaseVar _ -> true | _ -> false
@@ -384,7 +385,7 @@ object (self:'a)
384385
method is_unknown_reference =
385386
match base with BaseUnknown _ -> true | _ -> false
386387

387-
method toPretty = LBLOCK [ memory_base_to_pretty base ]
388+
method toPretty = LBLOCK [memory_base_to_pretty base]
388389

389390
end
390391

@@ -419,20 +420,20 @@ object (self)
419420

420421
method mk_basevar_reference v = self#mk_reference (BaseVar v)
421422

422-
method mk_base_array_reference (v: variable_t) (t: btype_t) =
423-
self#mk_reference (BaseArray (v, t))
423+
method mk_base_array_reference (x: xpr_t) (t: btype_t) =
424+
self#mk_reference (BaseArray (x, t))
424425

425-
method mk_base_struct_reference (v: variable_t) (t: btype_t) =
426-
self#mk_reference (BaseStruct (v, t))
426+
method mk_base_struct_reference (x: xpr_t) (t: btype_t) =
427+
self#mk_reference (BaseStruct (x, t))
427428

428429
method mk_unknown_reference s = self#mk_reference (BaseUnknown s)
429430

430431
method get_memory_reference (index: int): memory_reference_int traceresult =
431432
if H.mem table index then
432433
Ok (H.find table index)
433434
else
434-
Error [
435-
"get_memory_reference_int: index not found: " ^ (string_of_int index)]
435+
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
436+
^ "Index not found: " ^ (string_of_int index)]
436437

437438
method get_memory_reference_type (index: int): btype_t option =
438439
tfold_default
@@ -443,13 +444,13 @@ object (self)
443444
method is_unknown_reference (index: int): bool traceresult =
444445
let memref_r = self#get_memory_reference index in
445446
tmap
446-
~msg:"is_unknown_reference"
447+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
447448
(fun memref -> memref#is_unknown_reference) memref_r
448449

449450
method is_global_reference (index: int): bool traceresult =
450451
let memref_r = self#get_memory_reference index in
451452
tmap
452-
~msg:"is_global_reference"
453+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
453454
(fun memref -> memref#is_global_reference) memref_r
454455

455456
method initialize =

CodeHawk/CHB/bchlib/bCHVarDictionary.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ object (self)
117117
| BAllocatedStackFrame
118118
| BGlobal -> (tags, [])
119119
| BaseVar v -> (tags, [xd#index_variable v])
120-
| BaseArray (v, t) -> (tags, [xd#index_variable v; bcd#index_typ t])
121-
| BaseStruct (v, t) -> (tags, [xd#index_variable v; bcd#index_typ t])
120+
| BaseArray (x, t) -> (tags, [xd#index_xpr x; bcd#index_typ t])
121+
| BaseStruct (x, t) -> (tags, [xd#index_xpr x; bcd#index_typ t])
122122
| BaseUnknown s -> (tags, [bd#index_string s]) in
123123
memory_base_table#add key
124124

@@ -133,8 +133,8 @@ object (self)
133133
| "a" -> BAllocatedStackFrame
134134
| "g" -> BGlobal
135135
| "v" -> BaseVar (xd#get_variable (a 0))
136-
| "b" -> BaseArray (xd#get_variable (a 0), bcd#get_typ (a 1))
137-
| "s" -> BaseStruct (xd#get_variable (a 0), bcd#get_typ (a 1))
136+
| "b" -> BaseArray (xd#get_xpr (a 0), bcd#get_typ (a 1))
137+
| "s" -> BaseStruct (xd#get_xpr (a 0), bcd#get_typ (a 1))
138138
| "u" -> BaseUnknown (bd#get_string (a 0))
139139
| s -> raise_tag_error name s memory_base_mcts#tags
140140

0 commit comments

Comments
 (0)