static ast *createIvalCharPtr (ast *, sym_link *, ast *);
static ast *optimizeCompare (ast *);
ast *optimizeRRCRLC (ast *);
+ast *optimizeSWAP (ast *);
ast *optimizeGetHbit (ast *);
ast *backPatchLabels (ast *, symbol *, symbol *);
void PA(ast *t);
case RRC:
case RLC:
case GETHBIT:
+ case SWAP:
if (IS_AST_SYM_VALUE (pbody->left) &&
isSymbolEqual (AST_SYMBOL (pbody->left), sym))
return FALSE;
case '?':
case ':':
case SIZEOF: /* evaluate wihout code generation */
+
+ if (IS_AST_SYM_VALUE (pbody->left) &&
+ isSymbolEqual (AST_SYMBOL (pbody->left), sym))
+ return FALSE;
+
+ if (IS_AST_SYM_VALUE (pbody->right) &&
+ isSymbolEqual (AST_SYMBOL (pbody->right), sym))
+ return FALSE;
return isConformingBody (pbody->left, sym, body) &&
isConformingBody (pbody->right, sym, body);
/* adjust the storage class */
switch (DCL_TYPE(tree->left->ftype)) {
case POINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_DATA;
break;
case FPOINTER:
SPEC_SCLS(TETYPE(tree)) = S_XDATA;
SPEC_SCLS(TETYPE(tree)) = S_CODE;
break;
case GPOINTER:
+ SPEC_SCLS (TETYPE (tree)) = 0;
break;
case PPOINTER:
SPEC_SCLS(TETYPE(tree)) = S_XSTACK;
SPEC_SCLS(TETYPE(tree)) = S_EEPROM;
break;
case UPOINTER:
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
case ARRAY:
case FUNCTION:
break;
ast *wtree = optimizeRRCRLC (tree);
if (wtree != tree)
return decorateType (wtree);
+
+ wtree = optimizeSWAP (tree);
+ if (wtree != tree)
+ return decorateType (wtree);
+
// fall through
}
}
TTYPE (tree) = copyLinkChain (LTYPE (tree)->next);
TETYPE (tree) = getSpec (TTYPE (tree));
+ /* adjust the storage class */
+ switch (DCL_TYPE(tree->left->ftype)) {
+ case POINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_DATA;
+ break;
+ case FPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_XDATA;
+ break;
+ case CPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_CODE;
+ break;
+ case GPOINTER:
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
+ case PPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_XSTACK;
+ break;
+ case IPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_IDATA;
+ break;
+ case EEPPOINTER:
+ SPEC_SCLS(TETYPE(tree)) = S_EEPROM;
+ break;
+ case UPOINTER:
+ SPEC_SCLS (TETYPE (tree)) = 0;
+ break;
+ case ARRAY:
+ case FUNCTION:
+ break;
+ }
return tree;
}
/*----------------------------*/
case RRC:
case RLC:
+ case SWAP:
TTYPE (tree) = LTYPE (tree);
TETYPE (tree) = LETYPE (tree);
return tree;
}
}
LRVAL (tree) = RRVAL (tree) = 1;
- if (IS_LITERAL (LTYPE (tree)) && !IS_LITERAL (RTYPE (tree)))
- {
- COPYTYPE (TTYPE (tree), TETYPE (tree), RTYPE (tree));
- }
- else
- {
- COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree));
- }
+ TTYPE (tree) = TETYPE (tree) = copyLinkChain (LTYPE (tree));
+ if (IS_LITERAL (TTYPE (tree)))
+ SPEC_SCLS (TTYPE (tree)) &= ~S_LITERAL;
return tree;
/*------------------------------------------------------------------*/
if ((i = (int) AST_LIT_VALUE (tree->left->right)) !=
(j = (getSize (TTYPE (tree->left->left)) * 8 - 1)))
return tree;
+
+ /* make sure the port supports GETHBIT */
+ if (port->hasExtBitOp
+ && !port->hasExtBitOp(GETHBIT, getSize (TTYPE (tree->left->left))))
+ return tree;
return decorateType (newNode (GETHBIT, tree->left->left, NULL));
(getSize (TTYPE (root->left->left)) * 8 - 1))
goto tryNext0;
+ /* make sure the port supports RLC */
+ if (port->hasExtBitOp
+ && !port->hasExtBitOp(RLC, getSize (TTYPE (root->left->left))))
+ return root;
+
/* whew got the first case : create the AST */
return newNode (RLC, root->left->left, NULL);
}
(getSize (TTYPE (root->left->left)) * 8 - 1))
goto tryNext1;
+ /* make sure the port supports RLC */
+ if (port->hasExtBitOp
+ && !port->hasExtBitOp(RLC, getSize (TTYPE (root->left->left))))
+ return root;
+
/* whew got the first case : create the AST */
return newNode (RLC, root->left->left, NULL);
(getSize (TTYPE (root->left->left)) * 8 - 1))
goto tryNext2;
+ /* make sure the port supports RRC */
+ if (port->hasExtBitOp
+ && !port->hasExtBitOp(RRC, getSize (TTYPE (root->left->left))))
+ return root;
+
/* whew got the first case : create the AST */
return newNode (RRC, root->left->left, NULL);
(getSize (TTYPE (root->left->left)) * 8 - 1))
return root;
+ /* make sure the port supports RRC */
+ if (port->hasExtBitOp
+ && !port->hasExtBitOp(RRC, getSize (TTYPE (root->left->left))))
+ return root;
+
/* whew got the first case : create the AST */
return newNode (RRC, root->left->left, NULL);
return root;
}
+/*-----------------------------------------------------------------*/
+/* optimizeSWAP :- optimize for nibble/byte/word swaps */
+/*-----------------------------------------------------------------*/
+ast *
+optimizeSWAP (ast * root)
+{
+ /* will look for trees of the form
+ (?expr << 4) | (?expr >> 4) or
+ (?expr >> 4) | (?expr << 4) will make that
+ into a SWAP : operation ..
+ note : by 4 I mean (number of bits required to hold the
+ variable /2 ) */
+ /* if the root operations is not a | operation the not */
+ if (!IS_BITOR (root))
+ return root;
+
+ /* (?expr << 4) | (?expr >> 4) */
+ if ((IS_LEFT_OP (root->left) && IS_RIGHT_OP (root->right))
+ || (IS_RIGHT_OP (root->left) && IS_LEFT_OP (root->right)))
+ {
+
+ if (!SPEC_USIGN (TETYPE (root->left->left)))
+ return root;
+
+ if (!IS_AST_LIT_VALUE (root->left->right) ||
+ !IS_AST_LIT_VALUE (root->right->right))
+ return root;
+
+ /* make sure it is the same expression */
+ if (!isAstEqual (root->left->left,
+ root->right->left))
+ return root;
+
+ if (AST_LIT_VALUE (root->left->right) !=
+ (getSize (TTYPE (root->left->left)) * 4))
+ return root;
+
+ if (AST_LIT_VALUE (root->right->right) !=
+ (getSize (TTYPE (root->left->left)) * 4))
+ return root;
+
+ /* make sure the port supports SWAP */
+ if (port->hasExtBitOp
+ && !port->hasExtBitOp(SWAP, getSize (TTYPE (root->left->left))))
+ return root;
+
+ /* found it : create the AST */
+ return newNode (SWAP, root->left->left, NULL);
+ }
+
+
+ /* not found return root */
+ return root;
+}
+
/*-----------------------------------------------------------------*/
/* optimizeCompare - otimizes compares for bit variables */
/*-----------------------------------------------------------------*/
fprintf(outfile,")\n");
ast_print(tree->left,outfile,indent+2);
return ;
+ case SWAP:
+ fprintf(outfile,"SWAP (%p) type (",tree);
+ printTypeChain(tree->ftype,outfile);
+ fprintf(outfile,")\n");
+ ast_print(tree->left,outfile,indent+2);
+ return ;
case GETHBIT:
fprintf(outfile,"GETHBIT (%p) type (",tree);
printTypeChain(tree->ftype,outfile);
fprintf(outfile,"FOR LOOP BODY \n");
ast_print(tree->left,outfile,indent+2);
return ;
+ case CRITICAL:
+ fprintf(outfile,"CRITICAL (%p) \n",tree);
+ ast_print(tree->left,outfile,indent+2);
default:
return ;
}