iocc.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. #ifndef NORCSID
  6. static char rcsid[]= "$Id$";
  7. #endif
  8. #include "assert.h"
  9. #include "param.h"
  10. #include "set.h"
  11. #include "expr.h"
  12. #include "lookup.h"
  13. #include "token.h"
  14. #include "property.h"
  15. #include "iocc.h"
  16. #include <cgg_cg.h>
  17. #include "regvar.h"
  18. #include "extern.h"
  19. extern set_t l_sets[];
  20. int narexpr;
  21. expr_t arexp[MAXATT];
  22. expr_t iextoaddr();
  23. iocc_t subr_iocc(tokarg,subreg) {
  24. inst_t insta;
  25. iocc_t result;
  26. register i;
  27. insta.in_which = IN_COPY;
  28. insta.in_info[0] = tokarg;
  29. insta.in_info[1] = subreg;
  30. result.in_index = instalookup(insta,2);
  31. if (tokarg < 1) tokarg = 1;
  32. if (subreg==0)
  33. for (i=0;i<SETSIZE;i++)
  34. result.in_set[i] = l_sets[tokpatset[tokarg-1]].set_val[i];
  35. else {
  36. for (i=0;i<SETSIZE;i++)
  37. result.in_set[i] = 0;
  38. subregset(l_sets[tokpatset[tokarg-1]].set_val,subreg,result.in_set);
  39. }
  40. return(result);
  41. }
  42. iocc_t tokm_iocc(tokarg,ident) char *ident; {
  43. iocc_t result;
  44. inst_t insta;
  45. register i;
  46. char app[100];
  47. int dummy;
  48. for(i=0;i<SETSIZE;i++)
  49. result.in_set[i] = 0;
  50. insta.in_which = IN_MEMB;
  51. insta.in_info[0] = tokarg;
  52. if (tokarg < 1) tokarg = 1;
  53. sprintf(app,"%%%d.%s",tokarg,ident);
  54. insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set,
  55. app,TYPREG,&dummy);
  56. result.in_index = instalookup(insta,2);
  57. return(result);
  58. }
  59. iocc_t percident_iocc(ident) char *ident; {
  60. iocc_t result;
  61. inst_t insta;
  62. register i;
  63. char app[100];
  64. int dummy;
  65. for(i=0;i<SETSIZE;i++)
  66. result.in_set[i] = 0;
  67. insta.in_which = IN_MEMB;
  68. insta.in_info[0] = 0;
  69. sprintf(app,"%%%s",ident);
  70. insta.in_info[1] = 1+membset(cursetno,ident,result.in_set,
  71. app,TYPREG,&dummy);
  72. result.in_index = instalookup(insta,2);
  73. return(result);
  74. }
  75. iocc_t ident_iocc(ident) char *ident; {
  76. iocc_t result;
  77. inst_t insta;
  78. register i;
  79. register symbol *sy_p;
  80. for(i=0;i<SETSIZE;i++)
  81. result.in_set[i] = 0;
  82. insta.in_which = IN_RIDENT;
  83. sy_p = lookup(ident,symreg,mustexist);
  84. insta.in_info[0] = sy_p->sy_value.syv_regno;
  85. result.in_index = instalookup(insta,1);
  86. BIS(result.in_set,sy_p->sy_value.syv_regno);
  87. return(result);
  88. }
  89. iocc_t all_iocc(all_no,subreg) {
  90. iocc_t result;
  91. inst_t insta;
  92. register i;
  93. set_t localset;
  94. register short *sp;
  95. sp = l_props[allreg[all_no]].pr_regset;
  96. for (i=0;i<SETSIZE;i++)
  97. localset.set_val[i] = i<SZOFSET(MAXREGS) ? sp[i] : 0;
  98. for(i=0;i<SETSIZE;i++)
  99. result.in_set[i] = 0;
  100. insta.in_which = IN_ALLOC;
  101. insta.in_info[0] = all_no;
  102. insta.in_info[1] = subreg;
  103. subregset(localset.set_val,subreg,result.in_set);
  104. result.in_index = instalookup(insta,2);
  105. return(result);
  106. }
  107. iocc_t descr_iocc(ident) char *ident; {
  108. iocc_t result;
  109. inst_t insta;
  110. register symbol *sy_p;
  111. register token_p tp;
  112. register i;
  113. int typerr;
  114. for(i=0;i<SETSIZE;i++)
  115. result.in_set[i] = 0;
  116. sy_p = lookup(ident,symtok,mustexist);
  117. tp = l_tokens[sy_p->sy_value.syv_tokno];
  118. BIS(result.in_set,sy_p->sy_value.syv_tokno+nregs);
  119. insta.in_which = IN_DESCR;
  120. if (rvused&SL_REGVAR && strcmp(ident,"LOCAL")==0)
  121. insta.in_which = IN_S_DESCR;
  122. else if (rvused&DL_REGVAR && strcmp(ident,"DLOCAL")==0)
  123. insta.in_which = IN_D_DESCR;
  124. insta.in_info[0] = sy_p->sy_value.syv_tokno;
  125. for (i=0;i<MAXATT;i++) {
  126. if (tp->tk_att[i].ta_type == -3) {
  127. if (narexpr>i)
  128. error("token %s initialized with too many attributes",ident);
  129. break;
  130. }
  131. if (i>= narexpr) {
  132. error("token %s initialized with too few attributes",
  133. ident);
  134. break;
  135. }
  136. typerr = 0;
  137. switch(arexp[i].ex_typ) {
  138. default: assert(0);
  139. case TYPINT:
  140. if (tp->tk_att[i].ta_type != -1)
  141. if (tp->tk_att[i].ta_type == -2)
  142. arexp[i] = iextoaddr(arexp[i]);
  143. else
  144. typerr++;
  145. break;
  146. case TYPBOOL:
  147. typerr++; break;
  148. case TYPADDR:
  149. if (tp->tk_att[i].ta_type != -2)
  150. typerr++;
  151. break;
  152. case TYPREG:
  153. if (tp->tk_att[i].ta_type<0)
  154. typerr++;
  155. else if (!subset(arexp[i].ex_regset,
  156. l_props[tp->tk_att[i].ta_type].pr_regset,
  157. SZOFSET(MAXREGS)))
  158. typerr++;
  159. break;
  160. }
  161. if (typerr)
  162. error("Attribute %s.%s given wrong type of value",
  163. ident,tp->tk_att[i].ta_name);
  164. insta.in_info[i+1] = arexp[i].ex_index;
  165. }
  166. result.in_index = instalookup(insta,i+1);
  167. return(result);
  168. }
  169. /* low level instance package */
  170. int ninstances=1;
  171. inst_t l_instances[MAXINSTANCES];
  172. instalookup(insta,filled) inst_t insta; {
  173. register i,j;
  174. for (j=filled;j<=MAXATT;j++)
  175. insta.in_info[j] = 0;
  176. for (i=0;i<ninstances;i++) {
  177. if (insta.in_which != l_instances[i].in_which)
  178. continue;
  179. for(j=0;j<=MAXATT;j++)
  180. if (insta.in_info[j]!= l_instances[i].in_info[j])
  181. goto cont;
  182. return(i);
  183. cont:;
  184. }
  185. NEXT(ninstances,MAXINSTANCES,"Instances");
  186. l_instances[i] = insta;
  187. return(i);
  188. }