!IS_VOLATILE (setype) &&
!IN_FARSPACE (SPEC_OCLS (setype)) &&
!OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))))
-
+ {
+ wassert(IS_SYMOP(IC_RESULT (ic)));
+ wassert(IS_SYMOP(IC_RIGHT (ic)));
SPIL_LOC (IC_RIGHT (ic)) =
IC_RESULT (ic)->operand.symOperand;
+ }
+
}
#if 0 /* this needs furthur investigation can save a lot of code */
{
value *tval = args;
+ wassert (IS_SYMOP(op));
+
while (tval)
{
if (tval->sym &&
if (IS_ITEMP (op))
return 0;
- if (op->type == SYMBOL &&
+ if (IS_SYMOP(op) &&
(op->operand.symOperand->level == 0 ||
IS_STATIC (op->operand.symOperand->etype) ||
IS_EXTERN (op->operand.symOperand->etype))
symbol *element = getStructElement (SPEC_STRUCT (etype),
right->operand.symOperand);
+ wassert(IS_SYMOP(right));
+
/* add the offset */
ic = newiCode ('+', left, operandFromLit (element->offset));
ast2iCode (tree,0);
return reverseiCChain ();
}
+
+static const char *opTypeToStr(OPTYPE op)
+{
+ switch(op)
+ {
+ case SYMBOL: return "symbol";
+ case VALUE: return "value";
+ case TYPE: return "type";
+ }
+ return "undefined type";
+}
+
+
+operand *validateOpType(operand *op,
+ const char *macro,
+ const char *args,
+ OPTYPE type,
+ const char *file,
+ unsigned line)
+{
+ if (op && op->type == type)
+ {
+ return op;
+ }
+ fprintf(stderr,
+ "Internal error: validateOpType failed in %s(%s) @ %s:%u:"
+ " expected %s, got %s\n",
+ macro, args, file, line,
+ opTypeToStr(type), op ? opTypeToStr(op->type) : "null op");
+ exit(-1);
+ return op; // never reached, makes compiler happy.
+}
#define IS_OP_GLOBAL(op) (IS_SYMOP(op) && op->isGlobal)
#define IS_OP_POINTER(op) (IS_SYMOP(op) && op->isPtr)
#define IS_OP_PARM(op) (IS_SYMOP(op) && op->isParm)
-#define OP_SYMBOL(op) op->operand.symOperand
-#define OP_SYM_TYPE(op) op->operand.symOperand->type
-#define OP_SYM_ETYPE(op) op->operand.symOperand->etype
-#define OP_VALUE(op) op->operand.valOperand
-#define SPIL_LOC(op) op->operand.symOperand->usl.spillLoc
-#define OP_LIVEFROM(op) op->operand.symOperand->liveFrom
-#define OP_LIVETO(op) op->operand.symOperand->liveTo
-#define OP_REQV(op) op->operand.symOperand->reqv
#define OP_ISLIVE_FCALL(op) (IS_ITEMP(op) && OP_SYMBOL(op)->isLiveFcall)
#define SYM_SPIL_LOC(sym) sym->usl.spillLoc
}
operand;
+extern operand *validateOpType(operand *op,
+ const char *macro,
+ const char *args,
+ OPTYPE type,
+ const char *file,
+ unsigned line);
+
+#define OP_SYMBOL(op) validateOpType(op, "OP_SYMBOL", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand
+#define OP_VALUE(op) validateOpType(op, "OP_VALUE", #op, VALUE, __FILE__, __LINE__)->operand.valOperand
+#define OP_SYM_TYPE(op) validateOpType(op, "OP_SYM_TYPE", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->type
+#define OP_SYM_ETYPE(op) validateOpType(op, "OP_SYM_ETYPE", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->etype
+#define SPIL_LOC(op) validateOpType(op, "SPIL_LOC", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->usl.spillLoc
+#define OP_LIVEFROM(op) validateOpType(op, "OP_LIVEFROM", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->liveFrom
+#define OP_LIVETO(op) validateOpType(op, "OP_LIVETO", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->liveTo
+#define OP_REQV(op) validateOpType(op, "OP_REQV", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->reqv
+
/* definition for intermediate code */
#define IC_RESULT(x) (x)->ulrrcnd.lrr.result
#define IC_LEFT(x) (x)->ulrrcnd.lrr.left
fprintf (stderr, "Cant find macro \"%s\"\n", name);
wassertl (0, "Invalid macro name");
}
-
- /* Replace */
- strncpy(pinto, pval, plen);
- pinto += strlen(pval);
- plen -= plen > strlen(pval) ? strlen(pval) : plen;
- fdidsomething = TRUE;
+ else
+ {
+ /* Replace */
+ strncpy(pinto, pval, plen);
+ pinto += strlen(pval);
+ plen -= plen > strlen(pval) ? strlen(pval) : plen;
+ fdidsomething = TRUE;
+ }
pfrom = pend+1;
}
(IC_RESULT(x) && IC_RESULT(x)->aop && \
IC_RESULT(x)->aop->type == AOP_STK )
-/* #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) emitcode("mov","a,%s",x); */
-#define MOVA(x) { \
- char *_mova_tmp = strdup(x); \
- if (strcmp(_mova_tmp,"a") && strcmp(_mova_tmp,"acc")) \
- { \
- emitcode("mov","a,%s",_mova_tmp); \
- } \
- free(_mova_tmp); \
- }
-#define MOVB(x) { char *_movb_tmp = strdup(x); \
- if (strcmp(_movb_tmp,"b")) \
- { \
- emitcode("mov","b,%s",_movb_tmp); \
- } \
- free(_movb_tmp); \
- }
+#define MOVA(x) _movA(x)
+#define MOVB(x) _movB(x)
+
#define CLRC emitcode("clr","c")
#define SETC emitcode("setb","c")
va_end (ap);
}
+//
+// Move the passed value into A unless it is already there.
+//
+static void
+_movA(const char *s)
+{
+ if (strcmp(s,"a") && strcmp(s,"acc"))
+ {
+ emitcode("mov","a,%s",s);
+ }
+}
+
+//
+// Move the passed value into B unless it is already there.
+//
+static void
+_movB(const char *s)
+{
+ if (strcmp(s,"b"))
+ {
+ emitcode("mov","b,%s",s);
+ }
+}
+
/*-----------------------------------------------------------------*/
/* getFreePtr - returns r0 or r1 whichever is free or can be pushed */
/*-----------------------------------------------------------------*/
_endLazyDPSEvaluation ();
}
pi->generated = 1;
- } else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) &&
+ } else if ((AOP_IS_STR(left) || AOP_INDPTRn(left)) &&
AOP_SIZE(result) > 1 &&
- (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) {
+ IS_SYMOP(left) &&
+ (OP_SYMBOL(left)->liveTo > ic->seq || ic->depth)) {
size = AOP_SIZE (result) - 1;
if (AOP_INDPTRn(left)) {
!IS_BITVAR (sym->etype))
{
/* and that pointer is remat in data space */
- if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+ if (IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->remat &&
!IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) &&
DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER)
{
sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
}
+ wassert(IS_SYMOP(IC_LEFT (ic)));
+ wassert(IS_SYMOP(IC_RIGHT (dic)));
IC_LEFT (ic)->operand.symOperand =
IC_RIGHT (dic)->operand.symOperand;
OP_SYMBOL(IC_LEFT(ic))->liveTo = ic->seq;
sic->rlive = bitVectSetBit (sic->rlive, IC_RIGHT (dic)->key);
}
+ wassert(IS_SYMOP(IC_RIGHT (ic)));
+ wassert(IS_SYMOP(IC_RIGHT (dic)));
IC_RIGHT (ic)->operand.symOperand =
IC_RIGHT (dic)->operand.symOperand;
IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
}
/* mark the pointer usages */
- if (POINTER_SET (ic))
+ if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)))
OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
- if (POINTER_GET (ic))
+ if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic)))
OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic)))
OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
if (ic->op == RECEIVE && ic->argreg == 1 &&
+ IS_SYMOP (IC_RESULT (ic)) &&
getSize (operandType(IC_RESULT(ic))) <= 3)
OP_SYMBOL (IC_RESULT(ic))->uptr = 1;
if (ic->op == SEND && ic->argreg == 1 &&
+ IS_SYMOP(IC_LEFT(ic)) &&
getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3)
OP_SYMBOL (IC_LEFT(ic))->uptr = 1;
one and right is not in far space */
if (POINTER_SET (ic) &&
!isOperandInFarSpace (IC_RIGHT (ic)) &&
+ IS_SYMOP (IC_RESULT (ic)) &&
!OP_SYMBOL (IC_RESULT (ic))->remat &&
!IS_OP_RUONLY (IC_RIGHT (ic)) &&
getSize (aggrToPtr (operandType (IC_RESULT (ic)), FALSE)) > 1) {
/* if pointer get */
if (POINTER_GET (ic) &&
!isOperandInFarSpace (IC_RESULT (ic)) &&
+ IS_SYMOP (IC_LEFT (ic)) &&
!OP_SYMBOL (IC_LEFT (ic))->remat &&
!IS_OP_RUONLY (IC_RESULT (ic)) &&
getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) {
/* and that pointer is remat in data space */
- if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+ if (IS_SYMOP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->remat &&
!IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) &&
DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER)
{
if (POINTER_SET (ic))
OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
- if (POINTER_GET (ic))
+ if (POINTER_GET (ic) &&
+ IS_SYMOP(IC_LEFT (ic)))
OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
if (!SKIP_IC2 (ic))
/* if pointer get */
if (POINTER_GET (ic) &&
+ IS_SYMOP (IC_LEFT (ic)) &&
!isOperandInFarSpace (IC_RESULT (ic)) &&
!OP_SYMBOL (IC_LEFT (ic))->remat &&
!IS_OP_RUONLY (IC_RESULT (ic)) &&
/* if pointer get */
if (!DISABLE_PACK_ONE_USE &&
POINTER_GET (ic) &&
+ IS_SYMOP (IC_LEFT (ic)) &&
/* MLH: dont have far space
!isOperandInFarSpace(IC_RESULT(ic))&& */
!OP_SYMBOL (IC_LEFT (ic))->remat &&