// // SearchCSEList will search the common expression table for an entry // that matches the node passed and return a pointer to it. // static CSE *SearchCSEList(ENODE *node) { int cnt; for (cnt = 0; cnt < csendx; cnt++) { if( equalnode(node,CSETable[cnt].exp) ) return &CSETable[cnt]; } return (CSE *)NULL; }
void GenerateCheck(Statement * stmt) { AMODE *ap1, *ap2, *ap3, *ap4; ENODE *node, *ep; int size; initstack(); ep = node = stmt->exp; if (ep->p[0]->nodetype==en_lt && ep->p[1]->nodetype==en_ge && equalnode(ep->p[0]->p[0],ep->p[1]->p[0])) { ep->nodetype = en_chk; if (ep->p[0]) ep->p[2] = ep->p[0]->p[1]; else ep->p[2] = NULL; ep->p[1] = ep->p[1]->p[1]; ep->p[0] = ep->p[0]->p[0]; } else if (ep->p[0]->nodetype==en_ge && ep->p[1]->nodetype==en_lt && equalnode(ep->p[0]->p[0],ep->p[1]->p[0])) { ep->nodetype = en_chk; if (ep->p[1]) ep->p[2] = ep->p[1]->p[1]; else ep->p[2] = NULL; ep->p[1] = ep->p[0]->p[1]; ep->p[0] = ep->p[0]->p[0]; } if (ep->nodetype != en_chk) { error(ERR_CHECK); return; } size = GetNaturalSize(node); ap1 = GenerateExpression(node->p[0],F_REG,size); ap2 = GenerateExpression(node->p[1],F_REG|F_IMM0,size); ap3 = GenerateExpression(node->p[2],F_REG|F_IMMED,size); if (ap2->mode == am_immed) { ap2->mode = am_reg; ap2->preg = 0; } GenerateTriadic(op_chk,0,ap1,ap2,ap3); ReleaseTempRegister(ap3); ReleaseTempRegister(ap2); ReleaseTempRegister(ap1); }
/* * SearchCSEList will search the common expression table for an entry * that matches the node passed and return a pointer to it. */ static CSE *SearchCSEList(ENODE *node) { CSE *csp; csp = olist; while( csp != (CSE *)NULL ) { if( equalnode(node,csp->exp) ) return csp; csp = csp->next; } return (CSE *)NULL; }
/* * voidauto will void an auto dereference node which points to * the same auto constant as node. */ CSE *voidauto(ENODE *node) { CSE *csp; csp = (CSE *)olist; while( csp != NULL ) { if( IsLValue(csp->exp) && equalnode(node,csp->exp->p[0]) ) { if( csp->voidf ) return (CSE *)NULL; csp->voidf = 1; return csp; } csp = csp->next; } return (CSE *)NULL; }
// voidauto2 searches the entire CSE list for auto dereferenced node which // point to the passed node. There might be more than one LValue that matches. // voidauto will void an auto dereference node which points to // the same auto constant as node. // int voidauto2(ENODE *node) { int uses; bool voided; int cnt; uses = 0; voided = false; for (cnt = 0; cnt < csendx; cnt++) { if( IsLValue(CSETable[cnt].exp) && equalnode(node,CSETable[cnt].exp->p[0]) ) { CSETable[cnt].voidf = 1; voided = true; uses += CSETable[cnt].uses; } } return voided ? uses : -1; }
// voidauto2 searches the entire CSE list for auto dereferenced node which // point to the passed node. There might be more than one LValue that matches. // voidauto will void an auto dereference node which points to // the same auto constant as node. // int voidauto2(ENODE *node) { CSE *csp; int uses; int voided; uses = 0; voided = 0; csp = (CSE *)olist; while( csp != NULL ) { if( IsLValue(csp->exp) && equalnode(node,csp->exp->p[0]) ) { csp->voidf = 1; voided = 1; uses += csp->uses; } csp = csp->next; } return voided ? uses : -1; }
/* * equalnode will return 1 if the expressions pointed to by * node1 and node2 are equivalent. */ int equalnode(ENODE *node1, ENODE *node2) { if (node1 == NULL || node2 == NULL) return FALSE; if (node1->nodetype != node2->nodetype) return FALSE; switch (node1->nodetype) { case en_fcon: case en_autofcon: return (node1->f == node2->f); case en_icon: case en_labcon: case en_autocon: return (node1->i == node2->i); case en_nacon: return (!strcmp(node1->sp, node2->sp)); case en_cnacon: return (!strcmp(node1->sp, node2->sp)); default: if( IsLValue(node1) && equalnode(node1->p[0], node2->p[0]) ) return TRUE; return FALSE; } }
// // equalnode will return 1 if the expressions pointed to by // node1 and node2 are equivalent. // int equalnode(ENODE *node1, ENODE *node2) { if (node1 == NULL || node2 == NULL) { return FALSE; } if (node1->nodetype != node2->nodetype) { return FALSE; } switch (node1->nodetype) { case en_fcon: return (Float128::IsEqual(&node1->f128,&node2->f128)); // return (node1->f == node2->f); case en_regvar: case en_fpregvar: case en_icon: case en_labcon: case en_classcon: // Check type ? case en_autocon: case en_autovcon: case en_autofcon: { return (node1->i == node2->i); } case en_nacon:{ return (node1->sp->compare(*node2->sp)==0); } case en_cnacon: return (node1->sp->compare(*node2->sp)==0); default: if( IsLValue(node1) && equalnode(node1->p[0], node2->p[0]) ) { // if( equalnode(node1->p[0], node2->p[0]) ) return TRUE; } return FALSE; } }