move.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Id$";
  3. #endif
  4. #include "assert.h"
  5. #include "param.h"
  6. #include "tables.h"
  7. #include "types.h"
  8. #include <cgg_cg.h>
  9. #include "data.h"
  10. #include "result.h"
  11. #include "extern.h"
  12. /*
  13. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  14. * See the copyright notice in the ACK home directory, in the file "Copyright".
  15. *
  16. * Author: Hans van Staveren
  17. */
  18. move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
  19. register move_p mp;
  20. unsigned t;
  21. register struct reginfo *rp;
  22. register byte *tdpb;
  23. int i;
  24. unsigned codegen();
  25. if (eqtoken(tp1,tp2))
  26. return(0);
  27. if (tp2->t_token == -1) {
  28. if (tp1->t_token == -1) {
  29. if (eqtoken(&machregs[tp1->t_att[0].ar].r_contents,
  30. &machregs[tp2->t_att[0].ar].r_contents) &&
  31. machregs[tp1->t_att[0].ar].r_contents.t_token!=0)
  32. return(0);
  33. } else {
  34. if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
  35. return(0);
  36. }
  37. erasereg(tp2->t_att[0].ar);
  38. } else if (tp1->t_token == -1) {
  39. if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
  40. return(0);
  41. }
  42. /*
  43. * If we arrive here the move must really be executed
  44. */
  45. for (mp=moves;mp->m_set1>=0;mp++) {
  46. if (!match(tp1,&machsets[mp->m_set1],mp->m_expr1))
  47. continue;
  48. if (match(tp2,&machsets[mp->m_set2],mp->m_expr2))
  49. break;
  50. /*
  51. * Correct move rule is found
  52. */
  53. }
  54. assert(mp->m_set1>=0);
  55. /*
  56. * To get correct interpretation of things like %[1]
  57. * in move code we stack tp2 and tp1. This little trick
  58. * saves a lot of testing in other places.
  59. */
  60. fakestack[stackheight] = *tp2;
  61. fakestack[stackheight+1] = *tp1;
  62. stackheight += 2;
  63. tokpatlen += 2;
  64. t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0);
  65. tokpatlen -= 2;
  66. stackheight -= 2;
  67. if (tp2->t_token == -1) {
  68. rp = &machregs[tp2->t_att[0].ar];
  69. if (tp1->t_token == -1) {
  70. rp->r_contents =
  71. machregs[tp1->t_att[0].ar].r_contents ;
  72. }
  73. else rp->r_contents = *tp1;
  74. if (rp->r_contents.t_token > 0) {
  75. tdpb = &(tokens[rp->r_contents.t_token].t_type[0]);
  76. for (i=0;i<TOKENSIZE;i++)
  77. if (*tdpb++ == EV_REG &&
  78. clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
  79. rp->r_contents.t_token = 0;
  80. for (i = 0; i < TOKENSIZE; i++)
  81. rp->r_contents.t_att[i].aw = 0;
  82. break;
  83. }
  84. }
  85. }
  86. else if (tp1->t_token == -1)
  87. machregs[tp1->t_att[0].ar].r_contents = *tp2;
  88. return(t);
  89. }
  90. #define cocoreg machregs[0].r_contents
  91. setcc(tp) token_p tp; {
  92. cocoreg = *tp;
  93. }
  94. test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
  95. register test_p mp;
  96. unsigned t;
  97. unsigned codegen();
  98. if (cocoreg.t_token!=0) {
  99. if (eqtoken(tp,&cocoreg))
  100. return(0);
  101. if (tp->t_token == -1) {
  102. if (eqtoken(&machregs[tp->t_att[0].ar].r_contents,&cocoreg))
  103. return(0);
  104. }
  105. }
  106. /*
  107. * If we arrive here the test must really be executed
  108. */
  109. for (mp=tests;mp->t_set>=0;mp++) {
  110. if (match(tp,&machsets[mp->t_set],mp->t_expr))
  111. break;
  112. /*
  113. * Correct move rule is found
  114. */
  115. }
  116. assert(mp->t_set>=0);
  117. /*
  118. * To get correct interpretation of things like %[1]
  119. * in test code we stack tp. This little trick
  120. * saves a lot of testing in other places.
  121. */
  122. fakestack[stackheight] = *tp;
  123. stackheight++;
  124. tokpatlen++;
  125. t = codegen(&coderules[mp->t_cindex],ply,toplevel,maxcost,0);
  126. tokpatlen--;
  127. stackheight--;
  128. return(t);
  129. }