Skip to content

Commit 616854d

Browse files
committed
CHB:ARM: update for change in global variables
1 parent b95b52c commit 616854d

File tree

3 files changed

+29
-69
lines changed

3 files changed

+29
-69
lines changed

CodeHawk/CHB/bchlibarm32/bCHARMAnalysisResults.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module H = Hashtbl
5555

5656
let bd = BCHDictionary.bdictionary
5757
let bcd = BCHBCDictionary.bcdictionary
58+
let mmap = BCHGlobalMemoryMap.global_memory_map
5859

5960

6061
class fn_analysis_results_t (fn:arm_assembly_function_int) =
@@ -194,15 +195,17 @@ object (self)
194195
let dNode = xmlElement "instr-dictionary" in
195196
let iiNode = xmlElement "instructions" in
196197
let sfNode = xmlElement "stackframe" in
198+
let grNode = xmlElement "global-references" in
197199
(* let bNode = xmlElement "btypes" in *)
198200
begin
199201
self#write_xml_cfg cNode;
200202
self#write_xml_jumptables jjNode;
201203
self#write_xml_instructions iiNode;
202204
finfo#stackframe#write_xml sfNode;
205+
mmap#write_xml_references faddr vard grNode;
203206
(* self#write_xml_btypes bNode; *)
204207
id#write_xml dNode;
205-
append [cNode; dNode; iiNode; jjNode; sfNode]
208+
append [cNode; dNode; iiNode; jjNode; sfNode; grNode]
206209
end
207210

208211
method write_xml_register_types

CodeHawk/CHB/bchlibarm32/bCHARMOperand.ml

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ module TR = CHTraceResult
6363
let x2p = xpr_formatter#pr_expr
6464
let p2s = pretty_to_string
6565

66-
let memmap = BCHGlobalMemoryMap.global_memory_map
67-
68-
69-
let log_error (tag: string) (msg: string): tracelogspec_t =
70-
mk_tracelog_spec ~tag:("arm_operand:" ^ tag) msg
71-
7266

7367
let arm_operand_mode_to_string = function RD -> "RD" | WR -> "WR" | RW -> "RW"
7468

@@ -509,20 +503,7 @@ object (self:'a)
509503
STR (String.concat "; " e)]))
510504
| Ok v -> v) in
511505
(v, [STR "ARMShiftedIndexOffset"; STR "explicit"])
512-
| XVar v when floc#f#env#is_memory_address_variable v ->
513-
log_tfold_default
514-
(log_error "ARMShiftedIndexOffset" (p2s v#toPretty))
515-
(fun v ->
516-
(v, [STR "ARMShiftedIndexOffset";
517-
v#toPretty]))
518-
(env#mk_unknown_memory_variable "operand",
519-
[STR "ARMShiftedIndexOffset";
520-
self#toPretty;
521-
STR "; rx: ";
522-
x2p rx;
523-
STR ": ivax: ";
524-
x2p ivax])
525-
(floc#f#env#mk_memory_address_deref_variable v)
506+
(*
526507
| XOp (XPlus, [XVar basevar; XVar memoffset]) ->
527508
let optmemvaraddr = floc#decompose_memvar_address xoffset in
528509
(match optmemvaraddr with
@@ -542,7 +523,7 @@ object (self:'a)
542523
STR "; basevar: ";
543524
basevar#toPretty;
544525
STR "; memoffset: ";
545-
memoffset#toPretty]))
526+
memoffset#toPretty])) *)
546527
| _ ->
547528
(env#mk_unknown_memory_variable "operand",
548529
[STR "ARMShiftedIndexOffset";
@@ -616,17 +597,7 @@ object (self:'a)
616597
match kind with
617598
| ARMImmediate imm ->
618599
let imm = if unsigned then imm#to_unsigned else imm in
619-
(match imm#to_doubleword with
620-
| Some dw ->
621-
if memmap#has_location dw then
622-
let name = memmap#get_location_name dw in
623-
let var =
624-
floc#f#env#mk_global_memory_address
625-
~optname:(Some name) imm#to_numerical in
626-
XVar var
627-
else
628-
num_constant_expr imm#to_numerical
629-
| _ -> num_constant_expr imm#to_numerical)
600+
num_constant_expr imm#to_numerical
630601
| ARMFPConstant _ -> XConst XRandom
631602
| ARMReg _ | ARMWritebackReg _ -> XVar (self#to_variable floc)
632603
| ARMDoubleReg _ -> XVar (self#to_variable floc)
@@ -639,19 +610,7 @@ object (self:'a)
639610
num_constant_expr a#to_numerical
640611
| ARMLiteralAddress a ->
641612
if elf_header#is_readonly_address a then
642-
let dw = elf_header#get_program_value a in
643-
if memmap#has_location dw then
644-
let name = memmap#get_location_name dw in
645-
let ty = memmap#get_location_type dw in
646-
if is_struct_type ty || is_array_type ty then
647-
let var =
648-
floc#f#env#mk_global_memory_address
649-
~optname:(Some name) ~opttype:(Some ty) dw#to_numerical in
650-
XVar var
651-
else
652-
num_constant_expr (elf_header#get_program_value a)#to_numerical
653-
else
654-
num_constant_expr (elf_header#get_program_value a)#to_numerical
613+
num_constant_expr (elf_header#get_program_value a)#to_numerical
655614
else
656615
begin
657616
ch_error_log#add

CodeHawk/CHB/bchlibarm32/bCHFnARMDictionary.ml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ object (self)
104104
]
105105

106106
method index_sp_offset (o:(int * interval_t)) =
107-
let (level,offset) = o in
108-
let key = ([],[level; xd#index_interval offset]) in
107+
let (level, offset) = o in
108+
let key = ([], [level; xd#index_interval offset]) in
109109
sp_offset_table#add key
110110

111111
method get_sp_offset (index:int) =
@@ -478,15 +478,19 @@ object (self)
478478
floc#l#toPretty;
479479
STR ": Parameter type not recognized in call ";
480480
STR "instruction"])) in
481+
let ptype = get_parameter_type p in
481482
let xx = rewrite_expr ?restrict:(Some 4) x in
482-
let _ = floc#memrecorder#record_argument xx index in
483483
let xx =
484-
let optmemvar = floc#decompose_memvar_address xx in
485-
match optmemvar with
486-
| Some (memref, memoff) ->
487-
XOp ((Xf "addressofvar"),
488-
[XVar (floc#f#env#mk_index_offset_memory_variable memref memoff)])
489-
| _ -> xx in
484+
if is_pointer ptype then
485+
let _ = floc#memrecorder#record_argument xx index in
486+
let xx =
487+
TR.tfold_default
488+
(fun v -> XOp ((Xf "addressofvar"), [(XVar v)]))
489+
xx
490+
(floc#get_var_at_address ~btype:ptype xx) in
491+
xx
492+
else
493+
xx in
490494
let rdef = get_rdef xvar in
491495
(xx :: xprs, xvar :: xvars, rdef :: rdefs, index + 1))
492496
([], [], [], 1) callargs in
@@ -568,14 +572,11 @@ object (self)
568572
let rdefs = [get_rdef xrn; get_rdef xrm] @ (get_all_rdefs rresult) in
569573
let uses = get_def_use vrd in
570574
let useshigh = get_def_use_high vrd in
571-
let optmemvar = floc#decompose_memvar_address rresult in
572575
let rresult =
573-
match optmemvar with
574-
| Some (memref, memoff) ->
575-
let memvar =
576-
floc#f#env#mk_index_offset_memory_variable memref memoff in
577-
XOp ((Xf "addressofvar"), [XVar memvar])
578-
| _ -> rresult in
576+
TR.tfold_default
577+
(fun v -> XOp ((Xf "addressofvar"), [(XVar v)]))
578+
rresult
579+
(floc#get_var_at_address rresult) in
579580
let (tagstring, args) =
580581
mk_instrx_data
581582
~vars:[vrd]
@@ -2061,13 +2062,10 @@ object (self)
20612062
let xxsrc = rewrite_floc_expr srcfloc xsrc in
20622063
let xxdst = rewrite_expr ?restrict:(Some 4) xdst in
20632064
let xxdst =
2064-
let optmemvar = floc#decompose_memvar_address xxdst in
2065-
match optmemvar with
2066-
| Some (memref, memoff) ->
2067-
let memvar =
2068-
floc#f#env#mk_index_offset_memory_variable memref memoff in
2069-
XOp ((Xf "addressofvar"), [XVar memvar])
2070-
| _ -> xxdst in
2065+
TR.tfold_default
2066+
(fun v -> XOp ((Xf "addressofvar"), [(XVar v)]))
2067+
xxdst
2068+
(floc#get_var_at_address xxdst) in
20712069
let rdefs = [(get_rdef xsrc); (get_rdef xdst)] in
20722070
let _ =
20732071
match get_string_reference srcfloc xxsrc with

0 commit comments

Comments
 (0)