X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCicode.c;h=fe437728ce97f42e0c4663a2e65b8a25a3f8b5df;hb=a8df0838af9bf5d521eac7f34da9c296fb64340e;hp=1755276415f448ccbe38055e0006959d74ce0014;hpb=60c7254a378af70bb45e47881bfd0c02fc75c51b;p=fw%2Fsdcc diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 17552764..fe437728 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -561,8 +561,8 @@ newiCode (int op, operand * left, operand * right) ic = Safe_alloc ( sizeof (iCode)); ic->seqPoint = seqPoint; - ic->lineno = lineno; ic->filename = filename; + ic->lineno = lineno; ic->block = block; ic->level = scopeLevel; ic->op = op; @@ -701,8 +701,8 @@ copyiCode (iCode * ic) { iCode *nic = newiCode (ic->op, NULL, NULL); - nic->lineno = ic->lineno; nic->filename = ic->filename; + nic->lineno = ic->lineno; nic->block = ic->block; nic->level = ic->level; nic->parmBytes = ic->parmBytes; @@ -801,7 +801,6 @@ operandType (operand * op) /* depending on type of operand */ switch (op->type) { - case VALUE: return op->operand.valOperand->type; @@ -810,6 +809,7 @@ operandType (operand * op) case TYPE: return op->operand.typeOperand; + default: werror (E_INTERNAL_ERROR, __FILE__, __LINE__, " operand type not known "); @@ -822,7 +822,7 @@ operandType (operand * op) /*-----------------------------------------------------------------*/ /* operandSize - returns size of an operand in bytes */ /*-----------------------------------------------------------------*/ -unsigned int +unsigned int operandSize (operand * op) { sym_link *type; @@ -1947,6 +1947,37 @@ geniCodeRValue (operand * op, bool force) return IC_RESULT (ic); } +static DECLARATOR_TYPE +getPtrType(sym_link *type) +{ + //for Z80 anything goes + if (TARGET_Z80_LIKE) + return POINTER; + + //preserve original behaviour for PIC16 + if (TARGET_IS_PIC16) + 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 */ /*-----------------------------------------------------------------*/ @@ -1979,8 +2010,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) /* 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 */ @@ -2068,7 +2098,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) !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); @@ -3161,7 +3191,7 @@ geniCodeConditional (ast * tree,int lvl) ast *astTrue = tree->right->left; ast *astFalse = tree->right->right; operand *cond = ast2iCode (tree->left, lvl+1); - operand *result = newiTempOperand (tree->right->ftype, 0); + operand *result = newiTempOperand (tree->ftype, 0); operand *opTrue, *opFalse; ic = newiCodeCondition (geniCodeRValue (cond, FALSE), NULL, falseLabel); @@ -3525,6 +3555,7 @@ geniCodeFunctionBody (ast * tree,int lvl) iCode *ic; operand *func; sym_link *fetype; + char *savefilename; int savelineno; /* reset the auto generation */ @@ -3536,15 +3567,19 @@ geniCodeFunctionBody (ast * tree,int lvl) func = ast2iCode (tree->left,lvl+1); fetype = getSpec (operandType (func)); + savefilename = filename; savelineno = lineno; + filename = OP_SYMBOL (func)->fileDef; lineno = OP_SYMBOL (func)->lineDef; /* create an entry label */ geniCodeLabel (entryLabel); + filename = savefilename; lineno = savelineno; /* create a proc icode */ ic = newiCode (FUNCTION, func, NULL); - lineno=ic->lineno = OP_SYMBOL (func)->lineDef; + filename = ic->filename = OP_SYMBOL (func)->fileDef; + lineno = ic->lineno = OP_SYMBOL (func)->lineDef; ic->tree = tree; ADDTOCHAIN (ic); @@ -3945,7 +3980,7 @@ geniCodeCritical (ast *tree, int lvl) operand *op = NULL; sym_link *type; - if (!options.stackAuto) + if (!options.stackAuto && !TARGET_IS_HC08) { type = newLink(SPECIFIER); SPEC_VOLATILE(type) = 1;