From 60c38495d8e7d1941dfd7a42bd209cc7f22dd766 Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 1 Oct 2000 02:04:05 +0000 Subject: [PATCH] added conditional transformation git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@437 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCC.y | 54 +++++++++++++++++++++++++++--------------------------- src/port.h | 10 +++++++++- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/SDCC.y b/src/SDCC.y index 5775b325..ab463d4b 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -31,6 +31,7 @@ #include "SDCCval.h" #include "SDCCmem.h" #include "SDCCast.h" +#include "port.h" extern int yyerror (char *); extern FILE *yyin; @@ -287,41 +288,40 @@ shift_expr relational_expr : shift_expr - | relational_expr '<' shift_expr { $$ = newNode('<',$1,$3); } - | relational_expr '>' shift_expr { $$ = newNode('>',$1,$3); } + | relational_expr '<' shift_expr { + $$ = (port->lt_nge ? + newNode('!',newNode(GE_OP,$1,$3),NULL) : + newNode('<', $1,$3)); + } + | relational_expr '>' shift_expr { + $$ = (port->gt_nle ? + newNode('!',newNode(LE_OP,$1,$3),NULL) : + newNode('>',$1,$3)); + } | relational_expr LE_OP shift_expr { - /* $$ = newNode(LE_OP,$1,$3); */ - /* getting 8051 specific here : will change - LE_OP operation to "not greater than" i.e. - ( a <= b ) === ( ! ( a > b )) */ - $$ = newNode('!', - newNode('>', $1 , $3 ), - NULL); + $$ = (port->le_ngt ? + newNode('!', newNode('>', $1 , $3 ), NULL) : + newNode(LE_OP,$1,$3)); } | relational_expr GE_OP shift_expr { - /* $$ = newNode(GE_OP,$1,$3) ; */ - /* getting 8051 specific here : will change - GE_OP operation to "not less than" i.e. - ( a >= b ) === ( ! ( a < b )) */ - $$ = newNode('!', - newNode('<', $1 , $3 ), - NULL); + $$ = (port->ge_nlt ? + newNode('!', newNode('<', $1 , $3 ), NULL) : + newNode(GE_OP,$1,$3)); } ; equality_expr : relational_expr - | equality_expr EQ_OP relational_expr { $$ = newNode(EQ_OP,$1,$3);} - | equality_expr NE_OP relational_expr - { - /* $$ = newNode(NE_OP,$1,$3); */ - /* NE_OP changed : - expr1 != expr2 is equivalent to - (! expr1 == expr2) */ - $$ = newNode('!', - newNode(EQ_OP,$1,$3), - NULL); - } + | equality_expr EQ_OP relational_expr { + $$ = (port->eq_nne ? + newNode('!',newNode(NE_OP,$1,$3),NULL) : + newNode(EQ_OP,$1,$3)); + } + | equality_expr NE_OP relational_expr { + $$ = (port->ne_neq ? + newNode('!', newNode(EQ_OP,$1,$3), NULL) : + newNode(NE_OP,$1,$3)); + } ; and_expr diff --git a/src/port.h b/src/port.h index 2247a7e9..b98eee53 100644 --- a/src/port.h +++ b/src/port.h @@ -129,7 +129,7 @@ typedef struct { options are parsed. */ void (*setDefaultOptions)(void); /** Does the dirty work. */ - void (*assignRegisters)(eBBlock **, int); + void (*assignRegisters)(struct eBBlock **, int); /** Returns the register name of a symbol. Used so that 'regs' can be an incomplete type. */ @@ -161,6 +161,14 @@ typedef struct { /** If TRUE, then tprintf and !dw will be used for some initalisers */ bool use_dw_for_init; + + /* condition transformations */ + bool lt_nge ; /* transform (a < b) to !(a >= b) */ + bool gt_nle ; /* transform (a > b) to !(a <= b) */ + bool le_ngt ; /* transform (a <= b) to !(a > b) */ + bool ge_nlt ; /* transform (a >= b) to !(a < b) */ + bool ne_neq ; /* transform a != b --> ! (a == b) */ + bool eq_nne ; /* transform a == b --> ! (a != b) */ } PORT; extern PORT *port; -- 2.47.2