1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/* longop.c - software operations on longs for bcc */
/* Copyright (C) 1992 Bruce Evans */
#include "bcc.h"
#include "byteord.h"
#include "gencode.h"
#include "reg.h"
#include "scan.h"
#include "type.h"
/*-----------------------------------------------------------------------------
longop(operation code, source leaf, target leaf)
handles all binary operations on longs
source and target must already have been converted to long,
(except source is int for shifts) and not more than singly indirect
hence they must be direct (in an index reg paired with DREG),
or singly indirect (local, global, or from an index reg)
-----------------------------------------------------------------------------*/
PUBLIC void longop(op, source, target)
op_pt op;
struct symstruct *source;
struct symstruct *target;
{
store_pt reglist;
store_t regmark;
bool_t shiftflag;
scalar_t scalar;
offset_T spmark;
pushlist(reglist = (regmark = reguse) & (OPREG | OPWORKREG));
reguse &= ~reglist;
spmark = sp;
shiftflag = FALSE;
scalar = target->type->scalar;
if ((op_t) op == SLOP || (op_t) op == SROP)
shiftflag = TRUE;
else
scalar |= source->type->scalar;
if ((source->indcount == 0 && !shiftflag) ||
source->type->scalar & CHAR ||
source->storage & (BREG | DREG | OPREG | OPWORKREG))
{
pres2(source, target);
push(source);
}
if (!shiftflag)
address(source);
load(target, OPREG);
if (source->storage == CONSTANT && shiftflag)
{
if (scalar & UNSIGNED)
target->type = ultype;
if ((op_t) op == SLOP)
source->offset.offv = lslconst(source->offset.offv,
target->storage);
else
source->offset.offv = lsrconst(source->offset.offv,
target->storage, scalar & UNSIGNED);
if (source->offset.offv == 0)
goto shiftdone;
}
#ifdef I8088
/* This is ugly! But it works. I should be able to stop it being used
* by removing the char demotion. */
if (source->type->scalar & CHAR &&
!(source->storage & (BREG|DREG|DATREG1B))) {
load(source, DATREG1B);
outop2str("xor\tch,ch"); outnl();
source->storage = DATREG1;
}
#endif
load(source, OPWORKREG);
switch ((op_t) op)
{
case ADDOP:
call("ladd");
break;
case ANDOP:
call("land");
break;
case DIVOP:
call("ldiv");
break;
case EOROP:
call("leor");
break;
case EQOP:
call("lcmp");
break;
case MODOP:
call("lmod");
break;
case MULOP:
call("lmul");
break;
case OROP:
call("lor");
break;
case SLOP:
call("lsl");
break;
case SROP:
call("lsr");
break;
case SUBOP:
call("lsub");
break;
}
if (scalar & UNSIGNED)
{
outbyte('u');
target->type = ultype;
}
outlongendian();
shiftdone:
if ((reguse = regmark) & OPREG && op != EQOP)
load(target, getindexreg());
if (reglist)
{
#ifdef I8088
if (op == EQOP)
changesp(spmark, FALSE);
else
#endif
modstk(spmark);
poplist(reglist);
}
}
/*-----------------------------------------------------------------------------
long1op(operation code, target leaf)
handles all unary operations on longs except inc/dec
target must be not more than singly indirect
hence it must be direct (in an index reg paired with DREG),
or singly indirect (local, global, or from an index reg)
-----------------------------------------------------------------------------*/
PUBLIC void long1op(op, target)
op_pt op;
struct symstruct *target;
{
pushlist(reguse & OPREG);
load(target, OPREG);
if (op == NOTOP)
call("lcom");
else if (op == NEGOP)
call("lneg");
else
call("ltst");
outlongendian();
if (reguse & OPREG)
{
if (op != EQOP)
load(target, getindexreg());
poplist(reguse & OPREG);
}
}
PUBLIC void outlongendian()
{
#ifdef MC6809
outbyte('_');
#endif
#if DYNAMIC_LONG_ORDER
if (long_big_endian)
#endif
#if DYNAMIC_LONG_ORDER || LONG_BIG_ENDIAN
outnbyte('b');
#endif
#if DYNAMIC_LONG_ORDER
else
#endif
#if DYNAMIC_LONG_ORDER || LONG_BIG_ENDIAN == 0
outnbyte('l');
#endif
}
|