((signed char) get_mem(MEM_ROM, addr+immed_offset+1) * 2) & 0xfffe );
break;
case REG_DATA8_REL8 :
- sprintf(parm_str, "%s,#0x%04x,0x%02x",
+ sprintf(parm_str, "%s,#0x%02x,0x%02x",
reg_strs[((code >> 4) & 0xf)],
- get_mem(MEM_ROM, addr+immed_offset),
- ((signed char)get_mem(MEM_ROM, addr+immed_offset+1) * 2) & 0xfffe );
+ get_mem(MEM_ROM, addr+immed_offset+1),
+ ((signed char)get_mem(MEM_ROM, addr+immed_offset) * 2) & 0xfffe );
break;
case REG_DATA16_REL8 :
- sprintf(parm_str, "%s,#0x%02x,0x%02x",
- w_reg_strs[((code >> 4) & 0x7)*2],
- get_mem(MEM_ROM, addr+immed_offset+1) +
- (get_mem(MEM_ROM, addr+immed_offset+0)<<8),
- ((signed char)get_mem(MEM_ROM, addr+immed_offset+2) * 2) & 0xfffe );
+ sprintf(parm_str, "%s,#0x%04x,0x%02x",
+ w_reg_strs[(code >> 4) & 0xf],
+ get_mem(MEM_ROM, addr+immed_offset+2) +
+ (get_mem(MEM_ROM, addr+immed_offset+1)<<8),
+ ((signed char)get_mem(MEM_ROM, addr+immed_offset) * 2) & 0xfffe );
break;
case IREG_DATA8_REL8 :
- sprintf(parm_str, "[%s],#0x%04x,0x%02x",
+ sprintf(parm_str, "[%s],#0x%02x,0x%02x",
reg_strs[((code >> 4) & 0x7)],
- get_mem(MEM_ROM, addr+immed_offset),
- ((signed char)get_mem(MEM_ROM, addr+immed_offset+1) * 2) & 0xfffe );
+ get_mem(MEM_ROM, addr+immed_offset+1),
+ ((signed char)get_mem(MEM_ROM, addr+immed_offset) * 2) & 0xfffe );
break;
case IREG_DATA16_REL8 :
- sprintf(parm_str, "[%s],#0x%02x,0x%02x",
- w_reg_strs[((code >> 4) & 0x7)*2],
- get_mem(MEM_ROM, addr+immed_offset+1) +
- (get_mem(MEM_ROM, addr+immed_offset+0)<<8),
- ((signed char)get_mem(MEM_ROM, addr+immed_offset+2) * 2) & 0xfffe );
+ sprintf(parm_str, "[%s],#0x%04x,0x%02x",
+ w_reg_strs[(code >> 4) & 0x7],
+ get_mem(MEM_ROM, addr+immed_offset+2) +
+ (get_mem(MEM_ROM, addr+immed_offset+1)<<8),
+ ((signed char)get_mem(MEM_ROM, addr+immed_offset) * 2) & 0xfffe );
break;
case A_APLUSDPTR :
strcpy(parm_str, "A, [A+PC]");
break;
+ case REG_REGOFF8 :
+ sprintf(parm_str, "%s,%s+0x%02x",
+ w_reg_strs[(code >> 4) & 0x7],
+ w_reg_strs[code & 0x7],
+ get_mem(MEM_ROM, addr+immed_offset));
+ break;
+
+ case REG_REGOFF16 :
+ sprintf(parm_str, "%s,%s+0x%02x",
+ w_reg_strs[(code >> 4) & 0x7],
+ w_reg_strs[code & 0x7],
+ get_mem(MEM_ROM, addr+immed_offset+1) +
+ (get_mem(MEM_ROM, addr+immed_offset+0)<<8));
+ break;
+
default:
strcpy(parm_str, "???");
break;
return line;
}
-void printIc (char *op, iCode * ic, bool result, bool left, bool right) {
+void printIc (bool printToStderr,
+ char *op, iCode * ic, bool result, bool left, bool right) {
char line[132];
sprintf (line, "%s(%d)", op, ic->lineno);
strcat (line, printOp (IC_RIGHT(ic)));
}
emitcode (";", line);
+ if (printToStderr) {
+ fprintf (stderr, "%s\n", line);
+ }
}
/*-----------------------------------------------------------------*/
/* genNot - generate code for ! operation */
/*-----------------------------------------------------------------*/
static void genNot (iCode * ic) {
- printIc("genNot:", ic, 1,1,0);
+ printIc (0, "genNot:", ic, 1,1,0);
}
/*-----------------------------------------------------------------*/
/* genCpl - generate code for complement */
/*-----------------------------------------------------------------*/
static void genCpl (iCode * ic) {
- printIc("genCpl", ic, 1,1,0);
+ printIc (0, "genCpl", ic, 1,1,0);
}
/*-----------------------------------------------------------------*/
/* genUminus - unary minus code generation */
/*-----------------------------------------------------------------*/
static void genUminus (iCode * ic) {
- printIc("genUminus", ic, 1,1,0);
+ printIc (0, "genUminus", ic, 1,1,0);
}
/*-----------------------------------------------------------------*/
static void genIpush (iCode * ic) {
operand *left=IC_LEFT(ic);
- printIc ("genIpush", ic, 0,1,0);
+ printIc (0, "genIpush", ic, 0,1,0);
aopOp(left,FALSE,FALSE);
/* genIpop - recover the registers: can happen only for spilling */
/*-----------------------------------------------------------------*/
static void genIpop (iCode * ic) {
- printIc ("genIpop", ic, 0,1,0);
+ printIc (0, "genIpop", ic, 0,1,0);
}
/*-----------------------------------------------------------------*/
{
symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- printIc ("genEndFunction", ic, 0,0,0);
+ printIc (0, "genEndFunction", ic, 0,0,0);
if (IFFUNC_ISNAKED(sym->type)) {
emitcode(";", "naked function: no epilogue.");
static void genRet (iCode * ic) {
if (!IC_LEFT(ic)) {
- printIc ("genRet", ic, 0, 0, 0);
+ printIc (0, "genRet", ic, 0, 0, 0);
} else {
- printIc ("genRet", ic, 0, 1, 0);
+ printIc (0, "genRet", ic, 0, 1, 0);
aopOp(IC_LEFT(ic), TRUE, TRUE);
switch (AOP_SIZE(IC_LEFT(ic)))
{
int size;
char *instr;
- printIc ("genPlus", ic, 1,1,1);
+ printIc (0, "genPlus", ic, 1,1,1);
size=aopOp(result, TRUE, TRUE);
/* genMinus - generates code for subtraction */
/*-----------------------------------------------------------------*/
static void genMinus (iCode * ic) {
- printIc ("genMinus", ic, 1,1,1);
+ printIc (0, "genMinus", ic, 1,1,1);
}
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
static void genMult (iCode * ic) {
- printIc ("genMult", ic, 1,1,1);
+ printIc (0, "genMult", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
/* genDiv - generates code for division */
/*-----------------------------------------------------------------*/
static void genDiv (iCode * ic) {
- printIc ("genDiv", ic, 1,1,1);
+ printIc (0, "genDiv", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
/* genMod - generates code for division */
/*-----------------------------------------------------------------*/
static void genMod (iCode * ic) {
- printIc ("genMod", ic, 1,1,1);
-}
-
- /*-----------------------------------------------------------------*/
-/* genCmpGt :- greater than comparison */
-/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode * ic) {
- printIc ("genCmpGt", ic, 1,1,1);
-}
-/*-----------------------------------------------------------------*/
-/* genCmpLt - less than comparisons */
-/*-----------------------------------------------------------------*/
-static void genCmpLt (iCode * ic) {
- printIc ("genCmpLt", ic, 1,1,1);
-}
-/*-----------------------------------------------------------------*/
-/* genCmpEq - generates code for equal to */
-/*-----------------------------------------------------------------*/
-static void genCmpEq (iCode * ic) {
- printIc ("genCmpEq", ic, 1,1,1);
+ printIc (0, "genMod", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
return NULL;
}
+/*-----------------------------------------------------------------*/
+/* 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
+ }
+}
+
/*-----------------------------------------------------------------*/
/* hasInc - operand is incremented before any other use */
/*-----------------------------------------------------------------*/
/* genAndOp - for && operation */
/*-----------------------------------------------------------------*/
static void genAndOp (iCode * ic) {
- printIc ("genAndOp(&&)", ic, 1,1,1);
+ printIc (0, "genAndOp(&&)", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
/* genOrOp - for || operation */
/*-----------------------------------------------------------------*/
static void genOrOp (iCode * ic) {
- printIc ("genOrOp(||)", ic, 1,1,1);
+ printIc (0, "genOrOp(||)", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
/* genAnd - code for and */
/*-----------------------------------------------------------------*/
static void genAnd (iCode * ic, iCode * ifx) {
- printIc ("genAnd", ic, 1,1,1);
+ printIc (0, "genAnd", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
int size;
char *instr;
- printIc ("genOr", ic, 1,1,1);
+ printIc (0, "genOr", ic, 1,1,1);
size=aopOp(result, TRUE, TRUE);
/* genXor - code for xclusive or */
/*-----------------------------------------------------------------*/
static void genXor (iCode * ic, iCode * ifx) {
- printIc ("genXor", ic, 1,1,1);
+ printIc (0, "genXor", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void genInline (iCode * ic) {
- printIc ("genInline", ic, 0,0,0);
+ printIc (0, "genInline", ic, 0,0,0);
emitcode ("", IC_INLINE(ic));
}
/* genRRC - rotate right with carry */
/*-----------------------------------------------------------------*/
static void genRRC (iCode * ic) {
- printIc ("genRRC", ic, 1,1,0);
+ printIc (0, "genRRC", ic, 1,1,0);
}
/*-----------------------------------------------------------------*/
/* genRLC - generate code for rotate left with carry */
/*-----------------------------------------------------------------*/
static void genRLC (iCode * ic) {
- printIc ("genRLC", ic, 1,1,0);
+ printIc (0, "genRLC", ic, 1,1,0);
}
/*-----------------------------------------------------------------*/
/* genGetHbit - generates code get highest order bit */
/*-----------------------------------------------------------------*/
static void genGetHbit (iCode * ic) {
- printIc ("genGetHbit", ic, 1,1,0);
+ printIc (0, "genGetHbit", ic, 1,1,0);
}
/*-----------------------------------------------------------------*/
/* genLeftShift - generates code for left shifting */
/*-----------------------------------------------------------------*/
static void genLeftShift (iCode * ic) {
- printIc ("genLeftShift", ic, 1,1,1);
+ printIc (0, "genLeftShift", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
/* genRightShift - generate code for right shifting */
/*-----------------------------------------------------------------*/
static void genRightShift (iCode * ic) {
- printIc ("genRightShift", ic, 1,1,1);
+ printIc (0, "genRightShift", ic, 1,1,1);
}
/*-----------------------------------------------------------------*/
int size;
if (pi) {
- printIc ("genPointerGet pi", ic, 1,1,0);
+ printIc (0, "genPointerGet pi", ic, 1,1,0);
} else {
- printIc ("genPointerGet", ic, 1,1,0);
+ printIc (0, "genPointerGet", ic, 1,1,0);
}
if (!IS_PTR(operandType(left))) {
operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic);
int size;
- printIc ("genPointerSet", ic, 1,0,1);
+ printIc (0, "genPointerSet", ic, 1,0,1);
if (!IS_PTR(operandType(result))) {
bailOut ("genPointerSet: pointer required");
int size;
operand *left=IC_LEFT(ic);
- printIc ("genAddrOf", ic, 1,1,0);
+ printIc (0, "genAddrOf", ic, 1,1,0);
size=aopOp (IC_RESULT(ic), FALSE, TRUE);
int size;
char *instr;
- printIc ("genAssign", ic, 1,0,1);
+ printIc (0, "genAssign", ic, 1,0,1);
if (!IS_SYMOP(result)) {
bailOut("genAssign: result is not a symbol");
/* genJumpTab - genrates code for jump table */
/*-----------------------------------------------------------------*/
static void genJumpTab (iCode * ic) {
- printIc ("genJumpTab", ic, 0,0,0);
+ printIc (0, "genJumpTab", ic, 0,0,0);
}
/*-----------------------------------------------------------------*/
sym_link *etype=getSpec(rtype);
short ptrType, signedness;
- printIc ("genCast", ic, 1,1,1);
+ printIc (0, "genCast", ic, 1,1,1);
aopOp(result, TRUE, TRUE);
aopOp(right, !aopIsPtr(result), AOP_TYPE(result)!=AOP_DIR);
if (getSize (operandType (IC_RESULT (ic))) > 2)
return 0;
- printIc ("genDjnz", ic, 1,1,1);
+ printIc (0, "genDjnz", ic, 1,1,1);
/* otherwise we can save BIG */
lbl = newiTempLabel (NULL);
/* genReceive - generate code for a receive iCode */
/*-----------------------------------------------------------------*/
static void genReceive (iCode * ic) {
- printIc ("genReceive", ic, 1,0,0);
+ printIc (0, "genReceive", ic, 1,0,0);
}
/*-----------------------------------------------------------------*/