- /* will look for trees of the form
- (?expr << 1) | (?expr >> 7) or
- (?expr >> 7) | (?expr << 1) will make that
- into a RLC : operation ..
- Will also look for
- (?expr >> 1) | (?expr << 7) or
- (?expr << 7) | (?expr >> 1) will make that
- into a RRC operation
- note : by 7 I mean (number of bits required to hold the
- variable -1 ) */
- /* if the root operations is not a | operation the not */
- if (!IS_BITOR(root))
- return root ;
-
- /* I have to think of a better way to match patterns this sucks */
- /* that aside let start looking for the first case : I use a the
- negative check a lot to improve the efficiency */
- /* (?expr << 1) | (?expr >> 7) */
- if (IS_LEFT_OP(root->left) &&
- IS_RIGHT_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))
- goto tryNext0;
-
- /* make sure it is the same expression */
- if (!isAstEqual(root->left->left,
- root->right->left))
- goto tryNext0;
-
- if (AST_LIT_VALUE(root->left->right) != 1 )
- goto tryNext0 ;
-
- if (AST_LIT_VALUE(root->right->right) !=
- (getSize(TTYPE(root->left->left))*8 - 1))
- goto tryNext0 ;
-
- /* whew got the first case : create the AST */
- return newNode(RLC,root->left->left,NULL);
- }
-
- tryNext0:
- /* check for second case */
- /* (?expr >> 7) | (?expr << 1) */
- if (IS_LEFT_OP(root->right) &&
- IS_RIGHT_OP(root->left) ) {
-
- if (!SPEC_USIGN(TETYPE(root->left->left)))
- return root;
-
- if (!IS_AST_LIT_VALUE(root->left->right) ||
- !IS_AST_LIT_VALUE(root->right->right))
- goto tryNext1 ;
-
- /* make sure it is the same symbol */
- if (!isAstEqual(root->left->left,
- root->right->left))
- goto tryNext1 ;
-
- if (AST_LIT_VALUE(root->right->right) != 1 )
- goto tryNext1 ;
-
- if (AST_LIT_VALUE(root->left->right) !=
- (getSize(TTYPE(root->left->left))*8 - 1))
- goto tryNext1 ;
-
- /* whew got the first case : create the AST */
- return newNode(RLC,root->left->left,NULL);
-
- }
-
- tryNext1:
- /* third case for RRC */
- /* (?symbol >> 1) | (?symbol << 7) */
- if (IS_LEFT_OP(root->right) &&
- IS_RIGHT_OP(root->left) ) {
-
- if (!SPEC_USIGN(TETYPE(root->left->left)))
- return root;
-
- if (!IS_AST_LIT_VALUE(root->left->right) ||
- !IS_AST_LIT_VALUE(root->right->right))
- goto tryNext2;
-
- /* make sure it is the same symbol */
- if (!isAstEqual(root->left->left,
- root->right->left))
- goto tryNext2;
-
- if (AST_LIT_VALUE(root->left->right) != 1 )
- goto tryNext2;
-
- if (AST_LIT_VALUE(root->right->right) !=
- (getSize(TTYPE(root->left->left))*8 - 1))
- goto tryNext2;
-
- /* whew got the first case : create the AST */
- return newNode(RRC,root->left->left,NULL);
-
- }
- tryNext2:
- /* fourth and last case for now */
- /* (?symbol << 7) | (?symbol >> 1) */
- if (IS_RIGHT_OP(root->right) &&
- IS_LEFT_OP(root->left) ) {
-
- 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 symbol */
- if (!isAstEqual(root->left->left,
- root->right->left))
- return root;
-
- if (AST_LIT_VALUE(root->right->right) != 1 )
- return root ;
-
- if (AST_LIT_VALUE(root->left->right) !=
- (getSize(TTYPE(root->left->left))*8 - 1))
- return root ;
-
- /* whew got the first case : create the AST */
- return newNode(RRC,root->left->left,NULL);
-
- }
-
- /* not found return root */