Skip to content

Commit a2fcfff

Browse files
committed
CHB:ARM: add convenience function to access test instructions
1 parent 3efedae commit a2fcfff

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

CodeHawk/CHB/bchlibarm32/bCHARMAssemblyInstructions.ml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
------------------------------------------------------------------------------
55
The MIT License (MIT)
66
7-
Copyright (c) 2021-2024 Aarno Labs, LLC
7+
Copyright (c) 2021-2025 Aarno Labs, LLC
88
99
Permission is hereby granted, free of charge, to any person obtaining a copy
1010
of this software and associated documentation files (the "Software"), to deal
@@ -1138,3 +1138,24 @@ let get_aggregate (iaddr: doubleword_int): arm_instruction_aggregate_int =
11381138

11391139
let get_arm_jumptables (): (doubleword_int * arm_jumptable_int) list =
11401140
!arm_assembly_instructions#get_jumptables
1141+
1142+
1143+
let get_associated_test_instr
1144+
(finfo: function_info_int)
1145+
(ctxtiaddr: ctxt_iaddress_t)
1146+
: (location_int * arm_assembly_instruction_int) option =
1147+
if finfo#has_associated_cc_setter ctxtiaddr then
1148+
let faddr = finfo#get_address in
1149+
let testiaddr = finfo#get_associated_cc_setter ctxtiaddr in
1150+
let testloc = BCHLocation.ctxt_string_to_location faddr testiaddr in
1151+
let testaddr = testloc#i in
1152+
TR.tfold
1153+
~ok:(fun testinstr -> Some (testloc, testinstr))
1154+
~error:(fun e ->
1155+
begin
1156+
log_error_result __FILE__ __LINE__ e;
1157+
None
1158+
end)
1159+
(get_arm_assembly_instruction testaddr)
1160+
else
1161+
None

CodeHawk/CHB/bchlibarm32/bCHARMAssemblyInstructions.mli

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,20 @@ val has_aggregate: doubleword_int -> bool
102102

103103
(** [get_aggregate iaddr] returns the aggregate registered at virtual address [iaddr].
104104
105-
@raises [BCH_failure] if no aggregate is registered at [iaddr].*)
105+
raise BCH_failure if no aggregate is registered at [iaddr].*)
106106
val get_aggregate: doubleword_int -> arm_instruction_aggregate_int
107107

108108

109109

110110
val get_arm_jumptables: unit -> (doubleword_int * arm_jumptable_int) list
111+
112+
113+
(** [get_associated_test_instr finfo iaddr] returns the location and instruction
114+
that provides the test that is associated with the condition code of the
115+
instruction at address [iaddr]
116+
117+
If no test instruction is associated with the instruction at [iaddr] [None]
118+
is returned.
119+
*)
120+
val get_associated_test_instr:
121+
function_info_int -> ctxt_iaddress_t -> (location_int * arm_assembly_instruction_int) option

0 commit comments

Comments
 (0)