|
@@ -141,6 +141,7 @@ t_io_infos *file_infos; /* input and output files used by the compiler */
|
|
|
|
|
|
%left COMMA
|
|
|
%left ASSIGN
|
|
|
+%left IF ELSE
|
|
|
%left OROR
|
|
|
%left ANDAND
|
|
|
%left OR_OP
|
|
@@ -567,6 +568,27 @@ exp: NUMBER { $$ = create_expression ($1, IMMEDIATE); }
|
|
|
}
|
|
|
;
|
|
|
|
|
|
+ | exp IF exp ELSE exp
|
|
|
+ {
|
|
|
+ if ( $3.expression_type == IMMEDIATE)
|
|
|
+ $$ = $3.value ? $1 : $5;
|
|
|
+ else {
|
|
|
+ t_axe_expression zero = create_expression(0, IMMEDIATE);
|
|
|
+ t_axe_expression cmp =
|
|
|
+ handle_binary_comparison(program, $3, zero, _EQ_);
|
|
|
+ t_axe_expression one = create_expression(1, IMMEDIATE);
|
|
|
+ t_axe_expression mask = handle_bin_numeric_op(program, cmp, one, SUB);
|
|
|
+ int r = getNewRegister(program);
|
|
|
+ gen_notb_instruction(program, r, mask.value);
|
|
|
+ t_axe_expression notmask = create_expression(r, REGISTER);
|
|
|
+ $$ = handle_bin_numeric_op(program,
|
|
|
+ handle_bin_numeric_op(program, $1, mask, ANDB),
|
|
|
+ handle_bin_numeric_op(program, $5, notmask, ANDB),
|
|
|
+ ORB);
|
|
|
+ }
|
|
|
+ }
|
|
|
+;
|
|
|
+
|
|
|
%%
|
|
|
/*=========================================================================
|
|
|
MAIN
|