1 #ifndef lint 2 static char *sccsid ="simul.c (CWI) 1.1 85/03/01"; 3 #endif 4 #include "ideal.h" 5 6 7 DEPPTR depadd(dlistone, coeffone, dlisttwo, coefftwo) 8 DEPPTR dlistone; 9 float coeffone; 10 DEPPTR dlisttwo; 11 float coefftwo; 12 { 13 /* produce a dependency list = coeffone*dlistone + coefftwo*dlisttwo */ 14 register DEPPTR onewalk, twowalk, newhead, newwalk, prevnew; 15 DEPNODE nuhead; 16 prevnew = &nuhead; 17 prevnew->next = NULL; 18 onewalk = dlistone; 19 twowalk = dlisttwo; 20 while ((onewalk != NULL) || (twowalk != NULL)) { 21 if (onewalk != NULL) 22 if (twowalk != NULL) 23 if (onewalk->var > twowalk ->var) { 24 newwalk = depgen ( 25 onewalk->var, 26 coeffone*onewalk->coeff 27 ); 28 onewalk = onewalk->next; 29 } 30 else 31 if (onewalk->var == twowalk->var) { 32 newwalk = depgen ( 33 onewalk->var, 34 coeffone*onewalk->coeff 35 + coefftwo*twowalk->coeff 36 ); 37 onewalk = onewalk->next; 38 twowalk = twowalk->next; 39 } 40 else { 41 newwalk = depgen ( 42 twowalk->var, 43 coefftwo*twowalk->coeff 44 ); 45 twowalk = twowalk->next; 46 } 47 else { 48 newwalk = depgen ( 49 onewalk->var, 50 coeffone*onewalk->coeff 51 ); 52 onewalk = onewalk->next; 53 } 54 else { 55 newwalk = depgen ( 56 twowalk->var, 57 coefftwo*twowalk->coeff 58 ); 59 twowalk = twowalk->next; 60 } 61 if (fabs(newwalk->coeff) > EPSILON) { 62 prevnew->next = newwalk; 63 prevnew = newwalk; 64 } else 65 depfree (newwalk); 66 } 67 newhead = nuhead.next; 68 if (newhead != NULL) { 69 if (dbg) { 70 depprint (newhead); 71 fprintf (stderr, "\n"); 72 } 73 return(newhead); 74 } 75 else { 76 dprintf "empty dep rep\n"); 77 return (depgen ((VARPTR) NULL, 0.0)); 78 } 79 } 80 81 DEPPTR depsubst(depinto, depfrom, depwho) 82 /* substitutes depfrom for depwho in depinto 83 /* WARNING: if depinto actually contains depfrom, 84 /* depinto is replaced */ 85 DEPPTR depinto, 86 depfrom; 87 VARPTR depwho; 88 { 89 DEPPTR intowalker, intoparent, temp; 90 for (intowalker = depinto; 91 intowalker != NULL; 92 intowalker = intowalker->next) 93 if (intowalker->var == depwho) 94 break; 95 else 96 intoparent = intowalker; 97 if (intowalker == NULL) 98 return(depinto); 99 if (intowalker == depinto) 100 depinto = depinto->next; 101 else 102 intoparent->next = intowalker->next; 103 dprintf "Variable substitution proceeding\n"); 104 temp = depadd(depinto, 1.0, depfrom, intowalker->coeff); 105 depfree (depinto); 106 tryfree(intowalker); 107 depinto = temp; 108 return (temp); 109 } 110