[a7de7182] | 1 | /* $Id: misc.c,v 1.17 2009/02/11 15:58:55 ragge Exp $ */
|
---|
| 2 | /*
|
---|
| 3 | * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * Redistributions of source code and documentation must retain the above
|
---|
| 10 | * copyright notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * All advertising materials mentioning features or use of this software
|
---|
| 15 | * must display the following acknowledgement:
|
---|
| 16 | * This product includes software developed or owned by Caldera
|
---|
| 17 | * International, Inc.
|
---|
| 18 | * Neither the name of Caldera International, Inc. nor the names of other
|
---|
| 19 | * contributors may be used to endorse or promote products derived from
|
---|
| 20 | * this software without specific prior written permission.
|
---|
| 21 | *
|
---|
| 22 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
|
---|
| 23 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
|
---|
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
| 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 26 | * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
|
---|
| 27 | * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 30 | * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
|
---|
| 31 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
| 32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
| 33 | * POSSIBILITY OF SUCH DAMAGE.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <string.h>
|
---|
| 37 |
|
---|
| 38 | #include "defines.h"
|
---|
| 39 | #include "defs.h"
|
---|
| 40 |
|
---|
| 41 | int max(int, int);
|
---|
| 42 |
|
---|
| 43 | void
|
---|
| 44 | cpn(n, a, b)
|
---|
| 45 | register int n;
|
---|
| 46 | register char *a, *b;
|
---|
| 47 | {
|
---|
| 48 | while(--n >= 0)
|
---|
| 49 | *b++ = *a++;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | int
|
---|
| 54 | eqn(n, a, b)
|
---|
| 55 | register int n;
|
---|
| 56 | register char *a, *b;
|
---|
| 57 | {
|
---|
| 58 | while(--n >= 0)
|
---|
| 59 | if(*a++ != *b++)
|
---|
| 60 | return(NO);
|
---|
| 61 | return(YES);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | int
|
---|
| 70 | cmpstr(a, b, la, lb) /* compare two strings */
|
---|
| 71 | register char *a, *b;
|
---|
| 72 | ftnint la, lb;
|
---|
| 73 | {
|
---|
| 74 | register char *aend, *bend;
|
---|
| 75 | aend = a + la;
|
---|
| 76 | bend = b + lb;
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | if(la <= lb)
|
---|
| 80 | {
|
---|
| 81 | while(a < aend)
|
---|
| 82 | if(*a != *b)
|
---|
| 83 | return( *a - *b );
|
---|
| 84 | else
|
---|
| 85 | { ++a; ++b; }
|
---|
| 86 |
|
---|
| 87 | while(b < bend)
|
---|
| 88 | if(*b != ' ')
|
---|
| 89 | return(' ' - *b);
|
---|
| 90 | else
|
---|
| 91 | ++b;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | else
|
---|
| 95 | {
|
---|
| 96 | while(b < bend)
|
---|
| 97 | if(*a != *b)
|
---|
| 98 | return( *a - *b );
|
---|
| 99 | else
|
---|
| 100 | { ++a; ++b; }
|
---|
| 101 | while(a < aend)
|
---|
| 102 | if(*a != ' ')
|
---|
| 103 | return(*a - ' ');
|
---|
| 104 | else
|
---|
| 105 | ++a;
|
---|
| 106 | }
|
---|
| 107 | return(0);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | chainp hookup(x,y)
|
---|
| 115 | register chainp x, y;
|
---|
| 116 | {
|
---|
| 117 | register chainp p;
|
---|
| 118 |
|
---|
| 119 | if(x == NULL)
|
---|
| 120 | return(y);
|
---|
| 121 |
|
---|
| 122 | for(p = x ; p->chain.nextp ; p = p->chain.nextp)
|
---|
| 123 | ;
|
---|
| 124 | p->chain.nextp = y;
|
---|
| 125 | return(x);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | struct bigblock *mklist(p)
|
---|
| 131 | chainp p;
|
---|
| 132 | {
|
---|
| 133 | register struct bigblock *q;
|
---|
| 134 |
|
---|
| 135 | q = BALLO();
|
---|
| 136 | q->tag = TLIST;
|
---|
| 137 | q->b_list.listp = p;
|
---|
| 138 | return(q);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | chainp
|
---|
| 143 | mkchain(bigptr p, chainp q)
|
---|
| 144 | {
|
---|
| 145 | chainp r;
|
---|
| 146 |
|
---|
| 147 | if(chains) {
|
---|
| 148 | r = chains;
|
---|
| 149 | chains = chains->chain.nextp;
|
---|
| 150 | } else
|
---|
| 151 | r = ALLOC(chain);
|
---|
| 152 |
|
---|
| 153 | r->chain.datap = p;
|
---|
| 154 | r->chain.nextp = q;
|
---|
| 155 | return(r);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | char * varstr(n, s)
|
---|
| 161 | register int n;
|
---|
| 162 | register char *s;
|
---|
| 163 | {
|
---|
| 164 | register int i;
|
---|
| 165 | static char name[XL+1];
|
---|
| 166 |
|
---|
| 167 | for(i=0; i<n && *s!=' ' && *s!='\0' ; ++i)
|
---|
| 168 | name[i] = *s++;
|
---|
| 169 |
|
---|
| 170 | name[i] = '\0';
|
---|
| 171 |
|
---|
| 172 | return( name );
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | char * varunder(n, s)
|
---|
| 179 | register int n;
|
---|
| 180 | register char *s;
|
---|
| 181 | {
|
---|
| 182 | register int i;
|
---|
| 183 | static char name[XL+1];
|
---|
| 184 |
|
---|
| 185 | for(i=0; i<n && *s!=' ' && *s!='\0' ; ++i)
|
---|
| 186 | name[i] = *s++;
|
---|
| 187 |
|
---|
| 188 | name[i] = '\0';
|
---|
| 189 |
|
---|
| 190 | return( name );
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | char * nounder(n, s)
|
---|
| 198 | register int n;
|
---|
| 199 | register char *s;
|
---|
| 200 | {
|
---|
| 201 | register int i;
|
---|
| 202 | static char name[XL+1];
|
---|
| 203 |
|
---|
| 204 | for(i=0; i<n && *s!=' ' && *s!='\0' ; ++s)
|
---|
| 205 | if(*s != '_')
|
---|
| 206 | name[i++] = *s;
|
---|
| 207 |
|
---|
| 208 | name[i] = '\0';
|
---|
| 209 |
|
---|
| 210 | return( name );
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /*
|
---|
| 214 | * Save a block on heap.
|
---|
| 215 | */
|
---|
| 216 | char *
|
---|
| 217 | copyn(int n, char *s)
|
---|
| 218 | {
|
---|
| 219 | char *p, *q;
|
---|
| 220 |
|
---|
| 221 | p = q = ckalloc(n);
|
---|
| 222 | while(--n >= 0)
|
---|
| 223 | *q++ = *s++;
|
---|
| 224 | return(p);
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | /*
|
---|
| 228 | * Save a string on heap.
|
---|
| 229 | */
|
---|
| 230 | char *
|
---|
| 231 | copys(char *s)
|
---|
| 232 | {
|
---|
| 233 | return(copyn(strlen(s)+1 , s));
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /*
|
---|
| 237 | * convert a string to an int.
|
---|
| 238 | */
|
---|
| 239 | ftnint
|
---|
| 240 | convci(int n, char *s)
|
---|
| 241 | {
|
---|
| 242 | ftnint sum;
|
---|
| 243 | sum = 0;
|
---|
| 244 | while(n-- > 0)
|
---|
| 245 | sum = 10*sum + (*s++ - '0');
|
---|
| 246 | return(sum);
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | char *convic(n)
|
---|
| 250 | ftnint n;
|
---|
| 251 | {
|
---|
| 252 | static char s[20];
|
---|
| 253 | register char *t;
|
---|
| 254 |
|
---|
| 255 | s[19] = '\0';
|
---|
| 256 | t = s+19;
|
---|
| 257 |
|
---|
| 258 | do {
|
---|
| 259 | *--t = '0' + n%10;
|
---|
| 260 | n /= 10;
|
---|
| 261 | } while(n > 0);
|
---|
| 262 |
|
---|
| 263 | return(t);
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | double convcd(n, s)
|
---|
| 269 | int n;
|
---|
| 270 | register char *s;
|
---|
| 271 | {
|
---|
| 272 | char v[100];
|
---|
| 273 | register char *t;
|
---|
| 274 | if(n > 90)
|
---|
| 275 | {
|
---|
| 276 | err("too many digits in floating constant");
|
---|
| 277 | n = 90;
|
---|
| 278 | }
|
---|
| 279 | for(t = v ; n-- > 0 ; s++)
|
---|
| 280 | *t++ = (*s=='d' ? 'e' : *s);
|
---|
| 281 | *t = '\0';
|
---|
| 282 | return( atof(v) );
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 |
|
---|
| 286 |
|
---|
| 287 | struct bigblock *mkname(l, s)
|
---|
| 288 | int l;
|
---|
| 289 | register char *s;
|
---|
| 290 | {
|
---|
| 291 | struct hashentry *hp;
|
---|
| 292 | int hash;
|
---|
| 293 | register struct bigblock *q;
|
---|
| 294 | register int i;
|
---|
| 295 | char n[VL];
|
---|
| 296 |
|
---|
| 297 | hash = 0;
|
---|
| 298 | for(i = 0 ; i<l && *s!='\0' ; ++i)
|
---|
| 299 | {
|
---|
| 300 | hash += *s;
|
---|
| 301 | n[i] = *s++;
|
---|
| 302 | }
|
---|
| 303 | hash %= MAXHASH;
|
---|
| 304 | while( i < VL )
|
---|
| 305 | n[i++] = ' ';
|
---|
| 306 |
|
---|
| 307 | hp = hashtab + hash;
|
---|
| 308 | while((q = hp->varp))
|
---|
| 309 | if( hash==hp->hashval && eqn(VL,n,q->b_name.varname) )
|
---|
| 310 | return(q);
|
---|
| 311 | else if(++hp >= lasthash)
|
---|
| 312 | hp = hashtab;
|
---|
| 313 |
|
---|
| 314 | if(++nintnames >= MAXHASH-1)
|
---|
| 315 | fatal("hash table full");
|
---|
| 316 | hp->varp = q = BALLO();
|
---|
| 317 | hp->hashval = hash;
|
---|
| 318 | q->tag = TNAME;
|
---|
| 319 | cpn(VL, n, q->b_name.varname);
|
---|
| 320 | return(q);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 |
|
---|
| 324 |
|
---|
| 325 | struct labelblock *mklabel(l)
|
---|
| 326 | ftnint l;
|
---|
| 327 | {
|
---|
| 328 | register struct labelblock *lp;
|
---|
| 329 |
|
---|
| 330 | if(l == 0)
|
---|
| 331 | return(0);
|
---|
| 332 |
|
---|
| 333 | for(lp = labeltab ; lp < highlabtab ; ++lp)
|
---|
| 334 | if(lp->stateno == l)
|
---|
| 335 | return(lp);
|
---|
| 336 |
|
---|
| 337 | if(++highlabtab >= labtabend)
|
---|
| 338 | fatal("too many statement numbers");
|
---|
| 339 |
|
---|
| 340 | lp->stateno = l;
|
---|
| 341 | lp->labelno = newlabel();
|
---|
| 342 | lp->blklevel = 0;
|
---|
| 343 | lp->labused = NO;
|
---|
| 344 | lp->labdefined = NO;
|
---|
| 345 | lp->labinacc = NO;
|
---|
| 346 | lp->labtype = LABUNKNOWN;
|
---|
| 347 | return(lp);
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | int
|
---|
| 351 | newlabel()
|
---|
| 352 | {
|
---|
| 353 | return( lastlabno++ );
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 |
|
---|
| 357 | /* find or put a name in the external symbol table */
|
---|
| 358 |
|
---|
| 359 | struct extsym *mkext(s)
|
---|
| 360 | char *s;
|
---|
| 361 | {
|
---|
| 362 | int i;
|
---|
| 363 | register char *t;
|
---|
| 364 | char n[XL];
|
---|
| 365 | struct extsym *p;
|
---|
| 366 |
|
---|
| 367 | i = 0;
|
---|
| 368 | t = n;
|
---|
| 369 | while(i<XL && *s)
|
---|
| 370 | *t++ = *s++;
|
---|
| 371 | while(t < n+XL)
|
---|
| 372 | *t++ = ' ';
|
---|
| 373 |
|
---|
| 374 | for(p = extsymtab ; p<nextext ; ++p)
|
---|
| 375 | if(eqn(XL, n, p->extname))
|
---|
| 376 | return( p );
|
---|
| 377 |
|
---|
| 378 | if(nextext >= lastext)
|
---|
| 379 | fatal("too many external symbols");
|
---|
| 380 |
|
---|
| 381 | cpn(XL, n, nextext->extname);
|
---|
| 382 | nextext->extstg = STGUNKNOWN;
|
---|
| 383 | nextext->extsave = NO;
|
---|
| 384 | nextext->extp = 0;
|
---|
| 385 | nextext->extleng = 0;
|
---|
| 386 | nextext->maxleng = 0;
|
---|
| 387 | nextext->extinit = NO;
|
---|
| 388 | return( nextext++ );
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 |
|
---|
| 395 |
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | struct bigblock *builtin(t, s)
|
---|
| 399 | int t;
|
---|
| 400 | char *s;
|
---|
| 401 | {
|
---|
| 402 | register struct extsym *p;
|
---|
| 403 | register struct bigblock *q;
|
---|
| 404 |
|
---|
| 405 | p = mkext(s);
|
---|
| 406 | if(p->extstg == STGUNKNOWN)
|
---|
| 407 | p->extstg = STGEXT;
|
---|
| 408 | else if(p->extstg != STGEXT)
|
---|
| 409 | {
|
---|
| 410 | err1("improper use of builtin %s", s);
|
---|
| 411 | return(0);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | q = BALLO();
|
---|
| 415 | q->tag = TADDR;
|
---|
| 416 | q->vtype = t;
|
---|
| 417 | q->vclass = CLPROC;
|
---|
| 418 | q->vstg = STGEXT;
|
---|
| 419 | q->b_addr.memno = p - extsymtab;
|
---|
| 420 | return(q);
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 |
|
---|
| 424 | void
|
---|
| 425 | frchain(p)
|
---|
| 426 | register chainp *p;
|
---|
| 427 | {
|
---|
| 428 | register chainp q;
|
---|
| 429 |
|
---|
| 430 | if(p==0 || *p==0)
|
---|
| 431 | return;
|
---|
| 432 |
|
---|
| 433 | for(q = *p; q->chain.nextp ; q = q->chain.nextp)
|
---|
| 434 | ;
|
---|
| 435 | q->chain.nextp = chains;
|
---|
| 436 | chains = *p;
|
---|
| 437 | *p = 0;
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 |
|
---|
| 441 | ptr cpblock(n,p)
|
---|
| 442 | register int n;
|
---|
| 443 | register void * p;
|
---|
| 444 | {
|
---|
| 445 | register char *q, *r = p;
|
---|
| 446 | ptr q0;
|
---|
| 447 |
|
---|
| 448 | q = q0 = ckalloc(n);
|
---|
| 449 | while(n-- > 0)
|
---|
| 450 | *q++ = *r++;
|
---|
| 451 | return(q0);
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 |
|
---|
| 455 | int
|
---|
| 456 | max(a,b)
|
---|
| 457 | int a,b;
|
---|
| 458 | {
|
---|
| 459 | return( a>b ? a : b);
|
---|
| 460 | }
|
---|
| 461 |
|
---|
| 462 |
|
---|
| 463 | ftnint lmax(a, b)
|
---|
| 464 | ftnint a, b;
|
---|
| 465 | {
|
---|
| 466 | return( a>b ? a : b);
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | ftnint lmin(a, b)
|
---|
| 470 | ftnint a, b;
|
---|
| 471 | {
|
---|
| 472 | return(a < b ? a : b);
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 |
|
---|
| 476 |
|
---|
| 477 | int
|
---|
| 478 | maxtype(t1, t2)
|
---|
| 479 | int t1, t2;
|
---|
| 480 | {
|
---|
| 481 | int t;
|
---|
| 482 |
|
---|
| 483 | t = max(t1, t2);
|
---|
| 484 | if(t==TYCOMPLEX && (t1==TYDREAL || t2==TYDREAL) )
|
---|
| 485 | t = TYDCOMPLEX;
|
---|
| 486 | return(t);
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 |
|
---|
| 490 |
|
---|
| 491 | /* return log base 2 of n if n a power of 2; otherwise -1 */
|
---|
| 492 | int
|
---|
| 493 | flog2(n)
|
---|
| 494 | ftnint n;
|
---|
| 495 | {
|
---|
| 496 | int k;
|
---|
| 497 |
|
---|
| 498 | /* trick based on binary representation */
|
---|
| 499 |
|
---|
| 500 | if(n<=0 || (n & (n-1))!=0)
|
---|
| 501 | return(-1);
|
---|
| 502 |
|
---|
| 503 | for(k = 0 ; n >>= 1 ; ++k)
|
---|
| 504 | ;
|
---|
| 505 | return(k);
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 |
|
---|
| 509 | void
|
---|
| 510 | frrpl()
|
---|
| 511 | {
|
---|
| 512 | chainp rp;
|
---|
| 513 |
|
---|
| 514 | while(rpllist)
|
---|
| 515 | {
|
---|
| 516 | rp = rpllist->rplblock.nextp;
|
---|
| 517 | ckfree(rpllist);
|
---|
| 518 | rpllist = rp;
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | void
|
---|
| 523 | popstack(p)
|
---|
| 524 | register chainp *p;
|
---|
| 525 | {
|
---|
| 526 | register chainp q;
|
---|
| 527 |
|
---|
| 528 | if(p==NULL || *p==NULL)
|
---|
| 529 | fatal("popstack: stack empty");
|
---|
| 530 | q = (*p)->chain.nextp;
|
---|
| 531 | ckfree(*p);
|
---|
| 532 | *p = q;
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 |
|
---|
| 536 |
|
---|
| 537 | struct bigblock *
|
---|
| 538 | callk(type, name, args)
|
---|
| 539 | int type;
|
---|
| 540 | char *name;
|
---|
| 541 | bigptr args;
|
---|
| 542 | {
|
---|
| 543 | register struct bigblock *p;
|
---|
| 544 |
|
---|
| 545 | p = mkexpr(OPCALL, builtin(type,name), args);
|
---|
| 546 | p->vtype = type;
|
---|
| 547 | return(p);
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 |
|
---|
| 551 |
|
---|
| 552 | struct bigblock *
|
---|
| 553 | call4(type, name, arg1, arg2, arg3, arg4)
|
---|
| 554 | int type;
|
---|
| 555 | char *name;
|
---|
| 556 | bigptr arg1, arg2, arg3, arg4;
|
---|
| 557 | {
|
---|
| 558 | struct bigblock *args;
|
---|
| 559 | args = mklist( mkchain(arg1, mkchain(arg2, mkchain(arg3, mkchain(arg4, NULL)) ) ) );
|
---|
| 560 | return( callk(type, name, args) );
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 |
|
---|
| 564 |
|
---|
| 565 |
|
---|
| 566 | struct bigblock *call3(type, name, arg1, arg2, arg3)
|
---|
| 567 | int type;
|
---|
| 568 | char *name;
|
---|
| 569 | bigptr arg1, arg2, arg3;
|
---|
| 570 | {
|
---|
| 571 | struct bigblock *args;
|
---|
| 572 | args = mklist( mkchain(arg1, mkchain(arg2, mkchain(arg3, NULL) ) ) );
|
---|
| 573 | return( callk(type, name, args) );
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 |
|
---|
| 577 |
|
---|
| 578 |
|
---|
| 579 |
|
---|
| 580 | struct bigblock *
|
---|
| 581 | call2(type, name, arg1, arg2)
|
---|
| 582 | int type;
|
---|
| 583 | char *name;
|
---|
| 584 | bigptr arg1, arg2;
|
---|
| 585 | {
|
---|
| 586 | bigptr args;
|
---|
| 587 |
|
---|
| 588 | args = mklist( mkchain(arg1, mkchain(arg2, NULL) ) );
|
---|
| 589 | return( callk(type,name, args) );
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 |
|
---|
| 593 |
|
---|
| 594 |
|
---|
| 595 | struct bigblock *call1(type, name, arg)
|
---|
| 596 | int type;
|
---|
| 597 | char *name;
|
---|
| 598 | bigptr arg;
|
---|
| 599 | {
|
---|
| 600 | return( callk(type,name, mklist(mkchain(arg,0)) ));
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 |
|
---|
| 604 | struct bigblock *call0(type, name)
|
---|
| 605 | int type;
|
---|
| 606 | char *name;
|
---|
| 607 | {
|
---|
| 608 | return( callk(type, name, NULL) );
|
---|
| 609 | }
|
---|
| 610 |
|
---|
| 611 |
|
---|
| 612 |
|
---|
| 613 | struct bigblock *
|
---|
| 614 | mkiodo(dospec, list)
|
---|
| 615 | chainp dospec, list;
|
---|
| 616 | {
|
---|
| 617 | register struct bigblock *q;
|
---|
| 618 |
|
---|
| 619 | q = BALLO();
|
---|
| 620 | q->tag = TIMPLDO;
|
---|
| 621 | q->b_impldo.varnp = (struct bigblock *)dospec;
|
---|
| 622 | q->b_impldo.datalist = list;
|
---|
| 623 | return(q);
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 |
|
---|
| 627 |
|
---|
| 628 |
|
---|
| 629 | ptr
|
---|
| 630 | ckalloc(int n)
|
---|
| 631 | {
|
---|
| 632 | ptr p;
|
---|
| 633 |
|
---|
| 634 | if ((p = calloc(1, (unsigned) n)) == NULL)
|
---|
| 635 | fatal("out of memory");
|
---|
| 636 | #ifdef PCC_DEBUG
|
---|
| 637 | if (mflag)
|
---|
| 638 | printf("ckalloc: sz %d ptr %p\n", n, p);
|
---|
| 639 | #endif
|
---|
| 640 | return(p);
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | void
|
---|
| 644 | ckfree(void *p)
|
---|
| 645 | {
|
---|
| 646 | #ifdef PCC_DEBUG
|
---|
| 647 | if (mflag)
|
---|
| 648 | printf("ckfree: ptr %p\n", p);
|
---|
| 649 | #endif
|
---|
| 650 | free(p);
|
---|
| 651 | }
|
---|
| 652 |
|
---|
| 653 | #if 0
|
---|
| 654 | int
|
---|
| 655 | isaddr(p)
|
---|
| 656 | register bigptr p;
|
---|
| 657 | {
|
---|
| 658 | if(p->tag == TADDR)
|
---|
| 659 | return(YES);
|
---|
| 660 | if(p->tag == TEXPR)
|
---|
| 661 | switch(p->b_expr.opcode)
|
---|
| 662 | {
|
---|
| 663 | case OPCOMMA:
|
---|
| 664 | return( isaddr(p->b_expr.rightp) );
|
---|
| 665 |
|
---|
| 666 | case OPASSIGN:
|
---|
| 667 | case OPPLUSEQ:
|
---|
| 668 | return( isaddr(p->b_expr.leftp) );
|
---|
| 669 | }
|
---|
| 670 | return(NO);
|
---|
| 671 | }
|
---|
| 672 | #endif
|
---|
| 673 |
|
---|
| 674 | /*
|
---|
| 675 | * Return YES if not an expression.
|
---|
| 676 | */
|
---|
| 677 | int
|
---|
| 678 | addressable(bigptr p)
|
---|
| 679 | {
|
---|
| 680 | switch(p->tag) {
|
---|
| 681 | case TCONST:
|
---|
| 682 | return(YES);
|
---|
| 683 |
|
---|
| 684 | case TADDR:
|
---|
| 685 | return( addressable(p->b_addr.memoffset) );
|
---|
| 686 |
|
---|
| 687 | default:
|
---|
| 688 | return(NO);
|
---|
| 689 | }
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 |
|
---|
| 693 | int
|
---|
| 694 | hextoi(c)
|
---|
| 695 | register int c;
|
---|
| 696 | {
|
---|
| 697 | register char *p;
|
---|
| 698 | static char p0[17] = "0123456789abcdef";
|
---|
| 699 |
|
---|
| 700 | for(p = p0 ; *p ; ++p)
|
---|
| 701 | if(*p == c)
|
---|
| 702 | return( p-p0 );
|
---|
| 703 | return(16);
|
---|
| 704 | }
|
---|