iocc.c 4.7 KB

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