Skip to content

Commit d140186

Browse files
committed
CHB:convert memory offset to result type
1 parent 8ad2594 commit d140186

File tree

11 files changed

+291
-189
lines changed

11 files changed

+291
-189
lines changed

CodeHawk/CHB/bchanalyze/bCHTrace.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2020 Kestrel Technology LLC
88
Copyright (c) 2020 Henny Sipma
9-
Copyright (c) 2021-2024 Aarno Labs LLC
9+
Copyright (c) 2021-2025 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -76,10 +76,13 @@ let se_address_is_referenced
7676
if floc#is_address x then
7777
let (memref,memoffset) = floc#decompose_address x in
7878
if is_constant_offset memoffset then
79-
let memv =
80-
finfo#env#mk_memory_variable memref (get_total_constant_offset memoffset) in
81-
let memx = floc#rewrite_variable_to_external memv in
82-
var_is_referenced finfo memx v
79+
TR.tfold_default
80+
(fun offset ->
81+
let memv = finfo#env#mk_memory_variable memref offset in
82+
let memx = floc#rewrite_variable_to_external memv in
83+
var_is_referenced finfo memx v)
84+
false
85+
(get_total_constant_offset memoffset)
8386
else
8487
false
8588
else

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -670,25 +670,28 @@ object (self)
670670
^ ")"]
671671
| _ ->
672672
let (memref_r, memoffset_r) = self#decompose_memaddr address in
673-
tbind
673+
TR.tbind
674674
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
675675
(fun memref ->
676676
if memref#is_global_reference then
677-
tbind
678-
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": memref:global")
677+
TR.tbind
678+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__)
679+
^ ": memref:global")
679680
(fun memoff ->
680-
self#env#mk_global_variable (get_total_constant_offset memoff))
681+
TR.tbind
682+
self#env#mk_global_variable
683+
(get_total_constant_offset memoff))
681684
memoffset_r
682685
else
683-
tmap
686+
TR.tbind
684687
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
685688
(fun memoff ->
686-
(self#env#mk_memory_variable
687-
memref (get_total_constant_offset memoff)))
689+
TR.tmap
690+
(self#env#mk_memory_variable memref)
691+
(get_total_constant_offset memoff))
688692
memoffset_r)
689693
memref_r
690694

691-
692695
method get_memory_variable_1
693696
?(align=1) (* alignment of var value *)
694697
?(size=4)
@@ -749,10 +752,14 @@ object (self)
749752
(self#cia))
750753
(fun v -> v)
751754
(default ())
752-
(self#env#mk_global_variable (get_total_constant_offset memoffset))
755+
(TR.tbind
756+
self#env#mk_global_variable
757+
(get_total_constant_offset memoffset))
753758
else
754-
self#env#mk_memory_variable
755-
memref (get_total_constant_offset memoffset) in
759+
(TR.tfold_default
760+
(self#env#mk_memory_variable memref)
761+
(default ())
762+
(get_total_constant_offset memoffset)) in
756763
memvar
757764
else
758765
default () in
@@ -773,45 +780,44 @@ object (self)
773780
let addr = XOp (XPlus, [addr; num_constant_expr offset]) in
774781
let address = simplify_xpr (self#inv#rewrite_expr addr) in
775782
let (memref_r, memoff_r) = self#decompose_memaddr address in
776-
tbind
783+
TR.tbind
777784
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
778785
(fun memref ->
779786
if memref#is_global_reference then
780-
tbind
787+
TR.tbind
781788
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": memref:global")
782789
(fun memoff ->
783-
self#env#mk_global_variable ~size (get_total_constant_offset memoff))
790+
TR.tbind
791+
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
792+
(self#env#mk_global_variable ~size)
793+
(get_total_constant_offset memoff))
784794
memoff_r
785795
else
786-
tmap
796+
TR.tbind
787797
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
788798
(fun memoff ->
789-
(self#env#mk_memory_variable
790-
memref (get_total_constant_offset memoff)))
799+
TR.tmap
800+
(self#env#mk_memory_variable memref)
801+
(get_total_constant_offset memoff))
791802
memoff_r)
792803
memref_r
793804

794805
method get_memory_variable_2
795806
?(size=4) (var1:variable_t) (var2:variable_t) (offset:numerical_t) =
796-
let _ = track_function
797-
~iaddr:self#cia self#fa
798-
(LBLOCK [
799-
STR "get_memory_variable_2: ";
800-
STR "var1: ";
801-
var1#toPretty;
802-
STR "; var2: ";
803-
var2#toPretty;
804-
STR "; offset: ";
805-
offset#toPretty]) in
807+
let default () =
808+
self#env#mk_memory_variable
809+
(self#env#mk_unknown_memory_reference "memref-2") numerical_zero in
806810
let addr = XOp (XPlus, [XVar var1; XVar var2]) in
807811
let addr = XOp (XPlus, [addr; num_constant_expr offset]) in
808812
let address = self#inv#rewrite_expr addr in
809813
let (memref, memoffset) = self#decompose_address address in
810814
if is_constant_offset memoffset then
811-
self#env#mk_memory_variable ~size memref (get_total_constant_offset memoffset)
815+
TR.tfold_default
816+
(self#env#mk_memory_variable ~size memref)
817+
(default ())
818+
(get_total_constant_offset memoffset)
812819
else
813-
self#env#mk_memory_variable
814-
(self#env#mk_unknown_memory_reference "memref-2") numerical_zero
820+
default ()
815821

816822
(* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
817823
* resolve and save ScaledReg (cpureg1, cpureg2, s, offset) (memrefs3)
@@ -835,21 +841,24 @@ object (self)
835841
[addr; XOp (XMult, [int_constant_expr scale; indexexpr])]) in
836842
let address = simplify_xpr (self#inv#rewrite_expr addr) in
837843
let (memref_r, memoff_r) = self#decompose_memaddr address in
838-
tbind
844+
TR.tbind
839845
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
840846
(fun memref ->
841847
if memref#is_global_reference then
842-
tbind
848+
TR.tbind
843849
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": memref:global")
844850
(fun memoff ->
845-
self#env#mk_global_variable ~size (get_total_constant_offset memoff))
851+
TR.tbind
852+
(self#env#mk_global_variable ~size)
853+
(get_total_constant_offset memoff))
846854
memoff_r
847855
else
848-
tmap
856+
TR.tbind
849857
~msg:(__FILE__ ^ ":" ^ (string_of_int __LINE__))
850858
(fun memoff ->
851-
(self#env#mk_memory_variable
852-
memref (get_total_constant_offset memoff)))
859+
TR.tmap
860+
(self#env#mk_memory_variable memref)
861+
(get_total_constant_offset memoff))
853862
memoff_r)
854863
memref_r
855864

@@ -861,7 +870,7 @@ object (self)
861870
(offset:numerical_t) =
862871
let default () =
863872
self#env#mk_memory_variable
864-
(self#env#mk_unknown_memory_reference "memref-1") offset in
873+
(self#env#mk_unknown_memory_reference "memref-3") offset in
865874
let inv = self#inv in
866875
let indexExpr =
867876
if inv#is_constant index then
@@ -883,10 +892,14 @@ object (self)
883892
(self#cia ^ ": memoffset: " ^ (memory_offset_to_string memoffset)))
884893
(fun v -> v)
885894
(default ())
886-
(self#env#mk_global_variable (get_total_constant_offset memoffset))
895+
(TR.tbind
896+
self#env#mk_global_variable
897+
(get_total_constant_offset memoffset))
887898
else
888-
self#env#mk_memory_variable
889-
~size memref (get_total_constant_offset memoffset)
899+
TR.tfold_default
900+
(self#env#mk_memory_variable ~size memref)
901+
(default ())
902+
(get_total_constant_offset memoffset)
890903
else
891904
default ()
892905
(*

0 commit comments

Comments
 (0)