Added routine to evaluate operands of binary operator
This commit is contained in:
parent
352c5c581b
commit
cf3bcb5e63
1 changed files with 58 additions and 71 deletions
|
@ -117,8 +117,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
int + int, pointer + int, pointer + long,
|
int + int, pointer + int, pointer + long,
|
||||||
long + long, double + double
|
long + long, double + double
|
||||||
*/
|
*/
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (gencode) {
|
if (gencode) {
|
||||||
switch (tp->tp_fund) {
|
switch (tp->tp_fund) {
|
||||||
case INT:
|
case INT:
|
||||||
|
@ -169,8 +168,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
int - int, pointer - int, pointer - long,
|
int - int, pointer - int, pointer - long,
|
||||||
pointer - pointer, long - long, double - double
|
pointer - pointer, long - long, double - double
|
||||||
*/
|
*/
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (!gencode)
|
if (!gencode)
|
||||||
break;
|
break;
|
||||||
switch (tp->tp_fund) {
|
switch (tp->tp_fund) {
|
||||||
|
@ -207,34 +205,31 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
if (gencode && right->ex_class == String) {
|
if (gencode && right->ex_class == String) {
|
||||||
C_loi((arith)1);
|
C_loi((arith)1);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else { /* binary */
|
operands(expr, gencode);
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
if (gencode) {
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
switch (tp->tp_fund) {
|
||||||
if (gencode)
|
case INT:
|
||||||
switch (tp->tp_fund) {
|
case LONG:
|
||||||
case INT:
|
case POINTER:
|
||||||
case LONG:
|
if (tp->tp_unsigned)
|
||||||
case POINTER:
|
C_mlu(tp->tp_size);
|
||||||
if (tp->tp_unsigned)
|
else
|
||||||
C_mlu(tp->tp_size);
|
C_mli(tp->tp_size);
|
||||||
else
|
break;
|
||||||
C_mli(tp->tp_size);
|
case FLOAT:
|
||||||
break;
|
case DOUBLE:
|
||||||
case FLOAT:
|
case LNGDBL:
|
||||||
case DOUBLE:
|
C_mlf(tp->tp_size);
|
||||||
case LNGDBL:
|
break;
|
||||||
/*C_mlf(double_size);*/
|
default:
|
||||||
C_mlf(tp->tp_size);
|
crash("bad type *");
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
crash("bad type *");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (gencode)
|
if (gencode)
|
||||||
switch (tp->tp_fund) {
|
switch (tp->tp_fund) {
|
||||||
case INT:
|
case INT:
|
||||||
|
@ -256,8 +251,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
|
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
|
||||||
if (gencode)
|
if (gencode)
|
||||||
if (tp->tp_unsigned)
|
if (tp->tp_unsigned)
|
||||||
|
@ -266,8 +260,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
C_rmi(tp->tp_size);
|
C_rmi(tp->tp_size);
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (gencode)
|
if (gencode)
|
||||||
if (tp->tp_unsigned)
|
if (tp->tp_unsigned)
|
||||||
C_slu(tp->tp_size);
|
C_slu(tp->tp_size);
|
||||||
|
@ -275,8 +268,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
C_sli(tp->tp_size);
|
C_sli(tp->tp_size);
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (gencode)
|
if (gencode)
|
||||||
if (tp->tp_unsigned)
|
if (tp->tp_unsigned)
|
||||||
C_sru(tp->tp_size);
|
C_sru(tp->tp_size);
|
||||||
|
@ -289,8 +281,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
case GREATEREQ:
|
case GREATEREQ:
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
case NOTEQUAL:
|
case NOTEQUAL:
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (gencode) {
|
if (gencode) {
|
||||||
/* The operands have the same type */
|
/* The operands have the same type */
|
||||||
arith size = left->ex_type->tp_size;
|
arith size = left->ex_type->tp_size;
|
||||||
|
@ -330,8 +321,7 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
case '|':
|
case '|':
|
||||||
case '^':
|
case '^':
|
||||||
/* both operands should have type int */
|
/* both operands should have type int */
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
operands(expr, gencode);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
if (gencode) {
|
if (gencode) {
|
||||||
arith size = tp->tp_size;
|
arith size = tp->tp_size;
|
||||||
|
|
||||||
|
@ -487,11 +477,10 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
while ( ex->ex_class == Oper &&
|
while ( ex->ex_class == Oper &&
|
||||||
ex->OP_OPER == PARCOMMA
|
ex->OP_OPER == PARCOMMA
|
||||||
) {
|
) {
|
||||||
register struct expr *rght = ex->OP_RIGHT;
|
arith size = ex->OP_RIGHT->ex_type->tp_size;
|
||||||
EVAL(rght, RVAL,
|
EVAL(ex->OP_RIGHT, RVAL, size > 0,
|
||||||
rght->ex_type->tp_size > 0,
|
|
||||||
NO_LABEL, NO_LABEL);
|
NO_LABEL, NO_LABEL);
|
||||||
ParSize += ATW(rght->ex_type->tp_size);
|
ParSize += ATW(size);
|
||||||
ex = ex->OP_LEFT;
|
ex = ex->OP_LEFT;
|
||||||
}
|
}
|
||||||
EVAL(ex, RVAL, ex->ex_type->tp_size > 0,
|
EVAL(ex, RVAL, ex->ex_type->tp_size > 0,
|
||||||
|
@ -531,18 +520,14 @@ EVAL(expr, val, code, true_label, false_label)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '.':
|
case '.':
|
||||||
EVAL(left, LVAL, gencode, NO_LABEL, NO_LABEL);
|
case ARROW:
|
||||||
|
EVAL(left, oper == '.' ? LVAL : RVAL, gencode,
|
||||||
|
NO_LABEL, NO_LABEL);
|
||||||
ASSERT(is_cp_cst(right));
|
ASSERT(is_cp_cst(right));
|
||||||
if (gencode) {
|
if (gencode) {
|
||||||
C_adp(right->VL_VALUE);
|
C_adp(right->VL_VALUE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ARROW:
|
|
||||||
EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
|
|
||||||
ASSERT(is_cp_cst(right));
|
|
||||||
if (gencode)
|
|
||||||
C_adp(right->VL_VALUE);
|
|
||||||
break;
|
|
||||||
case ',':
|
case ',':
|
||||||
EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL);
|
EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL);
|
||||||
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
|
||||||
|
@ -816,10 +801,8 @@ assop(type, oper)
|
||||||
*/
|
*/
|
||||||
store_val(vl, tp)
|
store_val(vl, tp)
|
||||||
register struct value *vl;
|
register struct value *vl;
|
||||||
struct type *tp;
|
register struct type *tp;
|
||||||
{
|
{
|
||||||
arith size = tp->tp_size;
|
|
||||||
int tpalign = tp->tp_align;
|
|
||||||
int al_on_word;
|
int al_on_word;
|
||||||
register int inword;
|
register int inword;
|
||||||
register int indword;
|
register int indword;
|
||||||
|
@ -827,12 +810,12 @@ store_val(vl, tp)
|
||||||
|
|
||||||
if (vl->vl_class == Const) { /* absolute addressing */
|
if (vl->vl_class == Const) { /* absolute addressing */
|
||||||
load_cst(val, pointer_size);
|
load_cst(val, pointer_size);
|
||||||
store_block(size, tpalign);
|
store_block(tp->tp_size, tp->tp_align);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
al_on_word = (tpalign % word_align == 0);
|
al_on_word = (tp->tp_align % word_align == 0);
|
||||||
if (!(inword = (size == word_size && al_on_word)))
|
if (!(inword = (tp->tp_size == word_size && al_on_word)))
|
||||||
indword = (size == dword_size && al_on_word);
|
indword = (tp->tp_size == dword_size && al_on_word);
|
||||||
if (vl->vl_class == Name) {
|
if (vl->vl_class == Name) {
|
||||||
register struct idf *id = vl->vl_data.vl_idf;
|
register struct idf *id = vl->vl_data.vl_idf;
|
||||||
register struct def *df = id->id_def;
|
register struct def *df = id->id_def;
|
||||||
|
@ -849,16 +832,16 @@ store_val(vl, tp)
|
||||||
C_sde_dnam(id->id_text, val);
|
C_sde_dnam(id->id_text, val);
|
||||||
else {
|
else {
|
||||||
C_lae_dnam(id->id_text, val);
|
C_lae_dnam(id->id_text, val);
|
||||||
store_block(size, tpalign);
|
store_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ASSERT(df->df_sc != STATIC);
|
ASSERT(df->df_sc != STATIC);
|
||||||
if (inword || indword)
|
if (inword || indword)
|
||||||
StoreLocal(df->df_address + val, size);
|
StoreLocal(df->df_address + val, tp->tp_size);
|
||||||
else {
|
else {
|
||||||
AddrLocal(df->df_address + val);
|
AddrLocal(df->df_address + val);
|
||||||
store_block(size, tpalign);
|
store_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -873,7 +856,7 @@ store_val(vl, tp)
|
||||||
C_sde_dlb(dlb, val);
|
C_sde_dlb(dlb, val);
|
||||||
else {
|
else {
|
||||||
C_lae_dlb(dlb, val);
|
C_lae_dlb(dlb, val);
|
||||||
store_block(size, tpalign);
|
store_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -894,8 +877,6 @@ load_val(expr, rlval)
|
||||||
{
|
{
|
||||||
register struct type *tp = expr->ex_type;
|
register struct type *tp = expr->ex_type;
|
||||||
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
|
int rvalue = (rlval == RVAL && expr->ex_lvalue != 0);
|
||||||
arith size = tp->tp_size;
|
|
||||||
int tpalign = tp->tp_align;
|
|
||||||
int al_on_word;
|
int al_on_word;
|
||||||
register int inword, indword;
|
register int inword, indword;
|
||||||
register arith val = expr->VL_VALUE;
|
register arith val = expr->VL_VALUE;
|
||||||
|
@ -903,16 +884,16 @@ load_val(expr, rlval)
|
||||||
if (expr->VL_CLASS == Const) {
|
if (expr->VL_CLASS == Const) {
|
||||||
if (rvalue) { /* absolute addressing */
|
if (rvalue) { /* absolute addressing */
|
||||||
load_cst(val, pointer_size);
|
load_cst(val, pointer_size);
|
||||||
load_block(size, tpalign);
|
load_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
else /* integer, unsigned, long, enum etc */
|
else /* integer, unsigned, long, enum etc */
|
||||||
load_cst(val, size);
|
load_cst(val, tp->tp_size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (rvalue) {
|
if (rvalue) {
|
||||||
al_on_word = (tpalign % word_align == 0);
|
al_on_word = (tp->tp_align % word_align == 0);
|
||||||
if (!(inword = (size == word_size && al_on_word)))
|
if (!(inword = (tp->tp_size == word_size && al_on_word)))
|
||||||
indword = (size == dword_size && al_on_word);
|
indword = (tp->tp_size == dword_size && al_on_word);
|
||||||
}
|
}
|
||||||
if (expr->VL_CLASS == Label) {
|
if (expr->VL_CLASS == Label) {
|
||||||
if (rvalue) {
|
if (rvalue) {
|
||||||
|
@ -923,7 +904,7 @@ load_val(expr, rlval)
|
||||||
C_lde_dlb(expr->VL_LBL, val);
|
C_lde_dlb(expr->VL_LBL, val);
|
||||||
else {
|
else {
|
||||||
C_lae_dlb(expr->VL_LBL, val);
|
C_lae_dlb(expr->VL_LBL, val);
|
||||||
load_block(size, tpalign);
|
load_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -959,7 +940,7 @@ load_val(expr, rlval)
|
||||||
C_lde_dnam(id->id_text, val);
|
C_lde_dnam(id->id_text, val);
|
||||||
else {
|
else {
|
||||||
C_lae_dnam(id->id_text, val);
|
C_lae_dnam(id->id_text, val);
|
||||||
load_block(size, tpalign);
|
load_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -971,10 +952,10 @@ load_val(expr, rlval)
|
||||||
/* ASSERT(df->df_sc != STATIC); */
|
/* ASSERT(df->df_sc != STATIC); */
|
||||||
if (rvalue) {
|
if (rvalue) {
|
||||||
if (inword || indword)
|
if (inword || indword)
|
||||||
LoadLocal(df->df_address + val, size);
|
LoadLocal(df->df_address + val, tp->tp_size);
|
||||||
else {
|
else {
|
||||||
AddrLocal(df->df_address + val);
|
AddrLocal(df->df_address + val);
|
||||||
load_block(size, tpalign);
|
load_block(tp->tp_size, tp->tp_align);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1003,5 +984,11 @@ load_cst(val, siz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operands(expr, gencode)
|
||||||
|
register struct expr *expr;
|
||||||
|
{
|
||||||
|
EVAL(expr->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL);
|
||||||
|
EVAL(expr->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL);
|
||||||
|
}
|
||||||
#endif LINT
|
#endif LINT
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue