+/*
+ * Is xp an immediate constant?
+ * argtype: how the instruction will interpret the bytes
+ * xp->e_number.num_tag ("numtype"): the kind of number given
+ *
+ * Use the following table:
+ * float: TYPF, TYPD, TYPG, TYPH
+ * quad: TYPQ, TYPO
+ * int: TYPG, TYPW, TYPL
+ *
+ * numtype
+ * argtype float quad int
+ *
+ * float slitflt slitflt slitflt
+ * quad 0 0 0
+ * int 0..63 0 0..63
+ *
+ * Where the table entry implies the predicate to return.
+ */
+#define IMMFLT 1 /* these flags are not used by anybody (yet) */
+#define IMMINT 2
+
+int immconstant(xp, argtype, valuep)
+ reg struct exp *xp;
+ int argtype;
+ int *valuep;
+{
+ reg int back = 0;
+ int numtype;
+ reg int fits;
+
+ if ((xp->e_xtype & XTYPE) != XABS)
+ return(0);
+ if ((xp->e_xtype & XFORW) != 0)
+ return(0);
+ numtype = xp->e_number.num_tag;
+
+ fits = 1;
+ if (passno == 2) switch(argtype){
+ case TYPB:
+ switch(numtype){
+ default: fits = 0; break;
+ case TYPB: fits = 1; break;
+ case TYPW:
+ case TYPL:
+ fits = ISBYTE(xp->e_xvalue) || ISUBYTE(xp->e_xvalue);
+ break;
+ }
+ break;
+ case TYPW:
+ switch(numtype){
+ default: fits = 0; break;
+ case TYPB:
+ case TYPW: fits = 1; break;
+ case TYPL:
+ fits = ISWORD(xp->e_xvalue) || ISUWORD(xp->e_xvalue);
+ break;
+ }
+ break;
+ case TYPF:
+ if (numtype == TYPD){ /* same format for first 32 bits */
+ fits = 1;
+ break;
+ }
+ /*FALLTHROUGH*/
+ default:
+ fits = ty_nbyte[argtype] >= ty_nbyte[numtype];
+ }
+ if (!fits){
+ yywarning("Immediate constant type %s mismatches instruction type %s",
+ ty_string[numtype],
+ ty_string[argtype]);
+ }
+
+ switch(argtype){
+ case TYPF:
+ case TYPG:
+ case TYPD:
+ case TYPH:
+ back = slitflt(xp->e_number, argtype, valuep);
+ break;
+ case TYPO:
+ case TYPQ:
+ back = 0;
+ break;
+ case TYPB:
+ case TYPW:
+ case TYPL:
+ switch(numtype){
+ case TYPO:
+ case TYPQ:
+ back = 0;
+ break;
+ default:
+ *valuep = xp->e_xvalue;
+ back = ISLIT(xp->e_xvalue);
+ break;
+ }
+ break;
+ }
+ return(back);
+}