Skip to content

Commit 8e6ad58

Browse files
committed
CHB:ARM: add documentation for conditional expressions
1 parent fa3c09f commit 8e6ad58

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

CodeHawk/CHB/bchlibarm32/bCHARMConditionalExpr.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ let arm_conditional_expr
433433
else
434434
begin
435435
(if collect_diagnostics () then
436-
ch_diagnostics_log#add "condition" (x2p expr));
436+
ch_diagnostics_log#add
437+
"condition"
438+
(LBLOCK [condloc#toPretty; STR ": "; (x2p expr); STR ". ";
439+
pretty_print_list frozenVars#listOfValues
440+
(fun v -> v#toPretty) "[" ", " "]" ]));
437441
condfloc#set_test_expr expr;
438442
testfloc#set_test_variables frozenVars#listOfPairs;
439443
(frozenVars#listOfValues, (Some expr), opsused)
@@ -504,7 +508,8 @@ let arm_conditional_conditional_expr
504508
STR "; cond3: ";
505509
x2p cond3]) in
506510

507-
let xpr = XOp (XLOr, [XOp (XLAnd, [XOp (XLNot, [cond1]); cond3]); cond2]) in
511+
let xpr = XOp (XLOr, [XOp (XLAnd, [XOp (XLNot, [cond1]); cond3]);
512+
XOp (XLAnd, [cond1; cond2])]) in
508513
begin
509514
(if collect_diagnostics () then
510515
ch_diagnostics_log#add "condition" (x2p xpr));

CodeHawk/CHB/bchlibarm32/bCHARMConditionalExpr.mli

Lines changed: 44 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
@@ -37,6 +37,21 @@ open BCHLibTypes
3737
(* bchlibarm32 *)
3838
open BCHARMTypes
3939

40+
41+
(** Returns the predicate condition and associated info for a condidional,
42+
in particular it returns a tuple consisting of:
43+
- a list of temporary variables created to preserve the (frozen) values at
44+
the test location (testloc) for the location of the conditional (condloc)
45+
- the predicate that expresses the joint condition of test and condition
46+
code (cc, e.g., EQ), and
47+
- a list of the operands used in the creation of the predicate.
48+
49+
The arguments to the function are:
50+
- [condopc]: the opcode of the conditional instruction (e.g., Branch)
51+
- [testopc]: the opcode of the test instruction (e.g., Compare)
52+
- [condloc]: the location of conditional instruction
53+
- [testloc]: the location of the test instruction.
54+
*)
4055
val arm_conditional_expr:
4156
condopc: arm_opcode_t
4257
-> testopc:arm_opcode_t
@@ -45,6 +60,34 @@ val arm_conditional_expr:
4560
-> (variable_t list * xpr_t option * arm_operand_int list)
4661

4762

63+
(** Returns the predicate condition and associated info as above for a composite
64+
condtitional of the form
65+
{v
66+
I1: <test1> CMP x, #0
67+
I2: <test2-cc1> CMPEQ y, z
68+
I3: <cond-cc2> BGT
69+
v}
70+
where the ultimate predicate condition depends is a composite of potentially
71+
three test - cc combinations:
72+
- if test1-cc1 is true, I2 is executed and the branch predicate is test2-cc2
73+
- if test2-cc1 is false I2 is not executed and branch predicate is test2-cc1
74+
leading to the composite expression
75+
{v
76+
(test1-cc1 /\ test2-cc2) \/ ((not test1-cc1) /\ test1-cc2)
77+
v}
78+
or, in the case of the example above:
79+
{v
80+
(x = 0 /\ y > z) \/ (x != 0 /\ x > 0)
81+
or
82+
(x = 0 /\ y > z) \/ (x > 0)
83+
v}
84+
- [condopc]: the opcode of the conditional instruction (above: BGT)
85+
- [testopc] the opcode of the second test instruction (above: CMPEQ)
86+
- [testtestopc]: the opcode of the first test instruction (above: CMP)
87+
- [condloc]: the location of [condopc]
88+
- [testloc]: the location of [testopc]
89+
- [testtestloc]: the location of [testtestopc]
90+
*)
4891
val arm_conditional_conditional_expr:
4992
condopc: arm_opcode_t
5093
-> testopc: arm_opcode_t

0 commit comments

Comments
 (0)