2 // Copyright (c) 1999-2002 by Digital Mars
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
10 // Routines to convert expressions to elems.
24 static char __file__
[] = __FILE__
; /* for tassert.h */
27 /**********************************************
30 * ev should already be a bit type.
33 * 1 want result in flags
34 * 2 want value of result
47 elem
*bit_assign(enum OPER op
, elem
*eb
, elem
*ei
, elem
*ev
, int result
)
54 es
= el_bin(OPbts
, TYbit
, eb
, ei
);
57 es
= el_bin(OPcomma
, TYbit
, es
, el_long(TYbit
, 1));
58 er
= el_bin(OPcomma
, TYbit
, er
, el_long(TYbit
, 0));
60 e
= el_bin(OPcolon
, TYvoid
, es
, er
);
61 e
= el_bin(OPcond
, ev
->Ety
, ev
, e
);
67 *(eb + (ei >> 5)) &= ~(1 << (ei & 31));
68 *(eb + (ei >> 5)) |= ev << (ei & 31);
73 et = (eb + (ei >> 5));
75 *ett = (*et & ~(1 << em)) | (ev << em);
79 printf("bit_assign()\n");
83 elem
*eit
= el_same(&ei
);
86 elem
*evt
= el_same(&ev
);
89 et
= el_bin(OPshr
, TYuint
, ei
, el_long(TYuint
, BIT_SHIFT
));
90 et
= el_bin(OPadd
, TYnptr
, eb
, et
);
94 em
= el_bin(OPand
, TYbit
, eit
, el_long(TYbit
, BIT_MASK
));
96 e
= el_bin(OPshl
, TYbit
, el_long(TYbit
, 1), em
);
97 e
= el_una(OPcom
, TYbit
, e
);
98 et
= el_una(OPind
, TYbit
, et
);
99 e
= el_bin(OPand
, TYbit
, et
, e
);
102 e
= el_bin(OPor
, TYbit
, e
, el_bin(OPshl
, TYbit
, ev
, el_copytree(em
)));
103 ett
= el_una(OPind
, TYbit
, ett
);
104 e
= el_bin(OPeq
, TYbit
, ett
, e
);
106 e
= el_bin(OPcomma
, evt
->Ety
, e
, evt
);
111 /**********************************************
114 * ev should already be a bit type.
116 * 0 don't want result
117 * 1 want result in flags
118 * 2 want value of result
122 elem
*bit_read(elem
*eb
, elem
*ei
, int result
)
127 e
= el_bin(OPbt
, TYbit
, eb
, ei
);
128 e
= el_bin(OPand
, TYbit
, e
, el_long(TYbit
, 1));
131 // eb[ei] => (eb[ei >>> 5] >> (ei & 31)) & 1
133 elem
*eit
= el_same(&ei
);
135 // Now generate ((*(eb + (ei >>> 5)) >>> (eit & 31)) & 1
138 e
= el_bin(OPshr
, TYuint
, ei
, el_long(TYuint
, BIT_SHIFT
));
139 e
= el_bin(OPadd
, TYnptr
, eb
, e
);
140 e
= el_una(OPind
, TYbit
, e
);
142 eit
= el_bin(OPand
, TYbit
, eit
, el_long(TYbit
, BIT_MASK
));
143 e
= el_bin(OPshr
, TYbit
, e
, eit
);
144 e
= el_bin(OPand
, TYbit
, e
, el_long(TYbit
, 1));
146 // BUG: what about return type of e?