instruct.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef NORCSID
  2. static char rcsid[]= "$Header$";
  3. #endif
  4. #include "param.h"
  5. #include "instruct.h"
  6. #include "pseudo.h"
  7. #include "varinfo.h"
  8. #include "set.h"
  9. #include "expr.h"
  10. #include "iocc.h"
  11. #include <cgg_cg.h>
  12. #include "extern.h"
  13. extern int niops;
  14. extern iocc_t iops[];
  15. extern inproc;
  16. extern set_t l_sets[];
  17. extern inst_t l_instances[];
  18. extern expr_t subreg_expr(),regno_expr();
  19. struct varinfo * setcoco(n) {
  20. struct varinfo *vi;
  21. NEW(vi,struct varinfo);
  22. vi->vi_next = VI_NULL;
  23. vi->vi_int[0] = INSSETCC;
  24. vi->vi_int[1] = n;
  25. return(vi);
  26. }
  27. struct varinfo * generase(n) {
  28. struct varinfo *vi;
  29. NEW(vi,struct varinfo);
  30. vi->vi_next = VI_NULL;
  31. vi->vi_int[0] = INSERASE;
  32. vi->vi_int[1] = n;
  33. return(vi);
  34. }
  35. onlyreg(argno) {
  36. register bitno;
  37. register short *sp;
  38. sp = l_sets[tokpatset[argno-1]].set_val;
  39. for(bitno=nregs;bitno<nregs+ntokens;bitno++)
  40. if (BIT(sp,bitno))
  41. return(0);
  42. return(1);
  43. }
  44. makescratch(argno) {
  45. set_t s;
  46. if (tokpatro[argno-1])
  47. error("Instruction destroys %%%d, not allowed here",argno);
  48. s = l_sets[tokpatset[argno-1]];
  49. BIC(s.set_val,0);
  50. tokpatset[argno-1] = setlookup(s);
  51. }
  52. struct varinfo *gen_inst(ident,star) char *ident; {
  53. register struct varinfo *vi,*retval,*eravi;
  54. register instr_p ip;
  55. register struct operand *op;
  56. register i;
  57. register inst_p insta;
  58. if (star && !inproc)
  59. error("Variable instruction only allowed inside proc");
  60. for (ip=l_instr;ip<l_instr+ninstr;ip++) {
  61. if(strcmp(ident,ip->i_name))
  62. continue;
  63. if (ip->i_nops!=niops)
  64. continue;
  65. for(i=0,op=ip->i_oplist;i<niops;i++,op=op->o_next) {
  66. if (!subset(iops[i].in_set,l_sets[op->o_setno].set_val,SETSIZE))
  67. goto cont;
  68. }
  69. goto found; /* oh well, one more won't hurt */
  70. cont:;
  71. }
  72. error("Such an \"%s\" does not exist",ident);
  73. return(0);
  74. found:
  75. NEW(vi,struct varinfo);
  76. vi->vi_int[0] = ip-l_instr;
  77. vi->vi_int[1] = star;
  78. vi->vi_next=0;
  79. retval = vi;
  80. for(i=0;i<niops;i++) {
  81. NEW(vi->vi_vi,struct varinfo);
  82. vi=vi->vi_vi;
  83. vi->vi_int[0] = iops[i].in_index;
  84. }
  85. vi->vi_vi = 0;
  86. vi = retval;
  87. for(i=0,op=ip->i_oplist;i<niops;i++,op=op->o_next) {
  88. if(op->o_adorn&AD_CC) {
  89. vi->vi_next = setcoco(iops[i].in_index);
  90. vi=vi->vi_next;
  91. }
  92. switch(op->o_adorn&AD_RWMASK) {
  93. default:
  94. /* Nothing possible to do */
  95. break;
  96. case AD_RO:
  97. /* It might be possible to do something
  98. * here but not now.
  99. */
  100. break;
  101. case AD_RW:
  102. case AD_WO:
  103. /* Treated the same for now */
  104. insta = &l_instances[iops[i].in_index];
  105. switch(insta->in_which) {
  106. case IN_COPY:
  107. if(insta->in_info[1]==0 && !onlyreg(insta->in_info[0]))
  108. break;
  109. makescratch(insta->in_info[0]);
  110. vi->vi_next = generase(
  111. ex_lookup(
  112. EX_SUBREG,insta->in_info[0],
  113. insta->in_info[1]
  114. )
  115. );
  116. vi = vi->vi_next;
  117. break;
  118. case IN_MEMB:
  119. vi->vi_next = generase(
  120. ex_lookup(
  121. EX_TOKFIELD,insta->in_info[0],
  122. insta->in_info[1]
  123. )
  124. );
  125. vi=vi->vi_next;
  126. break;
  127. case IN_RIDENT:
  128. vi->vi_next = generase(
  129. ex_lookup(
  130. EX_REG,insta->in_info[0],0
  131. )
  132. );
  133. vi = vi->vi_next;
  134. break;
  135. case IN_ALLOC:
  136. vi->vi_next = generase(
  137. ex_lookup(
  138. EX_ALLREG,insta->in_info[0]+1,
  139. insta->in_info[1]
  140. )
  141. );
  142. vi = vi->vi_next;
  143. break;
  144. case IN_S_DESCR:
  145. case IN_D_DESCR:
  146. vi->vi_next = generase(
  147. ex_lookup(
  148. EX_REGVAR,insta->in_info[1],0
  149. )
  150. );
  151. vi = vi->vi_next;
  152. break;
  153. }
  154. break;
  155. }
  156. }
  157. for (eravi=ip->i_erases;eravi != VI_NULL;eravi=eravi->vi_next) {
  158. if (eravi->vi_int[0] < 0)
  159. vi->vi_next = setcoco(0);
  160. else
  161. vi->vi_next = generase(eravi->vi_int[0]);
  162. vi=vi->vi_next;
  163. }
  164. return(retval);
  165. }