3 enum condition_tree_type
{
23 struct condition_tree
{
24 condition_tree_type type
;
30 condition_tree
*right
;
32 condition_tree(condition_tree_type type
) :
33 type(type
), val(-1), var(NULL
), left(NULL
), right(NULL
) {}
34 condition_tree(int val
) :
35 type(ctt_cst
), val(val
), var(NULL
), left(NULL
), right(NULL
) {}
36 condition_tree(var_sym
*var
) :
37 type(ctt_sym
), val(-1), var(var
), left(NULL
), right(NULL
) {}
38 condition_tree(const operand
&op
) :
39 type(ctt_lod
), val(-1), var(NULL
), op(op
), left(NULL
), right(NULL
) {}
40 condition_tree(condition_tree_type type
, condition_tree
*left
) :
41 type(type
), val(-1), var(NULL
),
42 left(left
), right(NULL
) {
43 if (!left
|| left
->type
== ctt_invalid
) {
47 this->type
= ctt_invalid
;
48 } else if (type
== ctt_neg
&& left
->type
== ctt_cst
) {
49 this->val
*= left
->val
;
55 condition_tree(condition_tree_type type
,
56 condition_tree
*left
, condition_tree
*right
) :
57 type(type
), val(-1), var(NULL
),
58 left(left
), right(right
) {
59 if (!left
|| left
->type
== ctt_invalid
||
60 !right
|| right
->type
== ctt_invalid
) {
67 this->type
= ctt_invalid
;
68 } else if (type
== ctt_sub
) {
70 this->right
= new condition_tree(ctt_neg
, right
);
71 } else if (type
== ctt_mul
&&
72 left
->type
== ctt_cst
&& right
->type
== ctt_cst
) {
73 this->val
= left
->val
* right
->val
;
79 } else if (type
== ctt_mul
&&
80 left
->type
== ctt_cst
&& right
->type
== ctt_neg
) {
81 condition_tree
*tmp
= right
;
83 this->right
= tmp
->left
;
86 } else if (type
== ctt_mul
&&
87 left
->type
== ctt_cst
&& right
->type
== ctt_add
) {
88 this->left
= new condition_tree(ctt_mul
,
89 new condition_tree(left
->val
),
91 this->right
= new condition_tree(ctt_mul
,
97 } else if (type
== ctt_mul
&&
98 left
->type
== ctt_cst
&& right
->type
== ctt_mul
) {
99 this->left
= new condition_tree(ctt_mul
,
101 this->right
= right
->right
;
107 condition_tree(condition_tree_type type
,
108 int val
, var_sym
*var
,
109 condition_tree
*left
, condition_tree
*right
) :
110 type(type
), val(val
), var(var
),
111 left(left
), right(right
) {
114 condition_tree
*dup() {
115 return new condition_tree(type
, val
, var
,
116 left
? left
->dup() : NULL
,
117 right
? right
->dup() : NULL
);
120 void dump(FILE *out
= stderr
, int indent
= 0);
121 void eliminate_minmax();
131 condition_tree
*construct_condition_tree(operand op
, int verbose
);
132 condition_tree
*construct_condition_tree_expr(instruction
*ins
, int verbose
);
133 condition_tree
*construct_condition_tree(instruction
*ins
, int verbose
);