| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include <string.h> |
| 36 |
|
| 37 |
#include "defines.h" |
| 38 |
#include "defs.h" |
| 39 |
|
| 40 |
LOCAL void doentry(struct entrypoint *ep); |
| 41 |
LOCAL void retval(int t); |
| 42 |
LOCAL void epicode(void); |
| 43 |
LOCAL void procode(void); |
| 44 |
LOCAL int nextarg(int); |
| 45 |
LOCAL int nextarg(int); |
| 46 |
LOCAL void dobss(void); |
| 47 |
LOCAL void docommon(void); |
| 48 |
LOCAL void docomleng(void); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
void |
| 54 |
newproc() |
| 55 |
{ |
| 56 |
if(parstate != OUTSIDE) { |
| 57 |
execerr("missing end statement"); |
| 58 |
endproc(); |
| 59 |
} |
| 60 |
|
| 61 |
parstate = INSIDE; |
| 62 |
procclass = CLMAIN; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
void |
| 70 |
endproc() |
| 71 |
{ |
| 72 |
struct labelblock *lp; |
| 73 |
|
| 74 |
if(parstate < INDATA) |
| 75 |
enddcl(); |
| 76 |
if(ctlstack >= ctls) |
| 77 |
err("DO loop or BLOCK IF not closed"); |
| 78 |
for(lp = labeltab ; lp < labtabend ; ++lp) |
| 79 |
if(lp->stateno!=0 && lp->labdefined==NO) |
| 80 |
err1("missing statement number %s", |
| 81 |
convic(lp->stateno) ); |
| 82 |
|
| 83 |
epicode(); |
| 84 |
procode(); |
| 85 |
dobss(); |
| 86 |
prdbginfo(); |
| 87 |
|
| 88 |
putbracket(); |
| 89 |
|
| 90 |
procinit(); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
void |
| 99 |
enddcl() |
| 100 |
{ |
| 101 |
chainp p; |
| 102 |
|
| 103 |
parstate = INEXEC; |
| 104 |
docommon(); |
| 105 |
doequiv(); |
| 106 |
docomleng(); |
| 107 |
for(p = entries ; p ; p = p->entrypoint.nextp) |
| 108 |
doentry(&p->entrypoint); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
void |
| 118 |
startproc(struct extsym *progname, int class) |
| 119 |
{ |
| 120 |
chainp p; |
| 121 |
|
| 122 |
p = ALLOC(entrypoint); |
| 123 |
if(class == CLMAIN) { |
| 124 |
puthead("MAIN__"); |
| 125 |
newentry( mkname(5, "MAIN_") ); |
| 126 |
} |
| 127 |
p->entrypoint.entryname = progname; |
| 128 |
p->entrypoint.entrylabel = newlabel(); |
| 129 |
entries = p; |
| 130 |
|
| 131 |
procclass = class; |
| 132 |
retlabel = newlabel(); |
| 133 |
if (!quietflag) { |
| 134 |
fprintf(diagfile, " %s", |
| 135 |
(class==CLMAIN ? "MAIN" : "BLOCK DATA") ); |
| 136 |
if (progname) |
| 137 |
fprintf(diagfile, " %s", |
| 138 |
nounder(XL, procname = progname->extname)); |
| 139 |
fprintf(diagfile, ":\n"); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
struct extsym * |
| 146 |
newentry(struct bigblock *v) |
| 147 |
{ |
| 148 |
struct extsym *p; |
| 149 |
|
| 150 |
p = mkext( varunder(VL, v->b_name.varname) ); |
| 151 |
|
| 152 |
if (p==NULL || p->extinit || |
| 153 |
!ONEOF(p->extstg, M(STGUNKNOWN)|M(STGEXT))) { |
| 154 |
if(p == 0) |
| 155 |
dclerr("invalid entry name", v); |
| 156 |
else |
| 157 |
dclerr("external name already used", v); |
| 158 |
return(0); |
| 159 |
} |
| 160 |
v->vstg = STGAUTO; |
| 161 |
v->b_name.vprocclass = PTHISPROC; |
| 162 |
v->vclass = CLPROC; |
| 163 |
p->extstg = STGEXT; |
| 164 |
p->extinit = YES; |
| 165 |
return(p); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
void |
| 172 |
entrypt(int class, int type, ftnint length, struct extsym *entry, chainp args) |
| 173 |
{ |
| 174 |
struct bigblock *q; |
| 175 |
chainp p; |
| 176 |
|
| 177 |
if(class != CLENTRY) |
| 178 |
puthead( varstr(XL, procname = entry->extname) ); |
| 179 |
if (!quietflag) { |
| 180 |
if (class == CLENTRY) |
| 181 |
fprintf(diagfile, " entry "); |
| 182 |
fprintf(diagfile, " %s:\n", nounder(XL, entry->extname)); |
| 183 |
} |
| 184 |
q = mkname(VL, nounder(XL,entry->extname) ); |
| 185 |
|
| 186 |
if( (type = lengtype(type, (int) length)) != TYCHAR) |
| 187 |
length = 0; |
| 188 |
|
| 189 |
if(class == CLPROC) { |
| 190 |
procclass = CLPROC; |
| 191 |
proctype = type; |
| 192 |
procleng = length; |
| 193 |
|
| 194 |
retlabel = newlabel(); |
| 195 |
if(type == TYSUBR) |
| 196 |
ret0label = newlabel(); |
| 197 |
} |
| 198 |
|
| 199 |
p = ALLOC(entrypoint); |
| 200 |
entries = hookup(entries, p); |
| 201 |
p->entrypoint.entryname = entry; |
| 202 |
p->entrypoint.arglist = args; |
| 203 |
p->entrypoint.entrylabel = newlabel(); |
| 204 |
p->entrypoint.enamep = q; |
| 205 |
|
| 206 |
if(class == CLENTRY) { |
| 207 |
class = CLPROC; |
| 208 |
if(proctype == TYSUBR) |
| 209 |
type = TYSUBR; |
| 210 |
} |
| 211 |
|
| 212 |
q->vclass = class; |
| 213 |
q->b_name.vprocclass = PTHISPROC; |
| 214 |
settype(q, type, (int) length); |
| 215 |
|
| 216 |
if(parstate >= INDATA) |
| 217 |
doentry(&p->entrypoint); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
int multitypes = 0; |
| 223 |
|
| 224 |
LOCAL void |
| 225 |
epicode() |
| 226 |
{ |
| 227 |
int i; |
| 228 |
|
| 229 |
if(procclass==CLPROC) { |
| 230 |
if(proctype==TYSUBR) { |
| 231 |
putlabel(ret0label); |
| 232 |
if(substars) |
| 233 |
putforce(TYINT, MKICON(0) ); |
| 234 |
putlabel(retlabel); |
| 235 |
goret(TYSUBR); |
| 236 |
} else { |
| 237 |
putlabel(retlabel); |
| 238 |
if(multitypes) { |
| 239 |
typeaddr = autovar(1, TYADDR, NULL); |
| 240 |
putbranch( cpexpr(typeaddr) ); |
| 241 |
for(i = 0; i < NTYPES ; ++i) { |
| 242 |
if(rtvlabel[i] != 0) { |
| 243 |
putlabel(rtvlabel[i]); |
| 244 |
retval(i); |
| 245 |
} |
| 246 |
} |
| 247 |
} else |
| 248 |
retval(proctype); |
| 249 |
} |
| 250 |
} else if(procclass != CLBLOCK) { |
| 251 |
putlabel(retlabel); |
| 252 |
goret(TYSUBR); |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
LOCAL void |
| 260 |
retval(t) |
| 261 |
register int t; |
| 262 |
{ |
| 263 |
register struct bigblock *p; |
| 264 |
|
| 265 |
switch(t) |
| 266 |
{ |
| 267 |
case TYCHAR: |
| 268 |
case TYCOMPLEX: |
| 269 |
case TYDCOMPLEX: |
| 270 |
break; |
| 271 |
|
| 272 |
case TYLOGICAL: |
| 273 |
t = tylogical; |
| 274 |
case TYADDR: |
| 275 |
case TYSHORT: |
| 276 |
case TYLONG: |
| 277 |
p = cpexpr(retslot); |
| 278 |
p->vtype = t; |
| 279 |
putforce(t, p); |
| 280 |
break; |
| 281 |
|
| 282 |
case TYREAL: |
| 283 |
case TYDREAL: |
| 284 |
p = cpexpr(retslot); |
| 285 |
p->vtype = t; |
| 286 |
putforce(t, p); |
| 287 |
break; |
| 288 |
|
| 289 |
default: |
| 290 |
fatal1("retval: impossible type %d", t); |
| 291 |
} |
| 292 |
goret(t); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
LOCAL void |
| 299 |
procode() |
| 300 |
{ |
| 301 |
register chainp p; |
| 302 |
struct bigblock *argvec; |
| 303 |
|
| 304 |
if(lastargslot>0 && nentry>1) |
| 305 |
argvec = autovar(lastargslot/FSZADDR, TYADDR, NULL); |
| 306 |
else |
| 307 |
argvec = NULL; |
| 308 |
|
| 309 |
for(p = entries ; p ; p = p->entrypoint.nextp) |
| 310 |
prolog(&p->entrypoint, argvec); |
| 311 |
|
| 312 |
putrbrack(procno); |
| 313 |
|
| 314 |
prendproc(); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
LOCAL void |
| 322 |
doentry(struct entrypoint *ep) |
| 323 |
{ |
| 324 |
int type; |
| 325 |
struct bigblock *np, *q; |
| 326 |
chainp p; |
| 327 |
|
| 328 |
++nentry; |
| 329 |
if(procclass == CLMAIN) { |
| 330 |
putlabel(ep->entrylabel); |
| 331 |
return; |
| 332 |
} else if(procclass == CLBLOCK) |
| 333 |
return; |
| 334 |
|
| 335 |
impldcl(np = mkname(VL, nounder(XL, ep->entryname->extname))); |
| 336 |
type = np->vtype; |
| 337 |
if(proctype == TYUNKNOWN) |
| 338 |
if( (proctype = type) == TYCHAR) |
| 339 |
procleng = (np->vleng ? np->vleng->b_const.fconst.ci : (ftnint) 0); |
| 340 |
|
| 341 |
if(proctype == TYCHAR) { |
| 342 |
if(type != TYCHAR) |
| 343 |
err("noncharacter entry of character function"); |
| 344 |
else if( (np->vleng ? np->vleng->b_const.fconst.ci : (ftnint) 0) != procleng) |
| 345 |
err("mismatched character entry lengths"); |
| 346 |
} else if(type == TYCHAR) |
| 347 |
err("character entry of noncharacter function"); |
| 348 |
else if(type != proctype) |
| 349 |
multitype = YES; |
| 350 |
if(rtvlabel[type] == 0) |
| 351 |
rtvlabel[type] = newlabel(); |
| 352 |
ep->typelabel = rtvlabel[type]; |
| 353 |
|
| 354 |
if(type == TYCHAR) { |
| 355 |
if(chslot < 0) { |
| 356 |
chslot = nextarg(TYADDR); |
| 357 |
chlgslot = nextarg(TYLENG); |
| 358 |
} |
| 359 |
np->vstg = STGARG; |
| 360 |
np->b_name.vardesc.varno = chslot; |
| 361 |
if(procleng == 0) |
| 362 |
np->vleng = mkarg(TYLENG, chlgslot); |
| 363 |
} else if( ISCOMPLEX(type) ) { |
| 364 |
np->vstg = STGARG; |
| 365 |
if(cxslot < 0) |
| 366 |
cxslot = nextarg(TYADDR); |
| 367 |
np->b_name.vardesc.varno = cxslot; |
| 368 |
} else if(type != TYSUBR) { |
| 369 |
if(nentry == 1) |
| 370 |
retslot = autovar(1, TYDREAL, NULL); |
| 371 |
np->vstg = STGAUTO; |
| 372 |
np->b_name.voffset = retslot->b_addr.memoffset->b_const.fconst.ci; |
| 373 |
} |
| 374 |
|
| 375 |
for(p = ep->arglist ; p ; p = p->chain.nextp) |
| 376 |
if(! ((q = p->chain.datap)->b_name.vdcldone) ) |
| 377 |
q->b_name.vardesc.varno = nextarg(TYADDR); |
| 378 |
|
| 379 |
for(p = ep->arglist ; p ; p = p->chain.nextp) |
| 380 |
if(! ((q = p->chain.datap)->b_name.vdcldone) ) { |
| 381 |
impldcl(q); |
| 382 |
q->b_name.vdcldone = YES; |
| 383 |
if(q->vtype == TYCHAR) { |
| 384 |
if(q->vleng == NULL) |
| 385 |
q->vleng = mkarg(TYLENG, nextarg(TYLENG) ); |
| 386 |
else if(nentry == 1) |
| 387 |
nextarg(TYLENG); |
| 388 |
} else if(q->vclass==CLPROC && nentry==1) |
| 389 |
nextarg(TYLENG) ; |
| 390 |
} |
| 391 |
putlabel(ep->entrylabel); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
LOCAL int |
| 397 |
nextarg(type) |
| 398 |
int type; |
| 399 |
{ |
| 400 |
int k; |
| 401 |
k = lastargslot; |
| 402 |
lastargslot += typesize[type]; |
| 403 |
return(k); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
LOCAL void |
| 409 |
dobss() |
| 410 |
{ |
| 411 |
register struct hashentry *p; |
| 412 |
register struct bigblock *q; |
| 413 |
register int i; |
| 414 |
int align; |
| 415 |
ftnint leng, iarrl; |
| 416 |
|
| 417 |
setloc(UDATA); |
| 418 |
|
| 419 |
for(p = hashtab ; p<lasthash ; ++p) |
| 420 |
if((q = p->varp)) |
| 421 |
{ |
| 422 |
if( (q->vclass==CLUNKNOWN && q->vstg!=STGARG) || |
| 423 |
(q->vclass==CLVAR && q->vstg==STGUNKNOWN) ) |
| 424 |
warn1("local variable %s never used", varstr(VL,q->b_name.varname) ); |
| 425 |
else if(q->vclass==CLVAR && q->vstg==STGBSS) |
| 426 |
{ |
| 427 |
align = (q->vtype==TYCHAR ? ALILONG : typealign[q->vtype]); |
| 428 |
if(bssleng % align != 0) |
| 429 |
{ |
| 430 |
bssleng = roundup(bssleng, align); |
| 431 |
preven(align); |
| 432 |
} |
| 433 |
prlocvar( memname(STGBSS, q->b_name.vardesc.varno), iarrl = iarrlen(q) ); |
| 434 |
bssleng += iarrl; |
| 435 |
} |
| 436 |
else if(q->vclass==CLPROC && q->b_name.vprocclass==PEXTERNAL && q->vstg!=STGARG) |
| 437 |
mkext(varunder(VL, q->b_name.varname)) ->extstg = STGEXT; |
| 438 |
|
| 439 |
if(q->vclass==CLVAR && q->vstg!=STGARG) |
| 440 |
{ |
| 441 |
if(q->b_name.vdim && !ISICON(q->b_name.vdim->nelt) ) |
| 442 |
dclerr("adjustable dimension on non-argument", q); |
| 443 |
if(q->vtype==TYCHAR && (q->vleng==NULL || !ISICON(q->vleng))) |
| 444 |
dclerr("adjustable leng on nonargument", q); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
for(i = 0 ; i < nequiv ; ++i) |
| 449 |
if(eqvclass[i].eqvinit==NO && (leng = eqvclass[i].eqvleng)!=0 ) |
| 450 |
{ |
| 451 |
bssleng = roundup(bssleng, ALIDOUBLE); |
| 452 |
preven(ALIDOUBLE); |
| 453 |
prlocvar( memname(STGEQUIV, i), leng); |
| 454 |
bssleng += leng; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
void |
| 461 |
doext() |
| 462 |
{ |
| 463 |
struct extsym *p; |
| 464 |
|
| 465 |
for(p = extsymtab ; p<nextext ; ++p) |
| 466 |
prext( varstr(XL, p->extname), p->maxleng, p->extinit); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
ftnint iarrlen(q) |
| 473 |
register struct bigblock *q; |
| 474 |
{ |
| 475 |
ftnint leng; |
| 476 |
|
| 477 |
leng = typesize[q->vtype]; |
| 478 |
if(leng <= 0) |
| 479 |
return(-1); |
| 480 |
if(q->b_name.vdim) { |
| 481 |
if( ISICON(q->b_name.vdim->nelt) ) |
| 482 |
leng *= q->b_name.vdim->nelt->b_const.fconst.ci; |
| 483 |
else return(-1); |
| 484 |
} |
| 485 |
if(q->vleng) { |
| 486 |
if( ISICON(q->vleng) ) |
| 487 |
leng *= q->vleng->b_const.fconst.ci; |
| 488 |
else return(-1); |
| 489 |
} |
| 490 |
return(leng); |
| 491 |
} |
| 492 |
|
| 493 |
LOCAL void |
| 494 |
docommon() |
| 495 |
{ |
| 496 |
register struct extsym *p; |
| 497 |
register chainp q; |
| 498 |
struct dimblock *t; |
| 499 |
bigptr neltp; |
| 500 |
register struct bigblock *v; |
| 501 |
ftnint size; |
| 502 |
int type; |
| 503 |
|
| 504 |
for(p = extsymtab ; p<nextext ; ++p) |
| 505 |
if(p->extstg==STGCOMMON) |
| 506 |
{ |
| 507 |
for(q = p->extp ; q ; q = q->chain.nextp) |
| 508 |
{ |
| 509 |
v = q->chain.datap; |
| 510 |
if(v->b_name.vdcldone == NO) |
| 511 |
vardcl(v); |
| 512 |
type = v->vtype; |
| 513 |
if(p->extleng % typealign[type] != 0) |
| 514 |
{ |
| 515 |
dclerr("common alignment", v); |
| 516 |
p->extleng = roundup(p->extleng, typealign[type]); |
| 517 |
} |
| 518 |
v->b_name.voffset = p->extleng; |
| 519 |
v->b_name.vardesc.varno = p - extsymtab; |
| 520 |
if(type == TYCHAR) |
| 521 |
size = v->vleng->b_const.fconst.ci; |
| 522 |
else size = typesize[type]; |
| 523 |
if((t = v->b_name.vdim)) { |
| 524 |
if( (neltp = t->nelt) && ISCONST(neltp) ) |
| 525 |
size *= neltp->b_const.fconst.ci; |
| 526 |
else |
| 527 |
dclerr("adjustable array in common", v); |
| 528 |
} |
| 529 |
p->extleng += size; |
| 530 |
} |
| 531 |
|
| 532 |
frchain( &(p->extp) ); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
LOCAL void |
| 541 |
docomleng() |
| 542 |
{ |
| 543 |
register struct extsym *p; |
| 544 |
|
| 545 |
for(p = extsymtab ; p < nextext ; ++p) |
| 546 |
if(p->extstg == STGCOMMON) |
| 547 |
{ |
| 548 |
if(p->maxleng!=0 && p->extleng!=0 && p->maxleng!=p->extleng && |
| 549 |
!eqn(XL,"_BLNK__ ",p->extname) ) |
| 550 |
warn1("incompatible lengths for common block %s", |
| 551 |
nounder(XL, p->extname) ); |
| 552 |
if(p->maxleng < p->extleng) |
| 553 |
p->maxleng = p->extleng; |
| 554 |
p->extleng = 0; |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
void |
| 563 |
frtemp(p) |
| 564 |
struct bigblock *p; |
| 565 |
{ |
| 566 |
holdtemps = mkchain(p, holdtemps); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
struct bigblock * |
| 575 |
autovar(int nelt, int t, bigptr lengp) |
| 576 |
{ |
| 577 |
ftnint leng = 0; |
| 578 |
register struct bigblock *q; |
| 579 |
|
| 580 |
if(t == TYCHAR) { |
| 581 |
if( ISICON(lengp) ) |
| 582 |
leng = lengp->b_const.fconst.ci; |
| 583 |
else |
| 584 |
fatal("automatic variable of nonconstant length"); |
| 585 |
} else |
| 586 |
leng = typesize[t]; |
| 587 |
autoleng = roundup( autoleng, typealign[t]); |
| 588 |
|
| 589 |
q = BALLO(); |
| 590 |
q->tag = TADDR; |
| 591 |
q->vtype = t; |
| 592 |
if(t == TYCHAR) |
| 593 |
q->vleng = MKICON(leng); |
| 594 |
q->vstg = STGAUTO; |
| 595 |
q->b_addr.ntempelt = nelt; |
| 596 |
#ifdef STACK_DOWN |
| 597 |
|
| 598 |
autoleng += nelt*leng; |
| 599 |
q->b_addr.memoffset = MKICON( - autoleng ); |
| 600 |
#else |
| 601 |
q->b_addr.memoffset = MKICON( autoleng ); |
| 602 |
autoleng += nelt*leng; |
| 603 |
#endif |
| 604 |
|
| 605 |
return(q); |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
struct bigblock *mktmpn(nelt, type, lengp) |
| 610 |
int nelt; |
| 611 |
register int type; |
| 612 |
bigptr lengp; |
| 613 |
{ |
| 614 |
ftnint leng = 0; |
| 615 |
chainp p, oldp; |
| 616 |
register struct bigblock *q; |
| 617 |
|
| 618 |
if(type==TYUNKNOWN || type==TYERROR) |
| 619 |
fatal1("mktmpn: invalid type %d", type); |
| 620 |
|
| 621 |
if(type==TYCHAR) { |
| 622 |
if( ISICON(lengp) ) |
| 623 |
leng = lengp->b_const.fconst.ci; |
| 624 |
else { |
| 625 |
err("adjustable length"); |
| 626 |
return( errnode() ); |
| 627 |
} |
| 628 |
} |
| 629 |
for(oldp = (chainp)&templist ; (p = oldp->chain.nextp) ; oldp = p) |
| 630 |
{ |
| 631 |
q = p->chain.datap; |
| 632 |
if(q->vtype==type && q->b_addr.ntempelt==nelt && |
| 633 |
(type!=TYCHAR || q->vleng->b_const.fconst.ci==leng) ) |
| 634 |
{ |
| 635 |
oldp->chain.nextp = p->chain.nextp; |
| 636 |
ckfree(p); |
| 637 |
return(q); |
| 638 |
} |
| 639 |
} |
| 640 |
q = autovar(nelt, type, lengp); |
| 641 |
q->b_addr.istemp = YES; |
| 642 |
return(q); |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
struct bigblock *fmktemp(type, lengp) |
| 649 |
int type; |
| 650 |
bigptr lengp; |
| 651 |
{ |
| 652 |
return( mktmpn(1,type,lengp) ); |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
struct extsym *comblock(len, s) |
| 658 |
register int len; |
| 659 |
register char *s; |
| 660 |
{ |
| 661 |
struct extsym *p; |
| 662 |
|
| 663 |
if(len == 0) |
| 664 |
{ |
| 665 |
s = BLANKCOMMON; |
| 666 |
len = strlen(s); |
| 667 |
} |
| 668 |
p = mkext( varunder(len, s) ); |
| 669 |
if(p->extstg == STGUNKNOWN) |
| 670 |
p->extstg = STGCOMMON; |
| 671 |
else if(p->extstg != STGCOMMON) |
| 672 |
{ |
| 673 |
err1("%s cannot be a common block name", s); |
| 674 |
return(0); |
| 675 |
} |
| 676 |
|
| 677 |
return( p ); |
| 678 |
} |
| 679 |
|
| 680 |
void |
| 681 |
incomm(c, v) |
| 682 |
struct extsym *c; |
| 683 |
struct bigblock *v; |
| 684 |
{ |
| 685 |
if(v->vstg != STGUNKNOWN) |
| 686 |
dclerr("incompatible common declaration", v); |
| 687 |
else |
| 688 |
{ |
| 689 |
v->vstg = STGCOMMON; |
| 690 |
c->extp = hookup(c->extp, mkchain(v,NULL) ); |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
void |
| 697 |
settype(v, type, length) |
| 698 |
register struct bigblock * v; |
| 699 |
register int type; |
| 700 |
register int length; |
| 701 |
{ |
| 702 |
if(type == TYUNKNOWN) |
| 703 |
return; |
| 704 |
|
| 705 |
if(type==TYSUBR && v->vtype!=TYUNKNOWN && v->vstg==STGARG) |
| 706 |
{ |
| 707 |
v->vtype = TYSUBR; |
| 708 |
frexpr(v->vleng); |
| 709 |
} |
| 710 |
else if(type < 0) |
| 711 |
{ |
| 712 |
if(v->vstg == STGUNKNOWN) |
| 713 |
v->vstg = - type; |
| 714 |
else if(v->vstg != -type) |
| 715 |
dclerr("incompatible storage declarations", v); |
| 716 |
} |
| 717 |
else if(v->vtype == TYUNKNOWN) |
| 718 |
{ |
| 719 |
if( (v->vtype = lengtype(type, length))==TYCHAR && length!=0) |
| 720 |
v->vleng = MKICON(length); |
| 721 |
} |
| 722 |
else if(v->vtype!=type || (type==TYCHAR && v->vleng->b_const.fconst.ci!=length) ) |
| 723 |
dclerr("incompatible type declarations", v); |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
int |
| 730 |
lengtype(type, length) |
| 731 |
register int type; |
| 732 |
register int length; |
| 733 |
{ |
| 734 |
switch(type) |
| 735 |
{ |
| 736 |
case TYREAL: |
| 737 |
if(length == 8) |
| 738 |
return(TYDREAL); |
| 739 |
if(length == 4) |
| 740 |
goto ret; |
| 741 |
break; |
| 742 |
|
| 743 |
case TYCOMPLEX: |
| 744 |
if(length == 16) |
| 745 |
return(TYDCOMPLEX); |
| 746 |
if(length == 8) |
| 747 |
goto ret; |
| 748 |
break; |
| 749 |
|
| 750 |
case TYSHORT: |
| 751 |
case TYDREAL: |
| 752 |
case TYDCOMPLEX: |
| 753 |
case TYCHAR: |
| 754 |
case TYUNKNOWN: |
| 755 |
case TYSUBR: |
| 756 |
case TYERROR: |
| 757 |
goto ret; |
| 758 |
|
| 759 |
case TYLOGICAL: |
| 760 |
if(length == 4) |
| 761 |
goto ret; |
| 762 |
break; |
| 763 |
|
| 764 |
case TYLONG: |
| 765 |
if(length == 0) |
| 766 |
return(tyint); |
| 767 |
if(length == 2) |
| 768 |
return(TYSHORT); |
| 769 |
if(length == 4) |
| 770 |
goto ret; |
| 771 |
break; |
| 772 |
default: |
| 773 |
fatal1("lengtype: invalid type %d", type); |
| 774 |
} |
| 775 |
|
| 776 |
if(length != 0) |
| 777 |
err("incompatible type-length combination"); |
| 778 |
|
| 779 |
ret: |
| 780 |
return(type); |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
void |
| 787 |
setintr(v) |
| 788 |
register struct bigblock * v; |
| 789 |
{ |
| 790 |
register int k; |
| 791 |
|
| 792 |
if(v->vstg == STGUNKNOWN) |
| 793 |
v->vstg = STGINTR; |
| 794 |
else if(v->vstg!=STGINTR) |
| 795 |
dclerr("incompatible use of intrinsic function", v); |
| 796 |
if(v->vclass==CLUNKNOWN) |
| 797 |
v->vclass = CLPROC; |
| 798 |
if(v->b_name.vprocclass == PUNKNOWN) |
| 799 |
v->b_name.vprocclass = PINTRINSIC; |
| 800 |
else if(v->b_name.vprocclass != PINTRINSIC) |
| 801 |
dclerr("invalid intrinsic declaration", v); |
| 802 |
if((k = intrfunct(v->b_name.varname))) |
| 803 |
v->b_name.vardesc.varno = k; |
| 804 |
else |
| 805 |
dclerr("unknown intrinsic function", v); |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
void |
| 810 |
setext(v) |
| 811 |
register struct bigblock * v; |
| 812 |
{ |
| 813 |
if(v->vclass == CLUNKNOWN) |
| 814 |
v->vclass = CLPROC; |
| 815 |
else if(v->vclass != CLPROC) |
| 816 |
dclerr("invalid external declaration", v); |
| 817 |
|
| 818 |
if(v->b_name.vprocclass == PUNKNOWN) |
| 819 |
v->b_name.vprocclass = PEXTERNAL; |
| 820 |
else if(v->b_name.vprocclass != PEXTERNAL) |
| 821 |
dclerr("invalid external declaration", v); |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
void |
| 829 |
setbound(v, nd, dims) |
| 830 |
register struct bigblock * v; |
| 831 |
int nd; |
| 832 |
struct uux dims[ ]; |
| 833 |
{ |
| 834 |
register bigptr q, t; |
| 835 |
register struct dimblock *p; |
| 836 |
int i; |
| 837 |
|
| 838 |
if(v->vclass == CLUNKNOWN) |
| 839 |
v->vclass = CLVAR; |
| 840 |
else if(v->vclass != CLVAR) |
| 841 |
{ |
| 842 |
dclerr("only variables may be arrays", v); |
| 843 |
return; |
| 844 |
} |
| 845 |
|
| 846 |
v->b_name.vdim = p = (struct dimblock *) ckalloc( sizeof(int) + (3+2*nd)*sizeof(bigptr) ); |
| 847 |
p->ndim = nd; |
| 848 |
p->nelt = MKICON(1); |
| 849 |
|
| 850 |
for(i=0 ; i<nd ; ++i) |
| 851 |
{ |
| 852 |
if( (q = dims[i].ub) == NULL) |
| 853 |
{ |
| 854 |
if(i == nd-1) |
| 855 |
{ |
| 856 |
frexpr(p->nelt); |
| 857 |
p->nelt = NULL; |
| 858 |
} |
| 859 |
else |
| 860 |
err("only last bound may be asterisk"); |
| 861 |
p->dims[i].dimsize = MKICON(1);; |
| 862 |
p->dims[i].dimexpr = NULL; |
| 863 |
} |
| 864 |
else |
| 865 |
{ |
| 866 |
if(dims[i].lb) |
| 867 |
{ |
| 868 |
q = mkexpr(OPMINUS, q, cpexpr(dims[i].lb)); |
| 869 |
q = mkexpr(OPPLUS, q, MKICON(1) ); |
| 870 |
} |
| 871 |
if( ISCONST(q) ) |
| 872 |
{ |
| 873 |
p->dims[i].dimsize = q; |
| 874 |
p->dims[i].dimexpr = NULL; |
| 875 |
} |
| 876 |
else { |
| 877 |
p->dims[i].dimsize = autovar(1, tyint, NULL); |
| 878 |
p->dims[i].dimexpr = q; |
| 879 |
} |
| 880 |
if(p->nelt) |
| 881 |
p->nelt = mkexpr(OPSTAR, p->nelt, cpexpr(p->dims[i].dimsize)); |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
q = dims[nd-1].lb; |
| 886 |
if(q == NULL) |
| 887 |
q = MKICON(1); |
| 888 |
|
| 889 |
for(i = nd-2 ; i>=0 ; --i) |
| 890 |
{ |
| 891 |
t = dims[i].lb; |
| 892 |
if(t == NULL) |
| 893 |
t = MKICON(1); |
| 894 |
if(p->dims[i].dimsize) |
| 895 |
q = mkexpr(OPPLUS, t, mkexpr(OPSTAR, cpexpr(p->dims[i].dimsize), q) ); |
| 896 |
} |
| 897 |
|
| 898 |
if( ISCONST(q) ) |
| 899 |
{ |
| 900 |
p->baseoffset = q; |
| 901 |
p->basexpr = NULL; |
| 902 |
} |
| 903 |
else |
| 904 |
{ |
| 905 |
p->baseoffset = autovar(1, tyint, NULL); |
| 906 |
p->basexpr = q; |
| 907 |
} |
| 908 |
} |