better type check for type-def's
[fw/sdcc] / src / SDCCopt.c
index 0a21e032896b8ec4a8077b12df842a9af8e49d55..8ed9c5979396b7cc4f29439cc08f03f1e93bf32d 100644 (file)
@@ -58,6 +58,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp)
   operand *right;
   symbol *func = NULL;
   int lineno = ic->lineno;
+  int bytesPushed=0;
 
   ip = ic->next;               /* insertion point */
   /* remove it from the iCode */
@@ -144,6 +145,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp)
        {
          newic = newiCode (IPUSH, right, NULL);
          newic->parmPush = 1;
+         bytesPushed+=4;
        }
 
       addiCodeToeBBlock (ebp, newic, ip);
@@ -158,6 +160,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp)
        {
          newic = newiCode (IPUSH, left, NULL);
          newic->parmPush = 1;
+         bytesPushed+=4;
        }
       addiCodeToeBBlock (ebp, newic, ip);
       newic->lineno = lineno;
@@ -165,8 +168,9 @@ cnvToFcall (iCode * ic, eBBlock * ebp)
   /* insert the call */
   newic = newiCode (CALL, operandFromSymbol (func), NULL);
   IC_RESULT (newic) = IC_RESULT (ic);
-  addiCodeToeBBlock (ebp, newic, ip);
   newic->lineno = lineno;
+  newic->parmBytes+=bytesPushed;
+  addiCodeToeBBlock (ebp, newic, ip);
 }
 
 /*-----------------------------------------------------------------*/
@@ -189,7 +193,7 @@ cnvToFloatCast (iCode * ic, eBBlock * ebp)
     {
       for (su = 0; su < 2; su++)
        {
-         if (checkType (type, __multypes[bwd][su]) == 1)
+         if (compareType (type, __multypes[bwd][su]) == 1)
            {
              func = __conv[0][bwd][su];
              goto found;
@@ -258,7 +262,7 @@ cnvFromFloatCast (iCode * ic, eBBlock * ebp)
     {
       for (su = 0; su < 2; su++)
        {
-         if (checkType (type, __multypes[bwd][su]) == 1)
+         if (compareType (type, __multypes[bwd][su]) == 1)
            {
              func = __conv[1][bwd][su];
              goto found;
@@ -319,6 +323,8 @@ convilong (iCode * ic, eBBlock * ebp, sym_link * type, int op)
   int lineno = ic->lineno;
   int bwd;
   int su;
+  int bytesPushed=0;
+
   remiCodeFromeBBlock (ebp, ic);
 
   /* depending on the type */
@@ -326,7 +332,7 @@ convilong (iCode * ic, eBBlock * ebp, sym_link * type, int op)
     {
       for (su = 0; su < 2; su++)
        {
-         if (checkType (type, __multypes[bwd][su]) == 1)
+         if (compareType (type, __multypes[bwd][su]) == 1)
            {
              if (op == '*')
                func = __muldiv[0][bwd][su];
@@ -380,6 +386,7 @@ found:
        {
          newic = newiCode (IPUSH, IC_RIGHT (ic), NULL);
          newic->parmPush = 1;
+         bytesPushed += getSize(type);
        }
       addiCodeToeBBlock (ebp, newic, ip);
       newic->lineno = lineno;
@@ -391,6 +398,7 @@ found:
        {
          newic = newiCode (IPUSH, IC_LEFT (ic), NULL);
          newic->parmPush = 1;
+         bytesPushed += getSize(type);
        }
       addiCodeToeBBlock (ebp, newic, ip);
       newic->lineno = lineno;
@@ -400,9 +408,9 @@ found:
   /* for the result */
   newic = newiCode (CALL, operandFromSymbol (func), NULL);
   IC_RESULT (newic) = IC_RESULT (ic);
-  addiCodeToeBBlock (ebp, newic, ip);
   newic->lineno = lineno;
-
+  newic->parmBytes+=bytesPushed; // to clear the stack after the call
+  addiCodeToeBBlock (ebp, newic, ip);
 }
 
 /*-----------------------------------------------------------------*/