iocc.c 4.7 KB

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