13192Smckusick /* Copyright (c) 1979 Regents of the University of California */ 23192Smckusick 3*3363Speter static char sccsid[] = "@(#)fend.c 1.4 03/24/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 55*3363Speter int savlabel = getlab(); 56*3363Speter int toplabel = getlab(); 57*3363Speter int botlabel = getlab(); 58*3363Speter 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 ); 137*3363Speter sextname( extname , fp -> symbol , cbn ); 138*3363Speter putprintf( " .globl %s" , 0 , extname ); 139*3363Speter putprintf( "%s:" , 0 , extname ); 1403192Smckusick stabfunc( fp -> symbol , fp -> class , bundle[1] , cbn - 1 ); 1413192Smckusick for ( p = fp -> chain ; p != NIL ; p = p -> chain ) { 1423192Smckusick stabparam( p -> symbol , p2type( p -> type ) 1433192Smckusick , p -> value[ NL_OFFS ] , lwidth( p -> type ) ); 1443192Smckusick } 1453192Smckusick if ( fp -> class == FUNC ) { 1463192Smckusick /* 1473192Smckusick * stab the function variable 1483192Smckusick */ 1493192Smckusick p = fp -> ptr[ NL_FVAR ]; 1503192Smckusick stablvar( p -> symbol , p2type( p -> type ) , cbn 1513192Smckusick , p -> value[ NL_OFFS ] , lwidth( p -> type ) ); 1523192Smckusick } 1533192Smckusick /* 1543192Smckusick * stab local variables 1553192Smckusick * rummage down hash chain links. 1563192Smckusick */ 1573192Smckusick for ( i = 0 ; i <= 077 ; i++ ) { 1583192Smckusick for ( p = disptab[ i ] ; p != NIL ; p = p->nl_next) { 1593192Smckusick if ( ( p -> nl_block & 037 ) != cbn ) { 1603192Smckusick break; 1613192Smckusick } 1623192Smckusick /* 1633192Smckusick * stab local variables 1643192Smckusick * that's named variables, but not params 1653192Smckusick */ 1663192Smckusick if ( ( p -> symbol != NIL ) 1673192Smckusick && ( p -> class == VAR ) 1683192Smckusick && ( p -> value[ NL_OFFS ] < 0 ) ) { 1693192Smckusick stablvar( p -> symbol , p2type( p -> type ) , cbn 1703192Smckusick , p -> value[ NL_OFFS ] , lwidth( p -> type ) ); 1713192Smckusick } 1723192Smckusick } 1733192Smckusick } 1743192Smckusick } 1753192Smckusick stablbrac( cbn ); 1763192Smckusick /* 1773192Smckusick * register save mask 1783192Smckusick */ 1793279Smckusic putprintf( " .word " , 1 ); 1803279Smckusic putprintf( PREFIXFORMAT , 0 , LABELPREFIX , savlabel ); 1813192Smckusick putjbr( botlabel ); 1823192Smckusick putlab( toplabel ); 1833192Smckusick if ( profflag ) { 1843192Smckusick /* 1853192Smckusick * call mcount for profiling 1863192Smckusick */ 1873192Smckusick putprintf( " moval 1f,r0" , 0 ); 1883192Smckusick putprintf( " jsb mcount" , 0 ); 1893192Smckusick putprintf( " .data" , 0 ); 1903192Smckusick putprintf( " .align 2" , 0 ); 1913192Smckusick putprintf( "1:" , 0 ); 1923192Smckusick putprintf( " .long 0" , 0 ); 1933192Smckusick putprintf( " .text" , 0 ); 1943192Smckusick } 1953192Smckusick /* 1963192Smckusick * set up unwind exception vector. 1973192Smckusick */ 1983192Smckusick putprintf( " moval %s,%d(%s)" , 0 1993192Smckusick , UNWINDNAME , UNWINDOFFSET , P2FPNAME ); 2003192Smckusick /* 2013192Smckusick * save address of display entry, for unwind. 2023192Smckusick */ 2033192Smckusick putprintf( " moval %s+%d,%d(%s)" , 0 2043192Smckusick , DISPLAYNAME , cbn * sizeof(struct dispsave) 2053192Smckusick , DPTROFFSET , P2FPNAME ); 2063192Smckusick /* 2073192Smckusick * save old display 2083192Smckusick */ 2093192Smckusick putprintf( " movq %s+%d,%d(%s)" , 0 2103192Smckusick , DISPLAYNAME , cbn * sizeof(struct dispsave) 2113192Smckusick , DSAVEOFFSET , P2FPNAME ); 2123192Smckusick /* 2133192Smckusick * set up new display by saving AP and FP in appropriate 2143192Smckusick * slot in display structure. 2153192Smckusick */ 2163192Smckusick putprintf( " movq %s,%s+%d" , 0 2173192Smckusick , P2APNAME , DISPLAYNAME , cbn * sizeof(struct dispsave) ); 2183192Smckusick /* 2193192Smckusick * ask second pass to allocate known locals 2203192Smckusick */ 2213192Smckusick putlbracket( ftnno , -sizes[ cbn ].om_max ); 2223192Smckusick /* 2233192Smckusick * and zero them if checking is on 2243192Smckusick * by calling blkclr( bytes of locals , starting local address ); 2253192Smckusick */ 2263301Smckusic if ( opt( 't' ) && ( -sizes[ cbn ].om_max ) > DPOFF1 ) { 2273301Smckusic putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) 2283301Smckusic , "_blkclr" ); 2293301Smckusic putleaf( P2ICON , ( -sizes[ cbn ].om_max ) - DPOFF1 2303301Smckusic , 0 , P2INT , 0 ); 2313301Smckusic putLV( 0 , cbn , sizes[ cbn ].om_max , P2CHAR ); 2323301Smckusic putop( P2LISTOP , P2INT ); 2333301Smckusic putop( P2CALL , P2INT ); 2343301Smckusic putdot( filename , line ); 2353192Smckusick } 2363192Smckusick #endif PC 2373192Smckusick if ( monflg ) { 2383192Smckusick if ( fp -> value[ NL_CNTR ] != 0 ) { 2393192Smckusick inccnt( fp -> value [ NL_CNTR ] ); 2403192Smckusick } 2413192Smckusick inccnt( bodycnts[ fp -> nl_block & 037 ] ); 2423192Smckusick } 2433192Smckusick if (fp->class == PROG) { 2443192Smckusick /* 2453192Smckusick * The glorious buffers option. 2463192Smckusick * 0 = don't buffer output 2473192Smckusick * 1 = line buffer output 2483192Smckusick * 2 = 512 byte buffer output 2493192Smckusick */ 2503192Smckusick # ifdef OBJ 2513192Smckusick if (opt('b') != 1) 2523192Smckusick put(1, O_BUFF | opt('b') << 8); 2533192Smckusick # endif OBJ 2543192Smckusick # ifdef PC 2553192Smckusick if ( opt( 'b' ) != 1 ) { 2563192Smckusick putleaf( P2ICON , 0 , 0 2573192Smckusick , ADDTYPE( P2FTN | P2INT , P2PTR ) , "_BUFF" ); 2583192Smckusick putleaf( P2ICON , opt( 'b' ) , 0 , P2INT , 0 ); 2593192Smckusick putop( P2CALL , P2INT ); 2603192Smckusick putdot( filename , line ); 2613192Smckusick } 2623192Smckusick # endif PC 2633192Smckusick out = 0; 2643192Smckusick for (p = fp->chain; p != NIL; p = p->chain) { 2653192Smckusick if (strcmp(p->symbol, "input") == 0) { 2663192Smckusick inp++; 2673192Smckusick continue; 2683192Smckusick } 2693192Smckusick if (strcmp(p->symbol, "output") == 0) { 2703192Smckusick out++; 2713192Smckusick continue; 2723192Smckusick } 2733192Smckusick iop = lookup1(p->symbol); 2743192Smckusick if (iop == NIL || bn != cbn) { 2753192Smckusick error("File %s listed in program statement but not declared", p->symbol); 2763192Smckusick continue; 2773192Smckusick } 2783192Smckusick if (iop->class != VAR) { 2793192Smckusick error("File %s listed in program statement but declared as a %s", p->symbol, classes[iop->class]); 2803192Smckusick continue; 2813192Smckusick } 2823192Smckusick if (iop->type == NIL) 2833192Smckusick continue; 2843192Smckusick if (iop->type->class != FILET) { 2853192Smckusick error("File %s listed in program statement but defined as %s", 2863192Smckusick p->symbol, nameof(iop->type)); 2873192Smckusick continue; 2883192Smckusick } 2893192Smckusick # ifdef OBJ 2903192Smckusick put(2, O_CON24, text(iop->type) ? 0 : width(iop->type->type)); 2913192Smckusick i = lenstr(p->symbol,0); 2923192Smckusick put(2, O_CON24, i); 2933192Smckusick put(2, O_LVCON, i); 2943192Smckusick putstr(p->symbol, 0); 2953192Smckusick put(2, O_LV | bn<<8+INDX, (int)iop->value[NL_OFFS]); 2963192Smckusick put(1, O_DEFNAME); 2973192Smckusick # endif OBJ 2983192Smckusick # ifdef PC 2993192Smckusick putleaf( P2ICON , 0 , 0 3003192Smckusick , ADDTYPE( P2FTN | P2INT , P2PTR ) 3013192Smckusick , "_DEFNAME" ); 3023192Smckusick putLV( p -> symbol , bn , iop -> value[NL_OFFS] 3033192Smckusick , p2type( iop ) ); 3043192Smckusick putCONG( p -> symbol , strlen( p -> symbol ) 3053192Smckusick , LREQ ); 3063192Smckusick putop( P2LISTOP , P2INT ); 3073192Smckusick putleaf( P2ICON , strlen( p -> symbol ) 3083192Smckusick , 0 , P2INT , 0 ); 3093192Smckusick putop( P2LISTOP , P2INT ); 3103192Smckusick putleaf( P2ICON 3113192Smckusick , text(iop->type) ? 0 : width(iop->type->type) 3123192Smckusick , 0 , P2INT , 0 ); 3133192Smckusick putop( P2LISTOP , P2INT ); 3143192Smckusick putop( P2CALL , P2INT ); 3153192Smckusick putdot( filename , line ); 3163192Smckusick # endif PC 3173192Smckusick } 3183192Smckusick if (out == 0 && fp->chain != NIL) { 3193192Smckusick recovered(); 3203192Smckusick error("The file output must appear in the program statement file list"); 3213192Smckusick } 3223192Smckusick } 3233192Smckusick /* 3243192Smckusick * Process the prog/proc/func body 3253192Smckusick */ 3263192Smckusick noreach = 0; 3273192Smckusick line = bundle[1]; 3283192Smckusick statlist(blk); 3293192Smckusick # ifdef PTREE 3303192Smckusick { 3313192Smckusick pPointer Body = tCopy( blk ); 3323192Smckusick 3333192Smckusick pDEF( PorFHeader[ nesting -- ] ).PorFBody = Body; 3343192Smckusick } 3353192Smckusick # endif PTREE 3363192Smckusick # ifdef OBJ 3373192Smckusick if (cbn== 1 && monflg != 0) { 3383192Smckusick patchfil(cntpatch - 2, (long)cnts, 2); 3393192Smckusick patchfil(nfppatch - 2, (long)pfcnt, 2); 3403192Smckusick } 3413192Smckusick # endif OBJ 3423192Smckusick # ifdef PC 3433192Smckusick if ( fp -> class == PROG && monflg ) { 3443192Smckusick putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) 3453192Smckusick , "_PMFLUSH" ); 3463192Smckusick putleaf( P2ICON , cnts , 0 , P2INT , 0 ); 3473192Smckusick putleaf( P2ICON , pfcnt , 0 , P2INT , 0 ); 3483192Smckusick putop( P2LISTOP , P2INT ); 3493192Smckusick putLV( PCPCOUNT , 0 , 0 , P2INT ); 3503192Smckusick putop( P2LISTOP , P2INT ); 3513192Smckusick putop( P2CALL , P2INT ); 3523192Smckusick putdot( filename , line ); 3533192Smckusick } 3543192Smckusick # endif PC 3553192Smckusick if (fp->class == PROG && inp == 0 && (input->nl_flags & (NUSED|NMOD)) != 0) { 3563192Smckusick recovered(); 3573192Smckusick error("Input is used but not defined in the program statement"); 3583192Smckusick } 3593192Smckusick /* 3603192Smckusick * Clean up the symbol table displays and check for unresolves 3613192Smckusick */ 3623192Smckusick line = endline; 3633192Smckusick b = cbn; 3643192Smckusick Fp = fp; 3653192Smckusick chkref = syneflg == errcnt[cbn] && opt('w') == 0; 3663192Smckusick for (i = 0; i <= 077; i++) { 3673192Smckusick for (p = disptab[i]; p != NIL && (p->nl_block & 037) == b; p = p->nl_next) { 3683192Smckusick /* 3693192Smckusick * Check for variables defined 3703192Smckusick * but not referenced 3713192Smckusick */ 3723192Smckusick if (chkref && p->symbol != NIL) 3733192Smckusick switch (p->class) { 3743192Smckusick case FIELD: 3753192Smckusick /* 3763192Smckusick * If the corresponding record is 3773192Smckusick * unused, we shouldn't complain about 3783192Smckusick * the fields. 3793192Smckusick */ 3803192Smckusick default: 3813192Smckusick if ((p->nl_flags & (NUSED|NMOD)) == 0) { 3823192Smckusick warning(); 3833192Smckusick nerror("%s %s is neither used nor set", classes[p->class], p->symbol); 3843192Smckusick break; 3853192Smckusick } 3863192Smckusick /* 3873192Smckusick * If a var parameter is either 3883192Smckusick * modified or used that is enough. 3893192Smckusick */ 3903192Smckusick if (p->class == REF) 3913192Smckusick continue; 3923192Smckusick # ifdef OBJ 3933192Smckusick if ((p->nl_flags & NUSED) == 0) { 3943192Smckusick warning(); 3953192Smckusick nerror("%s %s is never used", classes[p->class], p->symbol); 3963192Smckusick break; 3973192Smckusick } 3983192Smckusick # endif OBJ 3993192Smckusick # ifdef PC 4003192Smckusick if (((p->nl_flags & NUSED) == 0) && ((p->ext_flags & NEXTERN) == 0)) { 4013192Smckusick warning(); 4023192Smckusick nerror("%s %s is never used", classes[p->class], p->symbol); 4033192Smckusick break; 4043192Smckusick } 4053192Smckusick # endif PC 4063192Smckusick if ((p->nl_flags & NMOD) == 0) { 4073192Smckusick warning(); 4083192Smckusick nerror("%s %s is used but never set", classes[p->class], p->symbol); 4093192Smckusick break; 4103192Smckusick } 4113192Smckusick case LABEL: 4123192Smckusick case FVAR: 4133192Smckusick case BADUSE: 4143192Smckusick break; 4153192Smckusick } 4163192Smckusick switch (p->class) { 4173192Smckusick case BADUSE: 4183192Smckusick cp = "s"; 4193192Smckusick if (p->chain->ud_next == NIL) 4203192Smckusick cp++; 4213192Smckusick eholdnl(); 4223192Smckusick if (p->value[NL_KINDS] & ISUNDEF) 4233192Smckusick nerror("%s undefined on line%s", p->symbol, cp); 4243192Smckusick else 4253192Smckusick nerror("%s improperly used on line%s", p->symbol, cp); 4263192Smckusick pnumcnt = 10; 4273192Smckusick pnums(p->chain); 4283192Smckusick pchr('\n'); 4293192Smckusick break; 4303192Smckusick 4313192Smckusick case FUNC: 4323192Smckusick case PROC: 4333192Smckusick # ifdef OBJ 4343192Smckusick if ((p->nl_flags & NFORWD)) 4353192Smckusick nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol); 4363192Smckusick # endif OBJ 4373192Smckusick # ifdef PC 4383192Smckusick if ((p->nl_flags & NFORWD) && ((p->ext_flags & NEXTERN) == 0)) 4393192Smckusick nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol); 4403192Smckusick # endif PC 4413192Smckusick break; 4423192Smckusick 4433192Smckusick case LABEL: 4443192Smckusick if (p->nl_flags & NFORWD) 4453192Smckusick nerror("label %s was declared but not defined", p->symbol); 4463192Smckusick break; 4473192Smckusick case FVAR: 4483192Smckusick if ((p->nl_flags & NMOD) == 0) 4493192Smckusick nerror("No assignment to the function variable"); 4503192Smckusick break; 4513192Smckusick } 4523192Smckusick } 4533192Smckusick /* 4543192Smckusick * Pop this symbol 4553192Smckusick * table slot 4563192Smckusick */ 4573192Smckusick disptab[i] = p; 4583192Smckusick } 4593192Smckusick 4603192Smckusick # ifdef OBJ 4613192Smckusick put(1, O_END); 4623192Smckusick # endif OBJ 4633192Smckusick # ifdef PC 4643192Smckusick /* 4653192Smckusick * if there were file variables declared at this level 4663192Smckusick * call pclose( &__disply[ cbn ] ) to clean them up. 4673192Smckusick */ 4683192Smckusick if ( dfiles[ cbn ] ) { 4693192Smckusick putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) 4703192Smckusick , "_PCLOSE" ); 4713192Smckusick putRV( DISPLAYNAME , 0 , cbn * sizeof( struct dispsave ) 4723192Smckusick , P2PTR | P2CHAR ); 4733192Smckusick putop( P2CALL , P2INT ); 4743192Smckusick putdot( filename , line ); 4753192Smckusick } 4763192Smckusick /* 4773192Smckusick * if this is a function, 4783192Smckusick * the function variable is the return value. 4793192Smckusick * if it's a scalar valued function, return scalar, 4803192Smckusick * else, return a pointer to the structure value. 4813192Smckusick */ 4823192Smckusick if ( fp -> class == FUNC ) { 4833192Smckusick struct nl *fvar = fp -> ptr[ NL_FVAR ]; 4843192Smckusick long fvartype = p2type( fvar -> type ); 4853192Smckusick long label; 4863192Smckusick char labelname[ BUFSIZ ]; 4873192Smckusick 4883192Smckusick switch ( classify( fvar -> type ) ) { 4893192Smckusick case TBOOL: 4903192Smckusick case TCHAR: 4913192Smckusick case TINT: 4923192Smckusick case TSCAL: 4933192Smckusick case TDOUBLE: 4943192Smckusick case TPTR: 4953192Smckusick putRV( fvar -> symbol , ( fvar -> nl_block ) & 037 4963192Smckusick , fvar -> value[ NL_OFFS ] , fvartype ); 4973192Smckusick break; 4983192Smckusick default: 4993192Smckusick label = getlab(); 5003192Smckusick sprintf( labelname , PREFIXFORMAT , 5013192Smckusick LABELPREFIX , label ); 5023192Smckusick putprintf( " .data" , 0 ); 5033192Smckusick putprintf( " .lcomm %s,%d" , 0 , 5043192Smckusick labelname , lwidth( fvar -> type ) ); 5053192Smckusick putprintf( " .text" , 0 ); 5063192Smckusick putleaf( P2NAME , 0 , 0 , fvartype , labelname ); 5073192Smckusick putLV( fvar -> symbol , ( fvar -> nl_block ) & 037 5083192Smckusick , fvar -> value[ NL_OFFS ] , fvartype ); 5093192Smckusick putstrop( P2STASG , fvartype , lwidth( fvar -> type ) , 5103192Smckusick align( fvar -> type ) ); 5113192Smckusick putdot( filename , line ); 5123192Smckusick putleaf( P2ICON , 0 , 0 , fvartype , labelname ); 5133192Smckusick break; 5143192Smckusick } 5153192Smckusick putop( P2FORCE , fvartype ); 5163192Smckusick putdot( filename , line ); 5173192Smckusick } 5183192Smckusick /* 5193192Smckusick * restore old display entry from save area 5203192Smckusick */ 5213192Smckusick 5223192Smckusick putprintf( " movq %d(%s),%s+%d" , 0 5233192Smckusick , DSAVEOFFSET , P2FPNAME 5243192Smckusick , DISPLAYNAME , cbn * sizeof(struct dispsave) ); 5253192Smckusick stabrbrac( cbn ); 5263192Smckusick putprintf( " ret" , 0 ); 5273192Smckusick /* 5283192Smckusick * let the second pass allocate locals 5293279Smckusic * and registers 5303192Smckusick */ 5313279Smckusic putprintf( " .set " , 1 ); 5323279Smckusic putprintf( PREFIXFORMAT , 1 , LABELPREFIX , savlabel ); 5333279Smckusic putprintf( ", 0x%x" , 0 , savmask() ); 5343192Smckusick putlab( botlabel ); 5353192Smckusick putprintf( " subl2 $LF%d,sp" , 0 , ftnno ); 5363192Smckusick putrbracket( ftnno ); 5373192Smckusick putjbr( toplabel ); 5383192Smckusick /* 5393192Smckusick * declare pcp counters, if any 5403192Smckusick */ 5413192Smckusick if ( monflg && fp -> class == PROG ) { 5423192Smckusick putprintf( " .data" , 0 ); 5433192Smckusick putprintf( " .comm " , 1 ); 5443192Smckusick putprintf( PCPCOUNT , 1 ); 5453192Smckusick putprintf( ",%d" , 0 , ( cnts + 1 ) * sizeof (long) ); 5463192Smckusick putprintf( " .text" , 0 ); 5473192Smckusick } 5483192Smckusick # endif PC 5493192Smckusick #ifdef DEBUG 5503192Smckusick dumpnl(fp->ptr[2], fp->symbol); 5513192Smckusick #endif 5523192Smckusick /* 5533192Smckusick * Restore the 5543192Smckusick * (virtual) name list 5553192Smckusick * position 5563192Smckusick */ 5573192Smckusick nlfree(fp->ptr[2]); 5583192Smckusick /* 5593192Smckusick * Proc/func has been 5603192Smckusick * resolved 5613192Smckusick */ 5623192Smckusick fp->nl_flags &= ~NFORWD; 5633192Smckusick /* 5643192Smckusick * Patch the beg 5653192Smckusick * of the proc/func to 5663192Smckusick * the proper variable size 5673192Smckusick */ 5683192Smckusick if (Fp == NIL) 5693192Smckusick elineon(); 5703192Smckusick # ifdef OBJ 5713192Smckusick patchfil(var, (long)(-sizes[cbn].om_max), 2); 5723192Smckusick # endif OBJ 5733192Smckusick cbn--; 5743192Smckusick if (inpflist(fp->symbol)) { 5753192Smckusick opop('l'); 5763192Smckusick } 5773192Smckusick } 578*3363Speter 579*3363Speter #ifdef PC 580*3363Speter /* 581*3363Speter * construct the long name of a function based on it's static nesting. 582*3363Speter * into a caller-supplied buffer (that should be about BUFSIZ big). 583*3363Speter */ 584*3363Speter sextname( buffer , name , level ) 585*3363Speter char buffer[]; 586*3363Speter char *name; 587*3363Speter int level; 588*3363Speter { 589*3363Speter char *starthere; 590*3363Speter int i; 591*3363Speter 592*3363Speter starthere = &buffer[0]; 593*3363Speter for ( i = 1 ; i < level ; i++ ) { 594*3363Speter sprintf( starthere , EXTFORMAT , enclosing[ i ] ); 595*3363Speter starthere += strlen( enclosing[ i ] ) + 1; 596*3363Speter } 597*3363Speter sprintf( starthere , EXTFORMAT , p -> symbol ); 598*3363Speter starthere += strlen( p -> symbol ) + 1; 599*3363Speter if ( starthere >= &buffer[ BUFSIZ ] ) { 600*3363Speter panic( "sextname" ); 601*3363Speter } 602*3363Speter } 603*3363Speter #endif PC 604