Annotation of researchv10no/cmd/cfront/optcfront/main.c, revision 1.1.1.1

1.1       root        1: /*ident        "@(#)ctrans:src/main.c  1.9" */
                      2: /***********************************************************************
                      3: 
                      4:        C++ source for cfront, the C++ compiler front-end
                      5:        written in the computer science research center of Bell Labs
                      6: 
                      7:        Copyright (c) 1984 AT&T, Inc. All Rights Reserved
                      8:        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC.
                      9: 
                     10: main.c:
                     11: 
                     12:        Initialize global environment
                     13:        Read argument line
                     14:        Start compilation
                     15:        Clean up and exit
                     16: 
                     17: **************************************************************************/
                     18: 
                     19: #ifdef __cplusplus
                     20: #include <stdlib.h>
                     21: #endif
                     22: 
                     23: #include <ctype.h>
                     24: #include <string.h>
                     25: #include <libc.h>
                     26: #include <osfcn.h>
                     27: #include <fstream.h>
                     28: #include "size.h"
                     29: #include "cfront.h"
                     30: #include "tree_dump.h"
                     31: #include "template.h"
                     32: #include "hash.h"
                     33: 
                     34: char* prog_name = "<<AT&T C++ Translator <(3.0)(PT)> 08/08/90>>";
                     35: char* src_file_name = "";
                     36: char* line_format = "\n# %d \"%s\"\n";
                     37: 
                     38: int dump_tree;
                     39: int tree_dump_brief = 0;
                     40: dcn_arg dump_tree_arg;
                     41: 
                     42: #ifdef unix
                     43: #include <signal.h>
                     44: 
                     45: static void core_dump(int = 0)
                     46: {
                     47:        if (error_count)
                     48:                fprintf(stderr,"sorry, cannot recover from previous error\n");
                     49:        else 
                     50:                error('i',"bus error (or something nasty like that)");
                     51:        ext(99);
                     52: }
                     53: #endif
                     54: 
                     55: Plist isf_list;
                     56: Pstmt st_ilist;
                     57: Pstmt st_dlist;
                     58: Ptable sti_tbl;
                     59: Ptable std_tbl;
                     60: Plist stat_mem_list;
                     61: 
                     62: int vtbl_opt = -1;     // how to deal with vtbls:
                     63:                        // -1 static and defined
                     64:                        // 0 external and supposed to be defined elsewhere
                     65:                        // 1 external and defined
                     66: int debug_opt;
                     67: int gplus_opt;         // -g to cc, overrides print optimization 
                     68: int ansi_opt;
                     69: int strict_opt;                // disallow features from the anachronism section
                     70:                        // of the manual
                     71: int warning_opt;       // produce more warnings if set
                     72: bit stmtno = 0;
                     73: 
                     74: extern simpl_init();
                     75: extern typ_init();
                     76: extern syn_init();
                     77: extern lex_init();
                     78: extern error_init();
                     79: 
                     80: char *st_name(char*);  // generates names of static ctor, dtor callers, ptbl_vec
                     81: Pname def_name;                // first definition in file
                     82: Pname pdef_name;       // used with ptbl_vec if function is first definition
                     83: 
                     84: int syn_count = 0; // to set conditional breakpoints to find particular expressions  
                     85: Hash *dumper_node_hash_table;
                     86:   
                     87: void static
                     88: clean_dumper_hash_table() {
                     89:        if(!dumper_node_hash_table) 
                     90:                return;
                     91:        else {
                     92:                HashWalker hi(*dumper_node_hash_table);
                     93:                while(hi.valid ()) {
                     94:                        struct node& n = *(struct node*) hi.key();
                     95:                if(n.permanent == 0 || n.permanent == 3) /* flush deleted nodes */          
                     96:                        dumper_node_hash_table->del(hi.key());
                     97:                hi.advance();                              
                     98:                }                 
                     99:        }     
                    100: }     
                    101:    
                    102: void run()
                    103: /*
                    104:        run the appropriate stages
                    105: */
                    106: {
                    107:        Pname n;
                    108:        templp = new templ_compilation;  // canonical instance
                    109:                                         
                    110: 
                    111:        if(dump_tree) {
                    112:                dumper_node_hash_table =
                    113:                        dump_tree_arg.nodes_seen_hash = new pointer_hash (10000);
                    114:                dump_tree_arg.verbose = dt_recursive_1;
                    115:        }    
                    116: 
                    117:        while (n=syn()) {
                    118:                if (n == Pname(1)) continue;
                    119:                if (n->n_list) PERM(n->tp);
                    120: 
                    121:                DB( if(Rdebug>=1) error('d',"run: syn(): '%s'", n->string););
                    122:                 templp->instantiate_ref_templ();
                    123: 
                    124:                for (Pname nx, nn=n; nn; nn=nx) {
                    125:                        Pname rr;
                    126:                        ++syn_count;
                    127:                        nx = nn->n_list;
                    128:                        nn->n_list = 0;
                    129: 
                    130:                        DB( if(Rdebug>=1) error('d',"run: dcl(): %n, base: %k",nn,nn->base););
                    131: 
                    132:                        if ((rr=nn->dcl(gtbl,EXTERN))==0
                    133:                        || nn->base==0
                    134:                        || error_count) continue;
                    135: 
                    136:                        DB( if(Rdebug>=1) error('d',"run: simpl(): %n",nn););
                    137: 
                    138:                        nn->simpl();
                    139: 
                    140:                        if (error_count) {
                    141:                                if(dump_tree) {
                    142:                                        display_cfront_node (dump_tree_arg, nn);
                    143:                                        *dump_tree_arg.output_stream << "---------------------------\n\n";
                    144:                                }
                    145:                                continue;
                    146:                        }
                    147: 
                    148:                        DB( if(Rdebug>=1) error('d',"run:print(): %n (%k) tp %t",nn,nn->base,nn->tp););
                    149: 
                    150:                        if (nn->base == TNAME)
                    151:                                nn->dcl_print(0);
                    152:                        else {
                    153:                                Ptype t = nn->tp;
                    154:                        llxx:
                    155:                                switch (t->base) {
                    156:                                case TYPE:
                    157:                                        t = Pbase(t)->b_name->tp; goto llxx;
                    158:                                case CLASS:
                    159:                                        DB( if(Rdebug>=1) fprintf(stderr," -- class\n"););
                    160:                                        if (vtbl_opt==1 || gplus_opt) n->dcl_print(0);
                    161:                                        break;
                    162:                                case ENUM:
                    163:                                        DB( if(Rdebug>=1) fprintf(stderr," -- enum\n"););
                    164:                                        Penum(n->tp)->dcl_print(0);
                    165:                                        break;
                    166:                                case FCT:
                    167:                                        DB( if(Rdebug>=1) error('d'," -- fct%n inline %d body %d",nn,Pfct(t)->f_inline,Pfct(t)->body););
                    168:                                        if (Pfct(t)->body==0
                    169:                                        || (debug_opt==0 && Pfct(t)->f_inline && ((n->n_table!=gtbl) || strcmp(nn->string,"main")))
                    170:                                        || Pfct(t)->f_imeasure && Pfct(t)->f_inline==0) break;
                    171:                                        DB( if(Rdebug>=1) error('d',"rr %n inline %d body %d",rr,Pfct(rr->tp)->f_inline,Pfct(rr->tp)->body););
                    172:                                        rr->dcl_print(0);
                    173:                                        break;
                    174:        
                    175:                                default:
                    176:                                        DB( if(Rdebug>=1) error('d'," -- %n tpbase: %k",nn,nn->tp->base););
                    177:                                        // print class def, if appropriate
                    178:                                        // can't use tsizeof() since this may
                    179:                                        // print an error if class isn't defined
                    180:                                        { for(Ptype tx = t;;) {
                    181:                                                switch ( tx->base ) {
                    182:                                                case VEC:
                    183:                                                    tx=Pvec(tx)->typ;
                    184:                                                    continue;
                    185:                                                case TYPE: case COBJ:
                    186:                                                    tx=Pbase(tx)->b_name->tp;
                    187:                                                    continue;
                    188:                                                }
                    189:                                                Pclass cl = Pclass(tx);
                    190:                                                if ( cl->base == CLASS
                    191:                                                &&  (cl->defined&(DEFINED|SIMPLIFIED))
                    192:                                                &&   cl->c_body==1 )
                    193:                                                        cl->dcl_print(0);
                    194:                                                break;
                    195:                                          }
                    196:                                        }
                    197:                                        nn->dcl_print(0);
                    198:                                }
                    199:                        }
                    200: 
                    201:                        if(dump_tree) {
                    202:                                display_cfront_node (dump_tree_arg, nn);
                    203:                                *dump_tree_arg.output_stream << "---------------------------\n\n";
                    204:                        }
                    205: 
                    206:                        if (error_count) continue;
                    207: 
                    208:                        DB( if(Rdebug>=1) error('d',"run: cleanup"););
                    209:                        switch (nn->tp->base) { // clean up
                    210:                        default:
                    211:                        {       
                    212:                                Pexpr i = nn->n_initializer;
                    213:                                DB( if(Rdebug>=1) error('d',"default nn %n i %d",nn,i););
                    214:                                if (i && i!=Pexpr(1)) {
                    215:                                        DEL(i);
                    216:                                        nn->n_initializer = 0;
                    217:                                        if (def_name==0 && rr->n_scope != STATIC) { 
                    218:                                                def_name = rr;
                    219:                                                if (pdef_name == 0) ptbl_init(0);
                    220:                                        }
                    221:                                }
                    222:                                break;
                    223:                        }
                    224: 
                    225:                        case FCT:
                    226:                        {       
                    227:                                Pfct f = Pfct(nn->tp);
                    228:                                DB( if(Rdebug>=1) error('d', "function nn: %n local_class: %d %d", nn, local_class, f->local_class ););
                    229:                                if (f->body
                    230:                                && f->f_inline==0
                    231:                                && f->f_imeasure==0) {
                    232:                                         if ( local_class = f->local_class )  { 
                    233:                                                delete_local();
                    234:                                                local_class = 0;
                    235:                                        }
                    236: 
                    237:                                         if (ansi_opt && f->f_this) {
                    238:                                                 f->f_this->n_table = 0;
                    239:                                                 for (Pname n=f->f_this->n_list; n; n=n->n_list)
                    240:                                                         n->n_table = 0;
                    241:                                         }
                    242: 
                    243:                                        DEL(f->body);
                    244:                                        if (def_name==0) { 
                    245:                                                def_name = rr;
                    246:                                                if (pdef_name == 0) ptbl_init(0);
                    247:                                        }
                    248:                                }
                    249:                                break;
                    250:                        }
                    251: 
                    252:                        case CLASS:
                    253:                        {       Pclass cl = Pclass(nn->tp);
                    254:                                for (Pname px, p=cl->mem_list; p; p=px) {
                    255:                                    px = p->n_list;
                    256:                                    if (p->tp) {
                    257:                                        switch (p->tp->base) {
                    258:                                        case FCT:
                    259:                                        {       Pfct f = (Pfct)p->tp;
                    260:                                                if (f->body) {
                    261:                                                        if (f->f_inline==0
                    262:                                                        && f->f_imeasure==0) {
                    263:                                                                if ( local_class = f->local_class ) {
                    264:                                                                        delete_local();
                    265:                                                                        local_class = 0;
                    266:                                                                }
                    267:                                                                DEL(f->body);
                    268:                                                                f->body = 0;
                    269:                                                        }
                    270:                                                }
                    271:                                        }
                    272:                                        case CLASS:
                    273:                                        case ENUM:
                    274:                                                break;
                    275:                                        case COBJ:
                    276:                                        case EOBJ:
                    277:                                                DEL(p);
                    278:                                                break;
                    279:                                        default:
                    280:                                                delete p;
                    281:                                        }
                    282:                                    } else {
                    283:                                        delete p;
                    284:                                    }
                    285:                                } // for
                    286:                                cl->mem_list = 0;
                    287:                                cl->permanent = 3;
                    288:                                break;
                    289:                        }
                    290:                        }
                    291:                        DEL(nn);
                    292:                }
                    293:                lex_clear();
                    294:                if (dump_tree) clean_dumper_hash_table();
                    295:        }
                    296:        templp->end_of_compilation() ;
                    297: 
                    298:        switch (no_of_undcl) {
                    299:        case 1:         {error('w',"undeclaredF%n called",undcl);}
                    300:        case 0:         break;
                    301:        default:        {error('w',"%d undeclaredFs called; for example%n",no_of_undcl,undcl);}
                    302:        }
                    303: 
                    304:        switch (no_of_badcall) {
                    305:        case 1:         {error('w',"%n declaredWoutAs calledWAs",badcall);}
                    306:        case 0:         break;
                    307:        default:        {error('w',"%d Fs declaredWoutAs calledWAs; for example%n",no_of_badcall,badcall);}
                    308:        }
                    309: 
                    310:        if (error_count) return;
                    311: 
                    312:        int i = 1;
                    313:        for (Pname m=gtbl->get_mem(i); m; m=gtbl->get_mem(++i)) {
                    314:                if (m->base==TNAME
                    315:                || m->n_sto==EXTERN
                    316:                || m->n_stclass == ENUM) continue;
                    317: 
                    318:                Ptype t = m->tp;
                    319:                if (t == 0) continue;
                    320:                switch (t->base) {
                    321:                case CLASS:
                    322:                case ENUM:
                    323:                case OVERLOAD:  continue;
                    324:                case COBJ:
                    325:                //case ANON:
                    326:                case VEC:       break;
                    327:                case FCT:
                    328:                                if (Pfct(t)->f_inline || Pfct(t)->body==0) continue;
                    329:                }
                    330: 
                    331: //error('d',&m->where,"%n %d %d %s",m,m->n_addr_taken,m->n_used,m->n_sto==STATIC?"static":"");
                    332: //xxx doesn't check anon union members as their use bits are set differently
                    333:                if (m->n_addr_taken==0
                    334:                && m->n_used==0
                    335:                && m->n_sto == STATIC) { // (static or anon?)
                    336:                        for(;;) {
                    337: //error('d',&m->where,"  %t tconst(): %d",t,t->tconst());
                    338:                                if(t->base==TYPE) {
                    339:                                        if(t->tconst()) break;
                    340:                                        t=Pbase(t)->b_name->tp;
                    341:                                } else if(t->base==VEC) {
                    342:                                        t=Pvec(t)->typ;
                    343:                                } else {
                    344:                                    if ( t->tconst() == 0 ) {
                    345: //error('d',"m%n tp%t t%t",m,m->tp,t);
                    346:                                        if ( t->base != COBJ )
                    347:                                                error('w',&m->where,"%n defined but not used",m);
                    348:                                        else { Pclass cl;
                    349:                                            cl = Pclass(Pbase(t)->b_name->tp);
                    350:                                            if ( cl->has_ctor()==0 )
                    351:                                                if ( cl->csu == ANON )
                    352:                                                 ; //error('w',&m->where,"anonymous union defined but not used");
                    353:                                                else
                    354:                                                    error('w',&m->where,"%n defined but not used",m);
                    355:                                        }
                    356:                                    } // if const
                    357:                                    break;
                    358:                                }
                    359:                        } // for
                    360:                } // if static and not used
                    361:        }
                    362: 
                    363:         Pname ctor = 0;
                    364:        Pname dtor = 0;
                    365:        --curloc.line;
                    366: 
                    367:        if (st_ilist) { //      make an "init" function;
                    368:                        //      it calls all constructors for static objects
                    369:                DB( if(Rdebug>=1) error('d',"make sti"); );
                    370:                Pname n = new name( st_name("__sti__") );
                    371:                Pfct f = new fct(void_type,0,1);
                    372:                n->tp = f;
                    373:                f->body = new block(st_ilist->where,0,st_ilist);
                    374:        //      f->body->s = st_ilist;
                    375:                f->body->memtbl = sti_tbl;
                    376:                n->n_sto = EXTERN;
                    377:                // assignments here are really initializations:
                    378:                ignore_const++;
                    379:                f->f_linkage = linkage_C;
                    380:                f->sign();
                    381:                (void) n->dcl(gtbl,EXTERN);
                    382:                ignore_const--;
                    383:                n->simpl();
                    384:                n->dcl_print(0);
                    385:                ctor = n;
                    386:        }
                    387: 
                    388:        if (st_dlist) { //      make a "done" function;
                    389:                        //      it calls all destructors for static objects
                    390:                DB( if(Rdebug>=1) error('d',"make std"); );
                    391:                Pname n = new name( st_name("__std__") );
                    392:                Pfct f = new fct(void_type,0,1);
                    393:                n->tp = f;
                    394:                f->body = new block(st_dlist->where,0,st_dlist);
                    395:        //      f->body->s = st_dlist;
                    396:                f->body->memtbl = std_tbl;
                    397:                n->n_sto = EXTERN;
                    398:                f->f_linkage = linkage_C;
                    399:                f->sign();
                    400:                (void) n->dcl(gtbl,EXTERN);
                    401:                n->simpl();
                    402:                n->dcl_print(0);
                    403:                dtor = n;
                    404:        }
                    405: 
                    406: #ifdef PATCH
                    407:                /*For fast load: make a static "__link" */
                    408:        if (ctor || dtor)
                    409:        {
                    410:                printf("static struct __linkl { struct __linkl * next;\n");
                    411:                if ( ansi_opt )
                    412:                        printf("void (*ctor)(); void (*dtor)(); } __link = \n");
                    413:                else
                    414:                        printf("char (*ctor)(); char (*dtor)(); } __link = \n");
                    415:        //      printf("{ (struct __linkl *)0, %s, %s };\n",
                    416:        //              ctor_name ? ctor_name : "0",
                    417:        //              dtor_name ? dtor_name : "0");
                    418:                putstring("{ (struct __linkl *)0, ");
                    419:                if (ctor) ctor->print(); else putch('0');
                    420:                putch(',');
                    421:                if (dtor) dtor->print(); else putch('0');
                    422:                putstring("};\n");
                    423:        }
                    424: #endif
                    425: 
                    426:         DB( if(Rdebug>=1) error( 'd', "run: vlist: %d", vlist ); );
                    427:         do {
                    428:                for (vl* v = vlist; v; v = v->next) v->cl->really_print(v->vt);
                    429:                vlist = 0;
                    430: 
                    431:                for (Plist l=isf_list; l; l=l->l) {
                    432:                        Pname n = l->f;
                    433:                        Pfct f = Pfct(n->tp);
                    434: DB( if(Rdebug>=1)error('d',"isf %n %t f %d addr %d",n,f,f,n->n_addr_taken); );
                    435:                        if (f->base == OVERLOAD) {
                    436:                                n = Pgen(f)->fct_list->f;       // first fct
                    437:                                f = Pfct(n->tp);
                    438:                        }
                    439: 
                    440:                        if (debug_opt==0 && 
                    441:                                n->n_addr_taken) {
                    442:                                f->f_inline = 0;
                    443:                                if (n->n_dcl_printed<2) {
                    444:                                        if (warning_opt)
                    445:                                                error('w',"out-of-line copy of %n created",n);
                    446:                                        n->dcl_print(0);
                    447:                                }
                    448:                        }
                    449:                }
                    450:        } while (vlist);
                    451: 
                    452:        if (strict_opt == 0) { // define static members 
                    453:                // patch for SysV VAX -g linkage botch
                    454:                for (Plist l=stat_mem_list; l; l=l->l) {
                    455:                        Pname n = l->f;
                    456: // error('d',"stat mem %n %d %d ",n,n->n_initializer,n->n_evaluated);
                    457:                        if (n->n_initializer==0 && n->n_evaluated==0) {
                    458:                                Ptype t = n->tp;
                    459:                                n->n_sto = 0;
                    460:                                Pname cn = t->is_cl_obj();
                    461:                                if (cn==0) cn = cl_obj_vec;
                    462:                                if (cn) (void) t->tsizeof();    // be sure to print class
                    463:                                if ((cn && Pclass(cn->tp)->has_ctor())
                    464:                                || t->is_ref())
                    465:                                        ; // force explicit definition
                    466:                                else
                    467:                                        n->dcl_print(0);
                    468:                        }
                    469:                }
                    470:        }
                    471: 
                    472:        i = 1;
                    473:        for (Pname nm=ptbl->get_mem(i); nm; nm=ptbl->get_mem(++i))  {
                    474:                DB( if(Rdebug>=1) error('d',"ptbl anme %s string2 %s key:%k",nm->string==0?"???":nm->string2,nm->string2==0?"???":nm->string2,nm->n_key); );
                    475:                if ( nm->n_key == 0 ) { // ptbl used in file, generate definition
                    476:                        int str1 = (*src_file_name)?strlen(src_file_name)+2:0; // +2 for __
                    477:                        int str2 = strlen(nm->string2) - str1;
                    478:                        char *ps = new char[ str2 + 1 ];
                    479:                        strncpy( ps, nm->string2, str2 ); // grab vtbl name
                    480:                        ps[str2]='\0';
                    481:                        ps[2] = 'v';
                    482:                        fprintf(out_file,"extern struct __mptr %s[];\n",ps);
                    483:                        // fprintf(out_file,"struct __mptr* %s = %s;\n",nm->string2,ps);
                    484:                        ptbl_add_pair(nm->string2,ps);
                    485:                        delete ps;
                    486:                }
                    487:        }
                    488: 
                    489:        ptbl_init(1);
                    490:        curloc.putline();
                    491:        fprintf(out_file,"\n/* the end */\n");
                    492: }
                    493: 
                    494: 
                    495: #ifdef DBG
                    496: int Adebug = 0;
                    497: int Ddebug = 0;
                    498: int Edebug = 0;
                    499: int Ldebug = 0;
                    500: int Mdebug = 0;
                    501: int Ndebug = 0;
                    502: int Pdebug = 0;
                    503: int Rdebug = 0;
                    504: int Sdebug = 0;
                    505: int Tdebug = 0;
                    506: //Ydebug == yydebug initialized in y.tab.c
                    507: void
                    508: process_debug_flags( char* p )
                    509: {
                    510:        // arg to +Dxxx or debugging comments //@!xxx
                    511:        // format of xxx == sequence of any combination of
                    512:        //      +flags  --  increment flags (default)
                    513:        //      -flags  --  decrement flags
                    514:        //      0flags  --  unset flags
                    515:        // where flags are single chars
                    516:        int incr = 1;
                    517:        char c;
                    518:        fprintf(stderr,"\n*** processing debugging flags '%s'\n",p);
                    519:        while ( c = *p++ ) {
                    520:                switch ( c ) {
                    521:                case '+': incr =  1; break;
                    522:                case '-': incr = -1; break;
                    523:                case '0': incr =  0; break;
                    524:                case ' ': break;
                    525:                // flags...
                    526:                case 'A': if(incr==0) Adebug=0; else Adebug+=incr; break;
                    527:                case 'D': if(incr==0) Ddebug=0; else Ddebug+=incr; break;
                    528:                case 'E': if(incr==0) Edebug=0; else Edebug+=incr; break;
                    529:                case 'L': if(incr==0) Ldebug=0; else Ldebug+=incr; break;
                    530:                case 'M': if(incr==0) Mdebug=0; else Mdebug+=incr; break;
                    531:                case 'N': if(incr==0) Ndebug=0; else Ndebug+=incr; break;
                    532:                case 'P': if(incr==0) Pdebug=0; else Pdebug+=incr; break;
                    533:                case 'R': if(incr==0) Rdebug=0; else Rdebug+=incr; break;
                    534:                case 'S': if(incr==0) Sdebug=0; else Sdebug+=incr; break;
                    535:                case 'T': if(incr==0) Tdebug=0; else Tdebug+=incr; break;
                    536:                case 'Y': if(incr==0) Ydebug=0; else Ydebug+=incr; break;
                    537:                default: error('w',"unknown debugging flag '%c'",c);
                    538:                }
                    539:        }
                    540: }
                    541: #endif /*DBG*/
                    542: 
                    543: int no_of_undcl, no_of_badcall;
                    544: Pname undcl, badcall;
                    545: 
                    546: void pt_option(char * ostr) 
                    547: { // options +O[BTo] for PT
                    548:     ostr ++;                   /* skip the O */
                    549:     switch(*ostr) {
                    550:       default:
                    551:        fprintf(stderr, "cfront: argument syntax: invalidZizedTs option (+O[BTo].");
                    552:        exit(11);
                    553:     case 'B':
                    554:        tree_dump_brief = 1;
                    555:     case 'T':
                    556:        dump_tree = 1;
                    557:        if(0 == *(ostr + 1) || strcmp (ostr, "T-") == 0)
                    558:            dump_tree_arg.output_stream = (ostream*)&cout;
                    559:        else {
                    560:            dump_tree_arg.output_stream
                    561:                = new ofstream (ostr+1, ios::out);
                    562:            if(dump_tree_arg.output_stream->fail()) {
                    563:                perror ("cfront");
                    564:                fprintf (stderr, "Failed to open %s\n", ostr + 1);
                    565:                exit (11);
                    566:            }
                    567:        }
                    568:        break;
                    569:       case 'o':
                    570:        out_file = fopen (ostr+1, "w");
                    571:        if(out_file == NULL) {
                    572:            perror ("cfront");
                    573:            fprintf(stderr, "Failed to open %s\n", ostr+1);
                    574:            exit(11);
                    575:        }
                    576:        break;
                    577:     }
                    578: }
                    579: 
                    580: main(int argc, char* argv[])
                    581: /*
                    582:        read options, initialize, and run
                    583: */
                    584: {
                    585:        register char * cp;
                    586:        char* afile = "";
                    587: #ifdef unix
                    588: 
                    589: #ifdef COMPLETE_SIG_PF
                    590:         signal(SIGILL,core_dump);
                    591:         signal(SIGIOT,core_dump);
                    592:         signal(SIGEMT,core_dump);
                    593:         signal(SIGFPE,core_dump);
                    594:         signal(SIGBUS,core_dump);
                    595:         signal(SIGSEGV,core_dump);
                    596: #else
                    597:        typedef void (*ST)(int ...);    // trick to circumvent problems with old
                    598:        ST sick = ST(&signal);          // (or C) versions <signal.h>
                    599:        (*sick)(SIGILL,core_dump);
                    600:        (*sick)(SIGIOT,core_dump);
                    601:        (*sick)(SIGEMT,core_dump);
                    602:        (*sick)(SIGFPE,core_dump);
                    603:        (*sick)(SIGBUS,core_dump);
                    604:        (*sick)(SIGSEGV,core_dump);
                    605: 
                    606: #endif
                    607: #endif
                    608: 
                    609: // SUM: not needed
                    610: // #ifdef apollo
                    611: //     set_sbrk_size(1000000); // resets free store size
                    612: //#else
                    613: #ifndef apollo
                    614:        //(void) malloc(0);     // suppress cashing in V8 malloc
                    615: #endif
                    616: 
                    617:        error_init();
                    618: 
                    619:        for (int i=1; i<argc; ++i) {
                    620:                switch (*(cp=argv[i])) {
                    621:                case '+':
                    622:                        while (*++cp) {
                    623:                                switch(*cp) {
                    624:                                case 'O':   
                    625:                                        pt_option(cp);
                    626:                                        goto xx;
                    627:                                case 'f':
                    628:                                        src_file_name = cp+1;
                    629:                                        goto xx;
                    630:                                case 'x':       // read cross compilation table
                    631:                                        if (read_align(afile = cp+1)) {
                    632:                                                fprintf(stderr,"bad size-table (option +x)\n");
                    633:                                                exit(11);
                    634:                                        }
                    635:                                        goto xx;
                    636:                                case 'e':
                    637:                                        switch (*++cp) {
                    638:                                        case '0':
                    639:                                        case '1': 
                    640:                                                vtbl_opt = *cp-'0';
                    641:                                                break;
                    642:                                        default:
                    643:                                                fprintf(stderr,"bad +e option\n");
                    644:                                                exit(11);
                    645:                                        }
                    646:                                        break;
                    647:                                case 'd':
                    648:                                        debug_opt = 1;
                    649:                                        break;
                    650:                                case 'g':
                    651:                                        gplus_opt = 1;
                    652:                                        break;
                    653:                                case 'D':
                    654: #ifdef DBG
                    655:                                        process_debug_flags(++cp);
                    656: #else
                    657:                                        error('w',"cfront not compiled for debugging -- +D%s ignored",++cp);
                    658: #endif
                    659:                                        goto xx;
                    660:                                case 'w':
                    661:                                        warning_opt = 1;
                    662:                                        break;
                    663:                                case 'a':
                    664:                                        switch (*++cp) {
                    665:                                        case '0':
                    666:                                        case '1': 
                    667:                                                ansi_opt = *cp-'0';
                    668:                                                break;
                    669:                                        default:
                    670:                                                fprintf(stderr,"bad +a option\n");
                    671:                                                exit(11);
                    672:                                        }
                    673:                                        break;
                    674:                                case 'p':
                    675:                                        strict_opt = 1;
                    676:                                        break;
                    677:                                case 'L':
                    678:                                        line_format = "\n#line %d \"%s\"\n";
                    679:                                        break;
                    680:                                default:
                    681:                                        fprintf(stderr,"%s: unexpected option: +%c ignored\n",prog_name,*cp);
                    682: 
                    683:                                }
                    684:                        }
                    685:                xx:
                    686:                        break;
                    687:                default:
                    688:                        fprintf(stderr,"%s: bad argument \"%s\"\n",prog_name,cp);
                    689:                        exit(11);
                    690:                }
                    691:        }
                    692: 
                    693: 
                    694:        fprintf(out_file,line_format+1,1,src_file_name); // strips leading \n
                    695:        fprintf(out_file,"\n/* %s */\n",prog_name);
                    696:        if (*src_file_name) fprintf(out_file,"/* < %s > */\n",src_file_name);
                    697: 
                    698: //     if (Nspy) {
                    699: //             start_time = time(0);
                    700: //             print_align(afile);
                    701: //     }
                    702:        fflush(stderr);
                    703:        otbl_init();
                    704:        lex_init();
                    705:        syn_init();
                    706:        typ_init();
                    707:        simpl_init();
                    708:        scan_started = 1;
                    709:        curloc.putline();
                    710:        if ((BI_IN_BYTE==0) && (SZ_INT==0) && (SZ_WPTR==0))
                    711:                error("no size/alignment values - use +x of provide #ifdef in size.h");
                    712:        run();
                    713:        if(dump_tree) {
                    714:                ostream_printf(*dump_tree_arg.output_stream, "------------ GTBL ------------\n\n");
                    715:                display_cfront_node (dump_tree_arg, ktbl);
                    716:                ostream_printf(*dump_tree_arg.output_stream, "------------ KTBL ------------\n\n");
                    717:                display_cfront_node (dump_tree_arg, ktbl);
                    718:        }                                              
                    719: 
                    720: //     if (Nspy) {
                    721: //             stop_time = time(0);
                    722: //             spy(src_file_name);
                    723: //     }
                    724:        exit( (0<=error_count && error_count<127) ? error_count : 127);
                    725: }
                    726: 
                    727: char* st_name(char* pref)
                    728: /*
                    729:        make name "pref|source_file_name|_" or "pref|source_file_name|_"
                    730:        where non alphanumeric characters are replaced with '_'
                    731:        and add def_name at end to ensure uniqueness
                    732: */
                    733: {
                    734:        int prefl = strlen(pref);
                    735:        int strl = prefl + 2;   // trailing '_' and 0
                    736:        if (*src_file_name) strl += strlen(src_file_name);
                    737:        char* defs;
                    738:        int defl;
                    739:        if (def_name) {
                    740:                defs = def_name->string;
                    741:                defl = strlen(defs)+1;  // '_'
                    742:        }
                    743:        else {
                    744:                defs = 0;
                    745:                defl = 0;
                    746:        }
                    747:        char* name = new char[strl+defl];
                    748:        strcpy(name,pref);
                    749:        if (*src_file_name) strcpy(name+prefl,src_file_name);
                    750:        name[strl-2] = '_';
                    751:        name[strl-1] = 0;
                    752: //     char *p = name;
                    753: //     while ( *++p ) if (!isalpha(*p) && !isdigit(*p)) *p = '_';
                    754:        for (char* p = name; *p; p++) if (!isalpha(*p) && !isdigit(*p)) *p = '_';
                    755:        if (defs) {
                    756:                strcpy(name+strl-1,defs);       // after the '_'
                    757:                name[strl+defl-2] = '_';
                    758:                name[strl+defl-1] = 0;
                    759:        }
                    760: #ifdef DENSE
                    761:        void chop(char*);
                    762:        chop(name);
                    763: #endif
                    764: 
                    765:        return name;
                    766: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.