instruct.c 4.1 KB

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