+/*-----------------------------------------------------------------*/
+/* genCmp - compares whatever */
+/*-----------------------------------------------------------------*/
+static void genCmp (iCode * ic, char *trueInstr, char *falseInstr) {
+ iCode *ifx=ifxForOp(IC_RESULT(ic),ic);
+ operand *left=IC_LEFT(ic), *right=IC_RIGHT(ic);
+ int size;
+ bool isTrue;
+ char *instr;
+ int jlbl;
+
+ if (!ifx) {
+ bailOut("genCmp: no ifx");
+ } else {
+ ifx->generated=1;
+ }
+
+ size=aopOp(left, TRUE, TRUE);
+ aopOp(right, !aopIsPtr(left), TRUE);
+
+ if (IC_TRUE(ifx)) {
+ isTrue=TRUE;
+ jlbl=IC_TRUE(ifx)->key+100;
+ } else {
+ isTrue=FALSE;
+ jlbl=IC_FALSE(ifx)->key+100;
+ }
+
+ if (size==1) {
+ instr="cmp.b";
+ } else {
+ instr="cmp.w";
+ }
+ emitcode(instr, "%s,%s", AOP_NAME(left)[0], AOP_NAME(right)[0]);
+ emitcode(isTrue ? trueInstr : falseInstr, "%05d$", jlbl);
+ if (size>2) {
+ bailOut("genCmp: size > 2");
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* genCmpEq :- generates code for equal to */
+/*-----------------------------------------------------------------*/
+static void genCmpEq (iCode * ic) {
+ printIc (0, "genCmpEq", ic, 0,1,1);
+ genCmp(ic, "beq", "bne"); // no sign
+}
+
+/*-----------------------------------------------------------------*/
+/* genCmpGt :- greater than comparison */
+/*-----------------------------------------------------------------*/
+static void genCmpGt (iCode * ic) {
+ printIc (0, "genCmpGt", ic, 0,1,1);
+ if (SPEC_USIGN(operandType(IC_LEFT(ic))) ||
+ SPEC_USIGN(operandType(IC_RIGHT(ic)))) {
+ genCmp(ic, "bg", "bl"); // unsigned
+ } else {
+ genCmp(ic, "bgt", "ble"); // signed
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* genCmpLt - less than comparisons */
+/*-----------------------------------------------------------------*/
+static void genCmpLt (iCode * ic) {
+ printIc (0, "genCmpLt", ic, 0,1,1);
+ if (SPEC_USIGN(operandType(IC_LEFT(ic))) ||
+ SPEC_USIGN(operandType(IC_RIGHT(ic)))) {
+ genCmp(ic, "bcs", "bcc"); // unsigned
+ } else {
+ genCmp(ic, "blt", "bge"); // signed
+ }
+}
+