iocc.c 4.1 KB

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