1: #include "defs"
   2: 
   3: offsets(s)
   4: register ptr s;
   5: {
   6: register ptr p, q;
   7: ptr t;
   8: ptr prevp;
   9: int n;
  10: int size, align, mask, nelt;
  11: double rshift;
  12: 
  13: s->stralign = 1;
  14: s->strsize = 0;
  15: s->basetypes = 0;
  16: prevp = 0;
  17: rshift = 0;
  18: 
  19: for(p = s->strdesc ; p ; p = p->nextp)
  20:     {
  21:     q = p->datap;
  22:     if(q->vclass != 0)
  23:         dclerr("attempt to give storage class to mos",
  24:             q->namep);
  25:     else  q->vclass = CLMOS;
  26:     if(q->vtype == TYUNDEFINED)
  27:         impldecl(q);
  28: 
  29:     sizalign(q, &size, &align, &mask);
  30:     s->strsize = evenoff(s->strsize, align);
  31:     q->voffset = mkint(s->strsize);
  32:     /* sloppy formula */
  33:     nelt = 1;
  34:     if(t = q->vdim)
  35:         for(t = t->datap ; t ; t = t->nextp)
  36:         {
  37:         if(t->upperb == 0) continue;
  38:         n = conval(t->upperb);
  39:         if(t->lowerb)
  40:             n -= conval(t->lowerb)-1;
  41:         nelt *= n;
  42:         }
  43:     if(q->vtype==TYFIELD && q->vdim==0 &&
  44:          (n=conval(q->vtypep->frange))*rshift<=fieldmax && rshift>0)
  45:         {
  46:         prevp->vtypep->fanymore = 1;
  47:         q->vtypep->frshift = mkint( (int) rshift );
  48:         rshift *= n;
  49:         cfree(q->voffset);
  50:         q->voffset = mkint(s->strsize - tailor.ftnsize[FTNINT]);
  51:         }
  52:     else    {
  53:         if(q->vdim!=0 && q->vtype==TYFIELD)
  54:             q->vtype = TYINT;
  55:         rshift = (q->vtype==TYFIELD ? n : 0);
  56:         s->strsize +=  nelt * evenoff(size,align);
  57:         s->stralign = lcm(s->stralign, align);
  58:         s->basetypes |= mask;
  59:         }
  60:     prevp = q;
  61:     }
  62: }
  63: 
  64: 
  65: lcm(a,b)
  66: int a,b;
  67: {
  68: int ab, c;
  69: 
  70: if( (ab = a*b) == 0) return(0);
  71: 
  72: while(b)
  73:     {
  74:     c = a%b;
  75:     a = b;
  76:     b = c;
  77:     }
  78: 
  79: return(ab/a);
  80: }
  81: 
  82: 
  83: 
  84: 
  85: 
  86: sizalign(p, s, a, m)
  87: register ptr p;
  88: int *s;
  89: int *a;
  90: int *m;
  91: {
  92: register int k, t;
  93: 
  94: if(p->tag == TERROR)
  95:     return;
  96: if(p->tag!=TNAME && p->tag!=TTEMP && p->tag!=TFTNBLOCK)
  97:     badtag("sizalign", p->tag);
  98: switch(t = p->vtype)
  99:     {
 100:     case TYFIELD:
 101:     case TYINT:
 102:     case TYREAL:
 103:     case TYLREAL:
 104:     case TYCOMPLEX:
 105:     case TYLOG:
 106:         k = eflftn[t];
 107:         *s = tailor.ftnsize[k];
 108:         *a = tailor.ftnalign[k];
 109:         *m = ftnmask[k];
 110:         return;
 111: 
 112:     case TYLCOMPLEX:
 113:         if(tailor.lngcxtype)
 114:             {
 115:             k = FTNDCOMPLEX;
 116:             *s = tailor.ftnsize[FTNDCOMPLEX];
 117:             }
 118:         else
 119:             {
 120:             k = FTNDOUBLE;
 121:             *s = 2*tailor.ftnsize[k];
 122:             }
 123:         *a = tailor.ftnalign[k];
 124:         *m = ftnmask[k];
 125:         return;
 126: 
 127:     case TYSTRUCT:
 128:         *s = p->vtypep->strsize;
 129:         *a = p->vtypep->stralign;
 130:         *m = p->vtypep->basetypes;
 131:         return;
 132: 
 133:     case TYCHAR:
 134:         *s = tailor.ftnsize[FTNINT] *
 135:             ceil(conval(p->vtypep), tailor.ftnchwd);
 136:         *a = tailor.ftnalign[FTNINT];
 137:         *m = ftnmask[FTNINT];
 138:         return;
 139: 
 140:     case TYSUBR:
 141:         *s = 1;
 142:         *a = 1;
 143:         *m = 1;
 144:         dclerr("subroutine name as variable", p->sthead->namep);
 145:         return;
 146: 
 147:     default:
 148:         fatal1("sizalign: invalid type %d", t);
 149:     }
 150: }
 151: 
 152: 
 153: 
 154: evenoff(a,b)    /* round a up to a multiple of b */
 155: int a,b;
 156: {
 157: return(b * ceil(a,b));
 158: }
 159: 
 160: 
 161: ceil(a,b)
 162: int a,b;
 163: {
 164: return( (a+b-1)/b );
 165: }
 166: 
 167: 
 168: 
 169: 
 170: ptr esizeof(type, typep, dim)
 171: register int type;
 172: register ptr typep;
 173: ptr dim;
 174: {
 175: register int k;
 176: 
 177: switch(type)
 178:     {
 179:     case TYFIELD:
 180:     case TYINT:
 181:     case TYREAL:
 182:     case TYLREAL:
 183:     case TYCOMPLEX:
 184:     case TYLCOMPLEX:
 185:     case TYLOG:
 186:         k = tailor.ftnsize[ eflftn[type] ];
 187:         break;
 188: 
 189:     case TYSTRUCT:
 190:         k = typep->strsize;
 191:         break;
 192: 
 193:     case TYCHAR:
 194:         k = tailor.ftnsize[FTNINT] * ceil(conval(typep), tailor.ftnchwd);
 195:         break;
 196: 
 197:     default:
 198:         exprerr("invalid sizeof", "");
 199:         k = 0;
 200:     }
 201: /* debug version.  should multiply by dimension */
 202: return( mkint(k) );
 203: }
 204: 
 205: 
 206: 
 207: ptr elenof(type, typep, dim)
 208: register int type;
 209: register ptr typep;
 210: ptr dim;
 211: {
 212: if(type == TYCHAR)
 213:     return( mkint( conval(typep) ) );
 214: exprerr("invalid lengthof", "");
 215: return( mkint(0) );
 216: /* debug version.  should multiply by dimension */
 217: }

Defined functions

ceil defined in line 161; used 5 times
elenof defined in line 207; never used
esizeof defined in line 170; never used
evenoff defined in line 154; used 2 times
lcm defined in line 65; used 1 times
  • in line 57
offsets defined in line 3; used 1 times
sizalign defined in line 86; used 4 times
Last modified: 1982-06-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 859
Valid CSS Valid XHTML 1.0 Strict