/* depending on type of operand */
switch (op->type)
{
-
case VALUE:
return op->operand.valOperand->type;
case TYPE:
return op->operand.typeOperand;
+
default:
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
" operand type not known ");
return IC_RESULT (ic);
}
+static DECLARATOR_TYPE
+getPtrType(sym_link *type)
+{
+ //for Z80 anything goes
+ if (TARGET_Z80_LIKE)
+ return POINTER;
+
+ //for HC08 only zeropage ptr is different
+ if (TARGET_IS_HC08)
+ {
+ if (IS_DATA_PTR (type))
+ return POINTER;
+ else
+ return FPOINTER;
+ }
+
+ if (IS_DATA_PTR (type) && TARGET_MCS51_LIKE)
+ return IPOINTER;
+ if (IS_PTR (type))
+ return DCL_TYPE (type);
+ else if (IS_FUNC (type))
+ return CPOINTER;
+ else if (IS_ARRAY (type))
+ return PTR_TYPE (SPEC_OCLS (getSpec (type)));
+ return UPOINTER;
+}
+
/*-----------------------------------------------------------------*/
/* geniCodeCast - changes the value from one type to another */
/*-----------------------------------------------------------------*/
/* if this is a literal then just change the type & return */
if (IS_LITERAL (opetype) && op->type == VALUE && !IS_PTR (type) && !IS_PTR (optype))
{
- return operandFromValue (valCastLiteral (type,
- operandLitValue (op)));
+ return operandFromValue (valCastLiteral (type, operandLitValue (op)));
}
/* if casting to/from pointers, do some checking */
!IS_FIXED (type) &&
!IS_FIXED (optype) &&
((IS_SPEC (type) && IS_SPEC (optype)) ||
- (IS_DECL (type) && IS_DECL (optype) && DCL_TYPE (type) == DCL_TYPE (optype))))
+ (IS_DECL (type) && IS_DECL (optype) && getPtrType (type) == getPtrType (optype))))
{
ic = newiCode ('=', NULL, op);
IC_RESULT (ic) = newiTempOperand (type, 0);
static int
opIsGptr (operand * op)
{
- sym_link *type = operandType (op);
-
- if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
+ if (op && IS_GENPTR (operandType (op)) && (AOP_SIZE (op) == GPTRSIZE))
{
return 1;
}
static int
getDataSize (operand * op)
{
- int size;
- size = AOP_SIZE (op);
+ int size = AOP_SIZE (op);
+
if (size == GPTRSIZE)
{
sym_link *type = operandType (op);
}
if (opIsGptr (IC_RESULT (ic)) &&
- AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
- AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+ IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+ IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
}
/* object not on stack then we need the name */
- size = AOP_SIZE (IC_RESULT (ic));
+ size = getDataSize (IC_RESULT (ic));
offset = 0;
while (size--)
{
char s[SDCC_NAME_MAX];
- if (offset) {
+ if (offset)
+ {
switch (offset) {
case 1:
tsprintf(s, sizeof(s), "#!his",sym->rname);
tsprintf(s, sizeof(s), "#!hihihis",sym->rname);
break;
default: /* should not need this (just in case) */
- SNPRINTF (s, sizeof(s), "#(%s >> %d)",
- sym->rname,
- offset * 8);
+ SNPRINTF (s, sizeof(s), "#(%s >> %d)", sym->rname, offset * 8);
}
}
else
aopPut (IC_RESULT (ic), s, offset++);
}
+ if (opIsGptr (IC_RESULT (ic)))
+ {
+ char buffer[10];
+ SNPRINTF (buffer, sizeof(buffer), "#0x%02x",
+ pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+ aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+ }
release:
freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
/* bit variables done */
/* general case */
- size = AOP_SIZE (result);
+ size = getDataSize (result);
offset = 0;
if (AOP_TYPE (right) == AOP_LIT)
lit = ulFromVal (AOP (right)->aopu.aop_lit);
}
_endLazyDPSEvaluation ();
}
+ adjustArithmeticResult (ic);
release:
freeAsmop (result, NULL, ic, TRUE);
}
/*-----------------------------------------------------------------*/
-/* opIsGptr: returns non-zero if the passed operand is */
-/* a generic pointer type. */
+/* opIsGptr: returns non-zero if the passed operand is */
+/* a generic pointer type. */
/*-----------------------------------------------------------------*/
static int
opIsGptr (operand * op)
{
- sym_link *type = operandType (op);
-
- if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
+ if (op && IS_GENPTR (operandType (op)) && (AOP_SIZE (op) == GPTRSIZE))
{
return 1;
}
static int
getDataSize (operand * op)
{
- int size;
- size = AOP_SIZE (op);
+ int size = AOP_SIZE (op);
+
if (size == GPTRSIZE)
{
sym_link *type = operandType (op);
if (offset == 0)
SETC;
emitcode ("cpl", "a");
- emitcode ("addc", "a,#0");
+ emitcode ("addc", "a,#0x00");
}
else
{
}
emitcode ("mov", "r0,%s", spname);
MOVA ("r0");
- emitcode ("add", "a,#%d", count);
+ emitcode ("add", "a,#0x%02x", count);
emitcode ("mov", "%s,a", spname);
for (i = 0; i < mcs51_nRegs; i++)
{
// allocate space first
emitcode ("mov", "%s,%s", r->name, spname);
MOVA (r->name);
- emitcode ("add", "a,#%d", size);
+ emitcode ("add", "a,#0x%02x", size);
emitcode ("mov", "%s,a", spname);
while (size--)
// allocate space first
emitcode ("mov", "%s,%s", r->name, spname);
MOVA (r->name);
- emitcode ("add", "a,#%d", count);
+ emitcode ("add", "a,#0x%02x", count);
emitcode ("mov", "%s,a", spname);
}
}
if (opIsGptr (IC_RESULT (ic)) &&
- AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
- AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+ IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+ IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
{
- char buffer[5];
+ char buffer[10];
SNPRINTF (buffer, sizeof(buffer),
- "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+ "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
}
}
emitcode ("inc", "a"); /* inc doesn't set carry flag */
else
{
- emitcode ("add", "a,#1"); /* this sets carry flag */
+ emitcode ("add", "a,#0x01"); /* this sets carry flag */
emitcode ("xch", "a,b");
emitcode ("cpl", "a"); /* msb 2's complement */
- emitcode ("addc", "a,#0");
+ emitcode ("addc", "a,#0x00");
emitcode ("xch", "a,b");
}
emitLabel (lbl);
}
else /* compiletimeSign */
{
- if (aopPutUsesAcc (result, "#0xFF", offset))
+ if (aopPutUsesAcc (result, "#0xff", offset))
{
emitcode ("push", "acc");
pushedA = TRUE;
}
else if (bytelit == 0x0FF)
{
- aopPut (result, "#0xFF", offset);
+ aopPut (result, "#0xff", offset);
}
else if (IS_AOP_PREG (left))
{
/* dummy read of volatile operand */
if (isOperandVolatile (left, FALSE))
MOVA (aopGet (left, offset, FALSE, FALSE));
- aopPut (result, "#0xFF", offset);
+ aopPut (result, "#0xff", offset);
continue;
}
}
/* if there was something to be popped then do it */
if (popIc)
- genIpop (popIc);
+ genIpop (popIc);
/* if the condition is a bit variable */
if (isbit && dup)
}
/* object not on stack then we need the name */
- size = AOP_SIZE (IC_RESULT (ic));
+ size = getDataSize (IC_RESULT (ic));
offset = 0;
while (size--)
SNPRINTF (s, sizeof(s), "#%s", sym->rname);
aopPut (IC_RESULT (ic), s, offset++);
}
+ if (opIsGptr (IC_RESULT (ic)))
+ {
+ char buffer[10];
+ SNPRINTF (buffer, sizeof(buffer),
+ "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+ aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+ }
release:
freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
/* bit variables done */
/* general case */
- size = AOP_SIZE (result);
+ size = getDataSize (result);
offset = 0;
if (AOP_TYPE (right) == AOP_LIT)
lit = ulFromVal (AOP (right)->aopu.aop_lit);
offset++;
}
}
+ adjustArithmeticResult (ic);
release:
freeAsmop (result, NULL, ic, TRUE);
/* multiply by three */
if (aopGetUsesAcc (IC_JTCOND (ic), 0))
{
- emitcode ("mov", "b,#3");
+ emitcode ("mov", "b,#0x03");
emitcode ("mul", "ab");
}
else
exit(1);
}
- sprintf(gpValStr, "#0x%x", gpVal);
+ sprintf(gpValStr, "#0x%02x", gpVal);
aopPut (result, gpValStr, GPTRSIZE - 1);
}
goto release;
break;
case IPOP:
- /* IPOP happens only when trying to restore a
- spilt live range, if there is an ifx statement
+ /* IPOP happens only when trying to restore a
+ spilt live range, if there is an ifx statement
following this pop then the if statement might
- be using some of the registers being popped which
- would destory the contents of the register so
- we need to check for this condition and handle it */
+ be using some of the registers being popped which
+ would destory the contents of the register so
+ we need to check for this condition and handle it */
if (ic->next &&
ic->next->op == IFX &&
regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
genIfx (ic->next, ic);
- else
- genIpop (ic);
+ else
+ genIpop (ic);
break;
case CALL: