Skip to content

Commit 014b65c

Browse files
committed
CHB: more expressive representation for side effect values
1 parent 1648018 commit 014b65c

File tree

7 files changed

+123
-30
lines changed

7 files changed

+123
-30
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,14 +2761,17 @@ object (self)
27612761
let rhs =
27622762
match dest with
27632763
| NumConstant n ->
2764-
log_tfold_default
2765-
(mk_tracelog_spec
2766-
~tag:"get_sideeffect_assign:BlockWrite"
2767-
(self#cia ^ ": constant: " ^ n#toString))
2768-
(fun dw ->
2769-
let argDescr = dw#to_hex_string in
2770-
self#env#mk_side_effect_value self#cia ~global:true argDescr)
2771-
(self#env#mk_side_effect_value self#cia (bterm_to_string dest))
2764+
TR.tfold
2765+
~ok:(fun dw ->
2766+
self#env#mk_global_sideeffect_value self#cia dw "dest")
2767+
~error:(fun e ->
2768+
begin
2769+
log_error_result
2770+
~msg:(p2s (xxpredicate_to_pretty side_effect))
2771+
~tag:"get_sideeffect_assign"
2772+
__FILE__ __LINE__ e;
2773+
self#env#mk_side_effect_value self#cia "dest"
2774+
end)
27722775
(numerical_to_doubleword n)
27732776
| _ ->
27742777
self#env#mk_side_effect_value self#cia (bterm_to_string dest) in

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,16 @@ object (self)
994994
method mk_calltarget_value (tgt:call_target_t) =
995995
self#mk_variable (varmgr#make_calltarget_value tgt)
996996

997-
method mk_side_effect_value (iaddr:ctxt_iaddress_t) ?(global=false) (arg:string) =
998-
self#mk_variable (varmgr#make_side_effect_value iaddr ~global arg)
997+
method mk_global_sideeffect_value
998+
(iaddr: ctxt_iaddress_t) (gaddr: doubleword_int) (arg: string) =
999+
self#mk_variable (varmgr#make_global_sideeffect_value iaddr arg gaddr)
1000+
1001+
method mk_stack_sideeffect_value
1002+
(iaddr: ctxt_iaddress_t) (offset: numerical_t) (arg: string) =
1003+
self#mk_variable (varmgr#make_stack_sideeffect_value iaddr arg offset)
1004+
1005+
method mk_side_effect_value (iaddr:ctxt_iaddress_t) (arg:string) =
1006+
self#mk_variable (varmgr#make_side_effect_value iaddr "sev" arg)
9991007

10001008
method mk_field_value (sname:string) (offset:int) (fname:string) =
10011009
self#mk_variable (varmgr#make_field_value sname offset fname)

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,12 @@ end
34773477

34783478
(** {2 Assembly variable} *)
34793479

3480+
type sideeffect_argument_location_t =
3481+
| SEGlobal of doubleword_int
3482+
| SEStack of numerical_t
3483+
| SEDescr of string (* default value, uninterpreted *)
3484+
3485+
34803486
(** Assembly variable denotations.*)
34813487
type assembly_variable_denotation_t =
34823488
(* size (bytes) memory reference index *)
@@ -3555,11 +3561,11 @@ and constant_value_variable_t =
35553561
| CallTargetValue of call_target_t
35563562

35573563
| SideEffectValue of
3558-
ctxt_iaddress_t (* callsite *)
3559-
* string (* argument description *)
3560-
* bool (* is-global address *)
3561-
(** [SideEffectValue (iaddr, name, is_global)] represents the value
3562-
assigned by the callee at call site [iaddr] to the argument with
3564+
ctxt_iaddress_t (* callsite *)
3565+
* string (* name of parameter *)
3566+
* sideeffect_argument_location_t (* location of argument passed *)
3567+
(** [SideEffectValue (iaddr, name, seloc] represents the value
3568+
assigned by the callee at call site [iaddr] to the parameter with
35633569
name [name].*)
35643570

35653571
| BridgeVariable of ctxt_iaddress_t * int (* call site, argument index *)
@@ -3758,12 +3764,14 @@ class type vardictionary_int =
37583764

37593765
method index_memory_offset: memory_offset_t -> int
37603766
method index_memory_base: memory_base_t -> int
3767+
method index_sideeffect_argument_location: sideeffect_argument_location_t -> int
37613768
method index_assembly_variable_denotation: assembly_variable_denotation_t -> int
37623769
method index_constant_value_variable: constant_value_variable_t -> int
37633770
method index_stack_access: stack_access_t -> int
37643771

37653772
method get_memory_offset: int -> memory_offset_t
37663773
method get_memory_base: int -> memory_base_t
3774+
method get_sideeffect_argument_location: int -> sideeffect_argument_location_t
37673775
method get_assembly_variable_denotation: int -> assembly_variable_denotation_t
37683776
method get_constant_value_variable: int -> constant_value_variable_t
37693777

@@ -3923,8 +3931,12 @@ object
39233931
method make_calltarget_value: call_target_t -> assembly_variable_int
39243932
method make_function_pointer_value:
39253933
string -> string -> ctxt_iaddress_t -> assembly_variable_int
3934+
method make_global_sideeffect_value:
3935+
ctxt_iaddress_t -> string -> doubleword_int -> assembly_variable_int
3936+
method make_stack_sideeffect_value:
3937+
ctxt_iaddress_t -> string -> numerical_t -> assembly_variable_int
39263938
method make_side_effect_value:
3927-
ctxt_iaddress_t -> ?global:bool -> string -> assembly_variable_int
3939+
ctxt_iaddress_t -> string -> string -> assembly_variable_int
39283940
method make_field_value: string -> int -> string -> assembly_variable_int
39293941

39303942
(** {2 Memory references}*)
@@ -4839,8 +4851,11 @@ class type function_environment_int =
48394851
method mk_calltarget_value: call_target_t -> variable_t
48404852
method mk_function_pointer_value:
48414853
string -> string -> ctxt_iaddress_t -> variable_t
4842-
method mk_side_effect_value:
4843-
ctxt_iaddress_t -> ?global:bool-> string -> variable_t
4854+
method mk_global_sideeffect_value:
4855+
ctxt_iaddress_t -> doubleword_int -> string -> variable_t
4856+
method mk_stack_sideeffect_value:
4857+
ctxt_iaddress_t -> numerical_t -> string -> variable_t
4858+
method mk_side_effect_value: ctxt_iaddress_t -> string -> variable_t
48444859
method mk_field_value: string -> int -> string -> variable_t
48454860
method mk_symbolic_value: xpr_t -> variable_t
48464861
method mk_signed_symbolic_value: xpr_t -> int -> int -> variable_t

CodeHawk/CHB/bchlib/bCHSumTypeSerializer.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,25 @@ end
653653
let memory_offset_mcts: memory_offset_t mfts_int = new memory_offset_mcts_t
654654

655655

656+
class sideeffect_argument_location_mcts_t:[sideeffect_argument_location_t] mfts_int =
657+
object
658+
659+
inherit [sideeffect_argument_location_t] mcts_t "sideeffect_argument_location"
660+
661+
method !ts (s: sideeffect_argument_location_t) =
662+
match s with
663+
| SEGlobal _ -> "g"
664+
| SEStack _ -> "s"
665+
| SEDescr _ -> "d"
666+
667+
method !tags = ["d"; "g"; "s"]
668+
669+
end
670+
671+
let sideeffect_argument_location_mcts: sideeffect_argument_location_t mfts_int =
672+
new sideeffect_argument_location_mcts_t
673+
674+
656675
class assembly_variable_denotation_mcts_t:[assembly_variable_denotation_t] mfts_int =
657676
object
658677

CodeHawk/CHB/bchlib/bCHSumTypeSerializer.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The MIT License (MIT)
66
77
Copyright (c) 2005-2020 Kestrel Technology LLC
8-
Copyright (c) 2021-2024 Aarno Labs LLC
8+
Copyright (c) 2021-2025 Aarno Labs LLC
99
1010
Permission is hereby granted, free of charge, to any person obtaining a copy
1111
of this software and associated documentation files (the "Software"), to deal
@@ -96,6 +96,7 @@ val type_constraint_mcts: type_constraint_t mfts_int
9696

9797
val memory_base_mcts: memory_base_t mfts_int
9898
val memory_offset_mcts: memory_offset_t mfts_int
99+
val sideeffect_argument_location_mcts: sideeffect_argument_location_t mfts_int
99100
val assembly_variable_denotation_mcts: assembly_variable_denotation_t mfts_int
100101
val constant_value_variable_mcts: constant_value_variable_t mfts_int
101102
val stack_access_mcts: stack_access_t mfts_int

CodeHawk/CHB/bchlib/bCHVarDictionary.ml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ open BCHBasicTypes
4444
open BCHLibTypes
4545
open BCHSumTypeSerializer
4646

47+
module TR = CHTraceResult
48+
4749

4850
let bcd = BCHBCDictionary.bcdictionary
4951
let bd = BCHDictionary.bdictionary
@@ -74,6 +76,8 @@ object (self)
7476
val xd = xd
7577
val memory_base_table = mk_index_table "memory-base-table"
7678
val memory_offset_table = mk_index_table "memory-offset-table"
79+
val sideeffect_argument_location_table =
80+
mk_index_table "sideeffect-argument-location-table"
7781
val assembly_variable_denotation_table =
7882
mk_index_table "assembly-variable-denotation-table"
7983
val constant_value_variable_table =
@@ -172,6 +176,38 @@ object (self)
172176
| "u" -> UnknownOffset
173177
| s -> raise_tag_error name s memory_offset_mcts#tags
174178

179+
method index_sideeffect_argument_location (s: sideeffect_argument_location_t) =
180+
let tags = [sideeffect_argument_location_mcts#ts s] in
181+
let key = match s with
182+
| SEGlobal a -> (tags @ [a#to_hex_string], [])
183+
| SEStack s -> (tags @ [s#toString], [])
184+
| SEDescr d -> (tags @ [d], []) in
185+
sideeffect_argument_location_table#add key
186+
187+
method get_sideeffect_argument_location (index: int) =
188+
let name = "sideeffect_location" in
189+
let (tags, _) = sideeffect_argument_location_table#retrieve index in
190+
let t = t name tags in
191+
match (t 0) with
192+
| "d" -> SEDescr (t 1)
193+
| "g" ->
194+
TR.tfold
195+
~ok:(fun dw -> SEGlobal dw)
196+
~error:(fun e ->
197+
begin
198+
log_error_result
199+
~msg:"get_sideeffect_location"
200+
~tag:"vardictionary error"
201+
__FILE__ __LINE__ e;
202+
raise
203+
(BCH_failure
204+
(LBLOCK [STR "Vardictionary: get_sideeffect_location: ";
205+
STR (String.concat "; " e)]))
206+
end)
207+
(BCHDoubleword.string_to_doubleword (t 1))
208+
| "s" -> SEStack (CHNumerical.mkNumericalFromString (t 1))
209+
| s -> raise_tag_error name s sideeffect_argument_location_mcts#tags
210+
175211
method index_assembly_variable_denotation (v:assembly_variable_denotation_t) =
176212
let tags = [ assembly_variable_denotation_mcts#ts v ] in
177213
let key = match v with
@@ -182,7 +218,7 @@ object (self)
182218
assembly_variable_denotation_table#add key
183219

184220
method get_assembly_variable_denotation (index:int) =
185-
let name = "assembly_variable_denotation" in
221+
let name = "assembly_variable_denotation" in
186222
let (tags,args) = assembly_variable_denotation_table#retrieve index in
187223
let t = t name tags in
188224
let a = a name args in
@@ -207,8 +243,9 @@ object (self)
207243
| FunctionPointer (s1, s2, a) ->
208244
(tags @ [a], [bd#index_string s1; bd#index_string s2])
209245
| CallTargetValue t -> (tags, [id#index_call_target t])
210-
| SideEffectValue (a, name, isglobal) ->
211-
(tags @ [a ], [bd#index_string name; (if isglobal then 1 else 0)])
246+
| SideEffectValue (a, name, seloc) ->
247+
(tags @ [a],
248+
[bd#index_string name; self#index_sideeffect_argument_location seloc])
212249
| BridgeVariable (a,i) -> (tags @ [a], [i])
213250
| FieldValue (sname,offset,fname) ->
214251
(tags, [bd#index_string sname; offset; bd#index_string fname])
@@ -233,7 +270,9 @@ object (self)
233270
| "ev" -> SyscallErrorReturnValue (t 1)
234271
| "fp" -> FunctionPointer (bd#get_string (a 0), bd#get_string (a 1), t 1)
235272
| "ct" -> CallTargetValue (id#get_call_target (a 0))
236-
| "se" -> SideEffectValue (t 1, bd#get_string (a 0), (a 1) = 1)
273+
| "se" ->
274+
SideEffectValue
275+
(t 1, bd#get_string (a 0), self#get_sideeffect_argument_location (a 1))
237276
| "bv" -> BridgeVariable (t 1, a 0)
238277
| "fv" -> FieldValue (bd#get_string (a 0), a 1, bd#get_string (a 2))
239278
| "sv" -> SymbolicValue (xd#get_xpr (a 0))

CodeHawk/CHB/bchlib/bCHVariable.ml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,12 @@ object (self:'a)
235235

236236
method is_global_sideeffect =
237237
match denotation with
238-
| AuxiliaryVariable (SideEffectValue (_, _, isglobal)) -> isglobal
238+
| AuxiliaryVariable (SideEffectValue (_, _, SEGlobal _)) -> true
239239
| _ -> false
240240

241241
method get_global_sideeffect_target_address: doubleword_result =
242242
match denotation with
243-
| AuxiliaryVariable (SideEffectValue (_, arg, true)) ->
244-
let addr_r = string_to_doubleword arg in
245-
tprop addr_r (__FILE__ ^ ":" ^ (string_of_int __LINE__))
243+
| AuxiliaryVariable (SideEffectValue (_, _, SEGlobal dw)) -> Ok dw
246244
| _ ->
247245
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
248246
^ "Variable is not a global sideeffect value: "
@@ -698,9 +696,19 @@ object (self)
698696
method make_calltarget_value (tgt:call_target_t) =
699697
self#mk_variable (AuxiliaryVariable (CallTargetValue tgt))
700698

701-
method make_side_effect_value
702-
(iaddr:ctxt_iaddress_t) ?(global=false) (arg:string) =
703-
self#mk_variable (AuxiliaryVariable (SideEffectValue (iaddr,arg,global)))
699+
method make_global_sideeffect_value
700+
(iaddr: ctxt_iaddress_t) (arg: string) (gaddr: doubleword_int) =
701+
let sev = SideEffectValue (iaddr, arg, SEGlobal gaddr) in
702+
self#mk_variable (AuxiliaryVariable sev)
703+
704+
method make_stack_sideeffect_value
705+
(iaddr: ctxt_iaddress_t) (arg: string) (stackoffset: numerical_t) =
706+
let sev = SideEffectValue (iaddr, arg, SEStack stackoffset) in
707+
self#mk_variable (AuxiliaryVariable sev)
708+
709+
method make_side_effect_value (iaddr:ctxt_iaddress_t) (descr: string) (arg:string) =
710+
let sev = SideEffectValue (iaddr, arg, SEDescr descr) in
711+
self#mk_variable (AuxiliaryVariable sev)
704712

705713
method make_field_value (sname:string) (offset:int) (fname:string) =
706714
self#mk_variable (AuxiliaryVariable (FieldValue (sname,offset,fname)))

0 commit comments

Comments
 (0)