13192Smckusick /* Copyright (c) 1979 Regents of the University of California */ 23192Smckusick 3*3428Speter static char sccsid[] = "@(#)fend.c 1.6 04/01/81"; 43192Smckusick 53192Smckusick #include "whoami.h" 63192Smckusick #include "0.h" 73192Smckusick #include "tree.h" 83192Smckusick #include "opcode.h" 93192Smckusick #include "objfmt.h" 103192Smckusick #include "align.h" 113192Smckusick 123192Smckusick /* 133192Smckusick * this array keeps the pxp counters associated with 143192Smckusick * functions and procedures, so that they can be output 153192Smckusick * when their bodies are encountered 163192Smckusick */ 173192Smckusick int bodycnts[ DSPLYSZ ]; 183192Smckusick 193192Smckusick #ifdef PC 203192Smckusick # include "pc.h" 213192Smckusick # include "pcops.h" 223192Smckusick #endif PC 233192Smckusick 243192Smckusick #ifdef OBJ 253192Smckusick int cntpatch; 263192Smckusick int nfppatch; 273192Smckusick #endif OBJ 283192Smckusick 293192Smckusick struct nl *Fp; 303192Smckusick int pnumcnt; 313192Smckusick /* 323192Smckusick * Funcend is called to 333192Smckusick * finish a block by generating 343192Smckusick * the code for the statements. 353192Smckusick * It then looks for unresolved declarations 363192Smckusick * of labels, procedures and functions, 373192Smckusick * and cleans up the name list. 383192Smckusick * For the program, it checks the 393192Smckusick * semantics of the program 403192Smckusick * statement (yuchh). 413192Smckusick */ 423192Smckusick funcend(fp, bundle, endline) 433192Smckusick struct nl *fp; 443192Smckusick int *bundle; 453192Smckusick int endline; 463192Smckusick { 473192Smckusick register struct nl *p; 483192Smckusick register int i, b; 493192Smckusick int var, inp, out, *blk; 503192Smckusick bool chkref; 513192Smckusick struct nl *iop; 523192Smckusick char *cp; 533192Smckusick extern int cntstat; 543192Smckusick # ifdef PC 553363Speter int savlabel = getlab(); 563363Speter int toplabel = getlab(); 573363Speter int botlabel = getlab(); 583363Speter char extname[ BUFSIZ ]; 593192Smckusick # endif PC 603192Smckusick 613192Smckusick cntstat = 0; 623192Smckusick /* 633192Smckusick * yyoutline(); 643192Smckusick */ 653192Smckusick if (program != NIL) 663192Smckusick line = program->value[3]; 673192Smckusick blk = bundle[2]; 683192Smckusick if (fp == NIL) { 693192Smckusick cbn--; 703192Smckusick # ifdef PTREE 713192Smckusick nesting--; 723192Smckusick # endif PTREE 733192Smckusick return; 743192Smckusick } 753192Smckusick #ifdef OBJ 763192Smckusick /* 773192Smckusick * Patch the branch to the 783192Smckusick * entry point of the function 793192Smckusick */ 803192Smckusick patch4(fp->entloc); 813192Smckusick /* 823192Smckusick * Put out the block entrance code and the block name. 833192Smckusick * HDRSZE is the number of bytes of info in the static 843192Smckusick * BEG data area exclusive of the proc name. It is 853192Smckusick * currently defined as: 863192Smckusick /* struct hdr { 873192Smckusick /* long framesze; /* number of bytes of local vars */ 883192Smckusick /* long nargs; /* number of bytes of arguments */ 893192Smckusick /* bool tests; /* TRUE => perform runtime tests */ 903192Smckusick /* short offset; /* offset of procedure in source file */ 913192Smckusick /* char name[1]; /* name of active procedure */ 923192Smckusick /* }; 933192Smckusick */ 943192Smckusick # define HDRSZE (2 * sizeof(long) + sizeof(short) + sizeof(bool)) 953192Smckusick var = put(2, ((lenstr(fp->symbol,0) + HDRSZE) << 8) 963192Smckusick | (cbn == 1 && opt('p') == 0 ? O_NODUMP: O_BEG), (long)0); 973192Smckusick /* 983192Smckusick * output the number of bytes of arguments 993192Smckusick * this is only checked on formal calls. 1003192Smckusick */ 1013192Smckusick put(2, O_CASE4, cbn == 1 ? (long)0 : (long)(fp->value[NL_OFFS]-DPOFF2)); 1023192Smckusick /* 1033192Smckusick * Output the runtime test mode for the routine 1043192Smckusick */ 1053192Smckusick put(2, sizeof(bool) == 2 ? O_CASE2 : O_CASE4, opt('t') ? TRUE : FALSE); 1063192Smckusick /* 1073192Smckusick * Output line number and routine name 1083192Smckusick */ 1093192Smckusick put(2, O_CASE2, bundle[1]); 1103192Smckusick putstr(fp->symbol, 0); 1113192Smckusick #endif OBJ 1123192Smckusick #ifdef PC 1133192Smckusick /* 1143192Smckusick * put out the procedure entry code 1153192Smckusick */ 1163192Smckusick if ( fp -> class == PROG ) { 1173192Smckusick putprintf( " .text" , 0 ); 1183192Smckusick putprintf( " .align 1" , 0 ); 1193192Smckusick putprintf( " .globl _main" , 0 ); 1203192Smckusick putprintf( "_main:" , 0 ); 1213192Smckusick putprintf( " .word 0" , 0 ); 1223192Smckusick putprintf( " calls $0,_PCSTART" , 0 ); 1233192Smckusick putprintf( " movl 4(ap),__argc" , 0 ); 1243192Smckusick putprintf( " movl 8(ap),__argv" , 0 ); 1253192Smckusick putprintf( " calls $0,_program" , 0 ); 1263192Smckusick putprintf( " calls $0,_PCEXIT" , 0 ); 1273192Smckusick ftnno = fp -> entloc; 1283192Smckusick putprintf( " .text" , 0 ); 1293192Smckusick putprintf( " .align 1" , 0 ); 1303192Smckusick putprintf( " .globl _program" , 0 ); 1313192Smckusick putprintf( "_program:" , 0 ); 1323192Smckusick stabfunc( "program" , fp -> class , bundle[1] , 0 ); 1333192Smckusick } else { 1343192Smckusick ftnno = fp -> entloc; 1353192Smckusick putprintf( " .text" , 0 ); 1363192Smckusick putprintf( " .align 1" , 0 ); 1373367Speter sextname( extname , fp -> symbol , cbn - 1 ); 138*3428Speter putprintf( " .globl %s%s" , 0 , FORMALPREFIX , extname ); 1393363Speter putprintf( " .globl %s" , 0 , extname ); 1403363Speter putprintf( "%s:" , 0 , extname ); 1413192Smckusick stabfunc( fp -> symbol , fp -> class , bundle[1] , cbn - 1 ); 1423192Smckusick for ( p = fp -> chain ; p != NIL ; p = p -> chain ) { 1433192Smckusick stabparam( p -> symbol , p2type( p -> type ) 1443192Smckusick , p -> value[ NL_OFFS ] , lwidth( p -> type ) ); 1453192Smckusick } 1463192Smckusick if ( fp -> class == FUNC ) { 1473192Smckusick /* 1483192Smckusick * stab the function variable 1493192Smckusick */ 1503192Smckusick p = fp -> ptr[ NL_FVAR ]; 1513192Smckusick stablvar( p -> symbol , p2type( p -> type ) , cbn 1523192Smckusick , p -> value[ NL_OFFS ] , lwidth( p -> type ) ); 1533192Smckusick } 1543192Smckusick /* 1553192Smckusick * stab local variables 1563192Smckusick * rummage down hash chain links. 1573192Smckusick */ 1583192Smckusick for ( i = 0 ; i <= 077 ; i++ ) { 1593192Smckusick for ( p = disptab[ i ] ; p != NIL ; p = p->nl_next) { 1603192Smckusick if ( ( p -> nl_block & 037 ) != cbn ) { 1613192Smckusick break; 1623192Smckusick } 1633192Smckusick /* 1643192Smckusick * stab local variables 1653192Smckusick * that's named variables, but not params 1663192Smckusick */ 1673192Smckusick if ( ( p -> symbol != NIL ) 1683192Smckusick && ( p -> class == VAR ) 1693192Smckusick && ( p -> value[ NL_OFFS ] < 0 ) ) { 1703192Smckusick stablvar( p -> symbol , p2type( p -> type ) , cbn 1713192Smckusick , p -> value[ NL_OFFS ] , lwidth( p -> type ) ); 1723192Smckusick } 1733192Smckusick } 1743192Smckusick } 1753192Smckusick } 1763192Smckusick stablbrac( cbn ); 1773192Smckusick /* 1783192Smckusick * register save mask 1793192Smckusick */ 1803279Smckusic putprintf( " .word " , 1 ); 1813279Smckusic putprintf( PREFIXFORMAT , 0 , LABELPREFIX , savlabel ); 1823192Smckusick putjbr( botlabel ); 1833192Smckusick putlab( toplabel ); 1843192Smckusick if ( profflag ) { 1853192Smckusick /* 1863192Smckusick * call mcount for profiling 1873192Smckusick */ 1883192Smckusick putprintf( " moval 1f,r0" , 0 ); 1893192Smckusick putprintf( " jsb mcount" , 0 ); 1903192Smckusick putprintf( " .data" , 0 ); 1913192Smckusick putprintf( " .align 2" , 0 ); 1923192Smckusick putprintf( "1:" , 0 ); 1933192Smckusick putprintf( " .long 0" , 0 ); 1943192Smckusick putprintf( " .text" , 0 ); 1953192Smckusick } 1963192Smckusick /* 1973192Smckusick * set up unwind exception vector. 1983192Smckusick */ 1993192Smckusick putprintf( " moval %s,%d(%s)" , 0 2003192Smckusick , UNWINDNAME , UNWINDOFFSET , P2FPNAME ); 2013192Smckusick /* 2023192Smckusick * save address of display entry, for unwind. 2033192Smckusick */ 2043192Smckusick putprintf( " moval %s+%d,%d(%s)" , 0 2053192Smckusick , DISPLAYNAME , cbn * sizeof(struct dispsave) 2063192Smckusick , DPTROFFSET , P2FPNAME ); 2073192Smckusick /* 2083192Smckusick * save old display 2093192Smckusick */ 2103192Smckusick putprintf( " movq %s+%d,%d(%s)" , 0 2113192Smckusick , DISPLAYNAME , cbn * sizeof(struct dispsave) 2123192Smckusick , DSAVEOFFSET , P2FPNAME ); 2133192Smckusick /* 2143192Smckusick * set up new display by saving AP and FP in appropriate 2153192Smckusick * slot in display structure. 2163192Smckusick */ 2173192Smckusick putprintf( " movq %s,%s+%d" , 0 2183192Smckusick , P2APNAME , DISPLAYNAME , cbn * sizeof(struct dispsave) ); 2193192Smckusick /* 2203192Smckusick * ask second pass to allocate known locals 2213192Smckusick */ 2223192Smckusick putlbracket( ftnno , -sizes[ cbn ].om_max ); 2233192Smckusick /* 2243192Smckusick * and zero them if checking is on 2253192Smckusick * by calling blkclr( bytes of locals , starting local address ); 2263192Smckusick */ 2273301Smckusic if ( opt( 't' ) && ( -sizes[ cbn ].om_max ) > DPOFF1 ) { 2283301Smckusic putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) 2293301Smckusic , "_blkclr" ); 2303301Smckusic putleaf( P2ICON , ( -sizes[ cbn ].om_max ) - DPOFF1 2313301Smckusic , 0 , P2INT , 0 ); 2323301Smckusic putLV( 0 , cbn , sizes[ cbn ].om_max , P2CHAR ); 2333301Smckusic putop( P2LISTOP , P2INT ); 2343301Smckusic putop( P2CALL , P2INT ); 2353301Smckusic putdot( filename , line ); 2363192Smckusick } 2373192Smckusick #endif PC 2383192Smckusick if ( monflg ) { 2393192Smckusick if ( fp -> value[ NL_CNTR ] != 0 ) { 2403192Smckusick inccnt( fp -> value [ NL_CNTR ] ); 2413192Smckusick } 2423192Smckusick inccnt( bodycnts[ fp -> nl_block & 037 ] ); 2433192Smckusick } 2443192Smckusick if (fp->class == PROG) { 2453192Smckusick /* 2463192Smckusick * The glorious buffers option. 2473192Smckusick * 0 = don't buffer output 2483192Smckusick * 1 = line buffer output 2493192Smckusick * 2 = 512 byte buffer output 2503192Smckusick */ 2513192Smckusick # ifdef OBJ 2523192Smckusick if (opt('b') != 1) 2533192Smckusick put(1, O_BUFF | opt('b') << 8); 2543192Smckusick # endif OBJ 2553192Smckusick # ifdef PC 2563192Smckusick if ( opt( 'b' ) != 1 ) { 2573192Smckusick putleaf( P2ICON , 0 , 0 2583192Smckusick , ADDTYPE( P2FTN | P2INT , P2PTR ) , "_BUFF" ); 2593192Smckusick putleaf( P2ICON , opt( 'b' ) , 0 , P2INT , 0 ); 2603192Smckusick putop( P2CALL , P2INT ); 2613192Smckusick putdot( filename , line ); 2623192Smckusick } 2633192Smckusick # endif PC 2643192Smckusick out = 0; 2653192Smckusick for (p = fp->chain; p != NIL; p = p->chain) { 2663192Smckusick if (strcmp(p->symbol, "input") == 0) { 2673192Smckusick inp++; 2683192Smckusick continue; 2693192Smckusick } 2703192Smckusick if (strcmp(p->symbol, "output") == 0) { 2713192Smckusick out++; 2723192Smckusick continue; 2733192Smckusick } 2743192Smckusick iop = lookup1(p->symbol); 2753192Smckusick if (iop == NIL || bn != cbn) { 2763192Smckusick error("File %s listed in program statement but not declared", p->symbol); 2773192Smckusick continue; 2783192Smckusick } 2793192Smckusick if (iop->class != VAR) { 2803192Smckusick error("File %s listed in program statement but declared as a %s", p->symbol, classes[iop->class]); 2813192Smckusick continue; 2823192Smckusick } 2833192Smckusick if (iop->type == NIL) 2843192Smckusick continue; 2853192Smckusick if (iop->type->class != FILET) { 2863192Smckusick error("File %s listed in program statement but defined as %s", 2873192Smckusick p->symbol, nameof(iop->type)); 2883192Smckusick continue; 2893192Smckusick } 2903192Smckusick # ifdef OBJ 2913192Smckusick put(2, O_CON24, text(iop->type) ? 0 : width(iop->type->type)); 2923192Smckusick i = lenstr(p->symbol,0); 2933192Smckusick put(2, O_CON24, i); 2943192Smckusick put(2, O_LVCON, i); 2953192Smckusick putstr(p->symbol, 0); 2963192Smckusick put(2, O_LV | bn<<8+INDX, (int)iop->value[NL_OFFS]); 2973192Smckusick put(1, O_DEFNAME); 2983192Smckusick # endif OBJ 2993192Smckusick # ifdef PC 3003192Smckusick putleaf( P2ICON , 0 , 0 3013192Smckusick , ADDTYPE( P2FTN | P2INT , P2PTR ) 3023192Smckusick , "_DEFNAME" ); 3033192Smckusick putLV( p -> symbol , bn , iop -> value[NL_OFFS] 3043192Smckusick , p2type( iop ) ); 3053192Smckusick putCONG( p -> symbol , strlen( p -> symbol ) 3063192Smckusick , LREQ ); 3073192Smckusick putop( P2LISTOP , P2INT ); 3083192Smckusick putleaf( P2ICON , strlen( p -> symbol ) 3093192Smckusick , 0 , P2INT , 0 ); 3103192Smckusick putop( P2LISTOP , P2INT ); 3113192Smckusick putleaf( P2ICON 3123192Smckusick , text(iop->type) ? 0 : width(iop->type->type) 3133192Smckusick , 0 , P2INT , 0 ); 3143192Smckusick putop( P2LISTOP , P2INT ); 3153192Smckusick putop( P2CALL , P2INT ); 3163192Smckusick putdot( filename , line ); 3173192Smckusick # endif PC 3183192Smckusick } 3193192Smckusick if (out == 0 && fp->chain != NIL) { 3203192Smckusick recovered(); 3213192Smckusick error("The file output must appear in the program statement file list"); 3223192Smckusick } 3233192Smckusick } 3243192Smckusick /* 3253192Smckusick * Process the prog/proc/func body 3263192Smckusick */ 3273192Smckusick noreach = 0; 3283192Smckusick line = bundle[1]; 3293192Smckusick statlist(blk); 3303192Smckusick # ifdef PTREE 3313192Smckusick { 3323192Smckusick pPointer Body = tCopy( blk ); 3333192Smckusick 3343192Smckusick pDEF( PorFHeader[ nesting -- ] ).PorFBody = Body; 3353192Smckusick } 3363192Smckusick # endif PTREE 3373192Smckusick # ifdef OBJ 3383192Smckusick if (cbn== 1 && monflg != 0) { 3393192Smckusick patchfil(cntpatch - 2, (long)cnts, 2); 3403192Smckusick patchfil(nfppatch - 2, (long)pfcnt, 2); 3413192Smckusick } 3423192Smckusick # endif OBJ 3433192Smckusick # ifdef PC 3443192Smckusick if ( fp -> class == PROG && monflg ) { 3453192Smckusick putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) 3463192Smckusick , "_PMFLUSH" ); 3473192Smckusick putleaf( P2ICON , cnts , 0 , P2INT , 0 ); 3483192Smckusick putleaf( P2ICON , pfcnt , 0 , P2INT , 0 ); 3493192Smckusick putop( P2LISTOP , P2INT ); 3503192Smckusick putLV( PCPCOUNT , 0 , 0 , P2INT ); 3513192Smckusick putop( P2LISTOP , P2INT ); 3523192Smckusick putop( P2CALL , P2INT ); 3533192Smckusick putdot( filename , line ); 3543192Smckusick } 3553192Smckusick # endif PC 3563192Smckusick if (fp->class == PROG && inp == 0 && (input->nl_flags & (NUSED|NMOD)) != 0) { 3573192Smckusick recovered(); 3583192Smckusick error("Input is used but not defined in the program statement"); 3593192Smckusick } 3603192Smckusick /* 3613192Smckusick * Clean up the symbol table displays and check for unresolves 3623192Smckusick */ 3633192Smckusick line = endline; 3643192Smckusick b = cbn; 3653192Smckusick Fp = fp; 3663192Smckusick chkref = syneflg == errcnt[cbn] && opt('w') == 0; 3673192Smckusick for (i = 0; i <= 077; i++) { 3683192Smckusick for (p = disptab[i]; p != NIL && (p->nl_block & 037) == b; p = p->nl_next) { 3693192Smckusick /* 3703192Smckusick * Check for variables defined 3713192Smckusick * but not referenced 3723192Smckusick */ 3733192Smckusick if (chkref && p->symbol != NIL) 3743192Smckusick switch (p->class) { 3753192Smckusick case FIELD: 3763192Smckusick /* 3773192Smckusick * If the corresponding record is 3783192Smckusick * unused, we shouldn't complain about 3793192Smckusick * the fields. 3803192Smckusick */ 3813192Smckusick default: 3823192Smckusick if ((p->nl_flags & (NUSED|NMOD)) == 0) { 3833192Smckusick warning(); 3843192Smckusick nerror("%s %s is neither used nor set", classes[p->class], p->symbol); 3853192Smckusick break; 3863192Smckusick } 3873192Smckusick /* 3883192Smckusick * If a var parameter is either 3893192Smckusick * modified or used that is enough. 3903192Smckusick */ 3913192Smckusick if (p->class == REF) 3923192Smckusick continue; 3933192Smckusick # ifdef OBJ 3943192Smckusick if ((p->nl_flags & NUSED) == 0) { 3953192Smckusick warning(); 3963192Smckusick nerror("%s %s is never used", classes[p->class], p->symbol); 3973192Smckusick break; 3983192Smckusick } 3993192Smckusick # endif OBJ 4003192Smckusick # ifdef PC 4013192Smckusick if (((p->nl_flags & NUSED) == 0) && ((p->ext_flags & NEXTERN) == 0)) { 4023192Smckusick warning(); 4033192Smckusick nerror("%s %s is never used", classes[p->class], p->symbol); 4043192Smckusick break; 4053192Smckusick } 4063192Smckusick # endif PC 4073192Smckusick if ((p->nl_flags & NMOD) == 0) { 4083192Smckusick warning(); 4093192Smckusick nerror("%s %s is used but never set", classes[p->class], p->symbol); 4103192Smckusick break; 4113192Smckusick } 4123192Smckusick case LABEL: 4133192Smckusick case FVAR: 4143192Smckusick case BADUSE: 4153192Smckusick break; 4163192Smckusick } 4173192Smckusick switch (p->class) { 4183192Smckusick case BADUSE: 4193192Smckusick cp = "s"; 4203192Smckusick if (p->chain->ud_next == NIL) 4213192Smckusick cp++; 4223192Smckusick eholdnl(); 4233192Smckusick if (p->value[NL_KINDS] & ISUNDEF) 4243192Smckusick nerror("%s undefined on line%s", p->symbol, cp); 4253192Smckusick else 4263192Smckusick nerror("%s improperly used on line%s", p->symbol, cp); 4273192Smckusick pnumcnt = 10; 4283192Smckusick pnums(p->chain); 4293192Smckusick pchr('\n'); 4303192Smckusick break; 4313192Smckusick 4323192Smckusick case FUNC: 4333192Smckusick case PROC: 4343192Smckusick # ifdef OBJ 4353192Smckusick if ((p->nl_flags & NFORWD)) 4363192Smckusick nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol); 4373192Smckusick # endif OBJ 4383192Smckusick # ifdef PC 4393192Smckusick if ((p->nl_flags & NFORWD) && ((p->ext_flags & NEXTERN) == 0)) 4403192Smckusick nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol); 4413192Smckusick # endif PC 4423192Smckusick break; 4433192Smckusick 4443192Smckusick case LABEL: 4453192Smckusick if (p->nl_flags & NFORWD) 4463192Smckusick nerror("label %s was declared but not defined", p->symbol); 4473192Smckusick break; 4483192Smckusick case FVAR: 4493192Smckusick if ((p->nl_flags & NMOD) == 0) 4503192Smckusick nerror("No assignment to the function variable"); 4513192Smckusick break; 4523192Smckusick } 4533192Smckusick } 4543192Smckusick /* 4553192Smckusick * Pop this symbol 4563192Smckusick * table slot 4573192Smckusick */ 4583192Smckusick disptab[i] = p; 4593192Smckusick } 4603192Smckusick 4613192Smckusick # ifdef OBJ 4623192Smckusick put(1, O_END); 4633192Smckusick # endif OBJ 4643192Smckusick # ifdef PC 4653192Smckusick /* 4663192Smckusick * if there were file variables declared at this level 4673192Smckusick * call pclose( &__disply[ cbn ] ) to clean them up. 4683192Smckusick */ 4693192Smckusick if ( dfiles[ cbn ] ) { 4703192Smckusick putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) 4713192Smckusick , "_PCLOSE" ); 4723192Smckusick putRV( DISPLAYNAME , 0 , cbn * sizeof( struct dispsave ) 4733192Smckusick , P2PTR | P2CHAR ); 4743192Smckusick putop( P2CALL , P2INT ); 4753192Smckusick putdot( filename , line ); 4763192Smckusick } 4773192Smckusick /* 4783192Smckusick * if this is a function, 4793192Smckusick * the function variable is the return value. 4803192Smckusick * if it's a scalar valued function, return scalar, 4813192Smckusick * else, return a pointer to the structure value. 4823192Smckusick */ 4833192Smckusick if ( fp -> class == FUNC ) { 4843192Smckusick struct nl *fvar = fp -> ptr[ NL_FVAR ]; 4853192Smckusick long fvartype = p2type( fvar -> type ); 4863192Smckusick long label; 4873192Smckusick char labelname[ BUFSIZ ]; 4883192Smckusick 4893192Smckusick switch ( classify( fvar -> type ) ) { 4903192Smckusick case TBOOL: 4913192Smckusick case TCHAR: 4923192Smckusick case TINT: 4933192Smckusick case TSCAL: 4943192Smckusick case TDOUBLE: 4953192Smckusick case TPTR: 4963192Smckusick putRV( fvar -> symbol , ( fvar -> nl_block ) & 037 4973192Smckusick , fvar -> value[ NL_OFFS ] , fvartype ); 4983192Smckusick break; 4993192Smckusick default: 5003192Smckusick label = getlab(); 5013192Smckusick sprintf( labelname , PREFIXFORMAT , 5023192Smckusick LABELPREFIX , label ); 5033192Smckusick putprintf( " .data" , 0 ); 5043192Smckusick putprintf( " .lcomm %s,%d" , 0 , 5053192Smckusick labelname , lwidth( fvar -> type ) ); 5063192Smckusick putprintf( " .text" , 0 ); 5073192Smckusick putleaf( P2NAME , 0 , 0 , fvartype , labelname ); 5083192Smckusick putLV( fvar -> symbol , ( fvar -> nl_block ) & 037 5093192Smckusick , fvar -> value[ NL_OFFS ] , fvartype ); 5103192Smckusick putstrop( P2STASG , fvartype , lwidth( fvar -> type ) , 5113192Smckusick align( fvar -> type ) ); 5123192Smckusick putdot( filename , line ); 5133192Smckusick putleaf( P2ICON , 0 , 0 , fvartype , labelname ); 5143192Smckusick break; 5153192Smckusick } 5163192Smckusick putop( P2FORCE , fvartype ); 5173192Smckusick putdot( filename , line ); 5183192Smckusick } 5193192Smckusick /* 5203192Smckusick * restore old display entry from save area 5213192Smckusick */ 5223192Smckusick 5233192Smckusick putprintf( " movq %d(%s),%s+%d" , 0 5243192Smckusick , DSAVEOFFSET , P2FPNAME 5253192Smckusick , DISPLAYNAME , cbn * sizeof(struct dispsave) ); 5263192Smckusick stabrbrac( cbn ); 5273192Smckusick putprintf( " ret" , 0 ); 5283192Smckusick /* 5293192Smckusick * let the second pass allocate locals 5303279Smckusic * and registers 5313192Smckusick */ 5323279Smckusic putprintf( " .set " , 1 ); 5333279Smckusic putprintf( PREFIXFORMAT , 1 , LABELPREFIX , savlabel ); 5343279Smckusic putprintf( ", 0x%x" , 0 , savmask() ); 5353192Smckusick putlab( botlabel ); 5363192Smckusick putprintf( " subl2 $LF%d,sp" , 0 , ftnno ); 5373192Smckusick putrbracket( ftnno ); 5383192Smckusick putjbr( toplabel ); 5393192Smckusick /* 540*3428Speter * put down the entry point for formal calls 541*3428Speter * the arguments for FCALL have been passed to us 542*3428Speter * as hidden parameters after the regular arguments. 543*3428Speter */ 544*3428Speter if ( fp -> class != PROG ) { 545*3428Speter putprintf( "%s%s:" , 0 , FORMALPREFIX , extname ); 546*3428Speter putprintf( " .word " , 1 ); 547*3428Speter putprintf( PREFIXFORMAT , 0 , LABELPREFIX , savlabel ); 548*3428Speter putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) , 549*3428Speter "_FCALL" ); 550*3428Speter putRV( 0 , cbn , 551*3428Speter fp -> value[ NL_OFFS ] + sizeof( struct formalrtn * ) , 552*3428Speter P2PTR | P2STRTY ); 553*3428Speter putRV( 0 , cbn , fp -> value[ NL_OFFS ] , P2PTR|P2STRTY ); 554*3428Speter putop( P2LISTOP , P2INT ); 555*3428Speter putop( P2CALL , P2INT ); 556*3428Speter putdot( filename , line ); 557*3428Speter putjbr( botlabel ); 558*3428Speter } 559*3428Speter /* 5603192Smckusick * declare pcp counters, if any 5613192Smckusick */ 5623192Smckusick if ( monflg && fp -> class == PROG ) { 5633192Smckusick putprintf( " .data" , 0 ); 5643192Smckusick putprintf( " .comm " , 1 ); 5653192Smckusick putprintf( PCPCOUNT , 1 ); 5663192Smckusick putprintf( ",%d" , 0 , ( cnts + 1 ) * sizeof (long) ); 5673192Smckusick putprintf( " .text" , 0 ); 5683192Smckusick } 5693192Smckusick # endif PC 5703192Smckusick #ifdef DEBUG 5713192Smckusick dumpnl(fp->ptr[2], fp->symbol); 5723192Smckusick #endif 5733192Smckusick /* 5743192Smckusick * Restore the 5753192Smckusick * (virtual) name list 5763192Smckusick * position 5773192Smckusick */ 5783192Smckusick nlfree(fp->ptr[2]); 5793192Smckusick /* 5803192Smckusick * Proc/func has been 5813192Smckusick * resolved 5823192Smckusick */ 5833192Smckusick fp->nl_flags &= ~NFORWD; 5843192Smckusick /* 5853192Smckusick * Patch the beg 5863192Smckusick * of the proc/func to 5873192Smckusick * the proper variable size 5883192Smckusick */ 5893192Smckusick if (Fp == NIL) 5903192Smckusick elineon(); 5913192Smckusick # ifdef OBJ 5923192Smckusick patchfil(var, (long)(-sizes[cbn].om_max), 2); 5933192Smckusick # endif OBJ 5943192Smckusick cbn--; 5953192Smckusick if (inpflist(fp->symbol)) { 5963192Smckusick opop('l'); 5973192Smckusick } 5983192Smckusick } 5993363Speter 6003363Speter #ifdef PC 6013363Speter /* 6023363Speter * construct the long name of a function based on it's static nesting. 6033363Speter * into a caller-supplied buffer (that should be about BUFSIZ big). 6043363Speter */ 6053363Speter sextname( buffer , name , level ) 6063363Speter char buffer[]; 6073363Speter char *name; 6083363Speter int level; 6093363Speter { 6103363Speter char *starthere; 6113363Speter int i; 6123363Speter 6133363Speter starthere = &buffer[0]; 6143363Speter for ( i = 1 ; i < level ; i++ ) { 6153363Speter sprintf( starthere , EXTFORMAT , enclosing[ i ] ); 6163363Speter starthere += strlen( enclosing[ i ] ) + 1; 6173363Speter } 6183367Speter sprintf( starthere , EXTFORMAT , name ); 6193367Speter starthere += strlen( name ) + 1; 6203363Speter if ( starthere >= &buffer[ BUFSIZ ] ) { 6213363Speter panic( "sextname" ); 6223363Speter } 6233363Speter } 6243363Speter #endif PC 625