iocc.c 4.7 KB

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