Run through clang-format.
authorDavid Given <dg@cowlark.com>
Sun, 21 Aug 2016 17:38:54 +0000 (19:38 +0200)
committerDavid Given <dg@cowlark.com>
Sun, 21 Aug 2016 17:38:54 +0000 (19:38 +0200)
util/ego/il/il.c

index 6ec2a8a..d16ffce 100644 (file)
@@ -29,7 +29,7 @@
 
 int calnr;
 int complete_program;
-calcnt_p cchead;       /* call-count info of current proc */
+calcnt_p cchead; /* call-count info of current proc */
 STATIC long space = 0;
 STATIC long total_size = 0;
 
@@ -42,8 +42,8 @@ STATIC int kp_temps = 0;
 
 int Ssubst;
 #ifdef VERBOSE
-int Senv,Srecursive,Slocals,Sinstrlab,Sparsefails,Spremoved,Scals;
-int Sbig_caller,Sdispensable,Schangedcallee,Sbigcallee,Sspace,Szeroratio;
+int Senv, Srecursive, Slocals, Sinstrlab, Sparsefails, Spremoved, Scals;
+int Sbig_caller, Sdispensable, Schangedcallee, Sbigcallee, Sspace, Szeroratio;
 #endif
 
 /* P A S S  1
@@ -56,10 +56,9 @@ int Sbig_caller,Sdispensable,Schangedcallee,Sbigcallee,Sspace,Szeroratio;
  * The call descriptors are put in a file (calfile).
  */
 
-pass1(lnam,bnam,cnam)
-       char *lnam, *bnam, *cnam;
+pass1(lnam, bnam, cnam) char* lnam, *bnam, *cnam;
 {
-       FILE *f, *gf, *cf, *ccf; /* The EM input, the basic block graph,
+       FILEf, *gf, *cf, *ccf; /* The EM input, the basic block graph,
                                  * the call-list file and the calcnt file.
                                  */
        long laddr;
@@ -67,26 +66,29 @@ pass1(lnam,bnam,cnam)
        short kind;
        line_p l;
 
-       f = openfile(lnam,"r");
-       gf = openfile(bnam,"r");
-       cf = openfile(cnam,"w");
-       ccf = openfile(ccname,"w");
+       f = openfile(lnam, "r");
+       gf = openfile(bnam, "r");
+       cf = openfile(cnam, "w");
+       ccf = openfile(ccname, "w");
        mesregs = Lempty_set();
        apriori(fproc);
        /* use information from the procedure table to
         * see which calls certainly cannot be expanded.
         */
-       while(TRUE) {
+       while (TRUE)
+       {
                laddr = ftell(f);
-               if (!getunit(gf,f,&kind,&g,&l,&curproc,TRUE)) break;
+               if (!getunit(gf, f, &kind, &g, &l, &curproc, TRUE))
+                       break;
                /* Read the control flow graph and EM text of
                 * one procedure and analyze it.
                 */
-               if (kind == LDATA) {
-                       remunit(LDATA,(proc_p) 0,l);
+               if (kind == LDATA)
+               {
+                       remunit(LDATA, (proc_p)0, l);
                        continue;
                }
-               OUTTRACE("flow graph of proc %d read",curproc->p_id);
+               OUTTRACE("flow graph of proc %d read", curproc->p_id);
                assert(INSTR(g->b_start) == ps_pro);
                curproc->p_start = g;
                curproc->P_LADDR = laddr;
@@ -94,74 +96,78 @@ pass1(lnam,bnam,cnam)
                /* address of graph in basic block file */
                curproc->P_SIZE = proclength(curproc); /* #instructions */
                total_size += curproc->P_SIZE;
-               if (BIG_PROC(curproc)) {
+               if (BIG_PROC(curproc))
+               {
                        /* curproc is too large to be expanded in line */
                        UNSUITABLE(curproc);
                }
                calnr = 0;
-               anal_proc(curproc,cf,ccf);
-               OUTTRACE("proc %d processed",curproc->p_id);
-               remunit(LTEXT,curproc,(line_p) 0);
+               anal_proc(curproc, cf, ccf);
+               OUTTRACE("proc %d processed", curproc->p_id);
+               remunit(LTEXT, curproc, (line_p)0);
                /* remove control flow graph + text */
-               OUTTRACE("graph of proc %d removed",curproc->p_id);
+               OUTTRACE("graph of proc %d removed", curproc->p_id);
                Ldeleteset(mesregs);
                mesregs = Lempty_set();
        }
        fclose(f);
        fclose(gf);
        fclose(cf);
-       fclose(ccf); 
+       fclose(ccf);
 }
 
-
-
 /* P A S S  2
  *
  * Pass 2 reads the calfile and determines which calls should
  * be expanded in line. It does not use the EM text.
  */
 
-
-
 STATIC char cname2[128] = TMP_DIR;
 
-pass2(cnam,space)
-       char *cnam;
-       long space;
+pass2(cnam, space) char* cnam;
+long space;
 {
-       FILE  *cf, *cf2, *ccf;
-       call_p c,a;
-
-       cf = openfile(cnam,"r");
-       cf2 = openfile(cname2,"w");
-       ccf = openfile(ccname,"r");
-       while ((c = getcall(cf)) != (call_p) 0) {
+       FILE* cf, *cf2, *ccf;
+       call_p c, a;
+
+       cf = openfile(cnam, "r");
+       cf2 = openfile(cname2, "w");
+       ccf = openfile(ccname, "r");
+       while ((c = getcall(cf)) != (call_p)0)
+       {
                /* process all calls */
-               if (SUITABLE(c->cl_proc) && anal_params(c)) {
+               if (SUITABLE(c->cl_proc) && anal_params(c))
+               {
                        /* called proc. may be put in line */
                        /* see which parameters may be put in line */
                        assign_ratio(c); /* assign a rank */
                        a = abstract(c); /* abstract essential info */
-                       append_abstract(a,a->cl_caller);
+                       append_abstract(a, a->cl_caller);
                        /* put it in call-list of calling proc. */
-                       putcall(c,cf2,(short) 0);
-               } else {
+                       putcall(c, cf2, (short)0);
+               }
+               else
+               {
                        rem_call(c);
                }
        }
-       select_calls(fproc,ccf,space);
-       fclose(cf); if (! kp_temps) unlink(cnam);
+       select_calls(fproc, ccf, space);
+       fclose(cf);
+       if (!kp_temps)
+               unlink(cnam);
        fclose(cf2);
-       fclose(ccf); if (! kp_temps) unlink(ccname);
-       cf2 = openfile(cname2,"r");
-       add_actuals(fproc,cf2);
+       fclose(ccf);
+       if (!kp_temps)
+               unlink(ccname);
+       cf2 = openfile(cname2, "r");
+       add_actuals(fproc, cf2);
        cleancals(fproc); /* remove calls that were not selected */
        /* add actual parameters to each selected call */
-       fclose(cf2); if (! kp_temps) unlink(cname2);
+       fclose(cf2);
+       if (!kp_temps)
+               unlink(cname2);
 }
 
-
-
 /* P A S S  3
  *
  * pass 3 reads the substitution file and performs all
@@ -170,67 +176,76 @@ pass2(cnam,space)
  * EM textfile.
  */
 
-
-pass3(lnam,lnam2)
-       char *lnam,*lnam2;
+pass3(lnam, lnam2) char* lnam, *lnam2;
 {
        bool verbose = TRUE;
-       FILE *lfile, *lfilerand, *lfile2, *sfile;
-       call_p c,next;
-       line_p l,startscan,cal;
+       FILElfile, *lfilerand, *lfile2, *sfile;
+       call_p c, next;
+       line_p l, startscan, cal;
        short lastcid; /* last call-id seen */
 
        lfile = openfile(lnam, "r");
        lfilerand = openfile(lnam, "r");
-       lfile2 = openfile(lnam2,"w");
-       if (verbose) {
-               sfile = openfile(sname,"w");
+       lfile2 = openfile(lnam2, "w");
+       if (verbose)
+       {
+               sfile = openfile(sname, "w");
        }
        mesregs = Lempty_set();
-       while ((l = get_text(lfile,&curproc)) != (line_p) 0) {
-               if (curproc == (proc_p) 0) {
+       while ((l = get_text(lfile, &curproc)) != (line_p)0)
+       {
+               if (curproc == (proc_p)0)
+               {
                        /* Just a data-unit; no real instructions */
-                       putlines(l->l_next,lfile2);
+                       putlines(l->l_next, lfile2);
                        oldline(l);
                        continue;
                }
-               if (IS_DISPENSABLE(curproc)) {
-                       liquidate(curproc,l->l_next);
-               } else {
+               if (IS_DISPENSABLE(curproc))
+               {
+                       liquidate(curproc, l->l_next);
+               }
+               else
+               {
                        startscan = l->l_next;
                        lastcid = 0;
-                       for (c = curproc->P_CALS; c != (call_p) 0; c = next) {
+                       for (c = curproc->P_CALS; c != (call_p)0; c = next)
+                       {
                                next = c->cl_cdr;
-                               cal = scan_to_cal(startscan,c->cl_id - lastcid);
-                               assert (cal != (line_p) 0);
-                               startscan = scan_to_cal(cal->l_next,1);
+                               cal = scan_to_cal(startscan, c->cl_id - lastcid);
+                               assert(cal != (line_p)0);
+                               startscan = scan_to_cal(cal->l_next, 1);
                                /* next CAL */
                                lastcid = c->cl_id;
                                /* next CAL after current one */
-                               substitute(lfilerand,c,cal,l->l_next);
-                               if (verbose) {
-                                       putcall(c,sfile,0);
-                               } else {
+                               substitute(lfilerand, c, cal, l->l_next);
+                               if (verbose)
+                               {
+                                       putcall(c, sfile, 0);
+                               }
+                               else
+                               {
                                        rem_call(c);
                                }
                        }
                }
-               putlines(l->l_next,lfile2);
+               putlines(l->l_next, lfile2);
                Ldeleteset(mesregs);
                mesregs = Lempty_set();
                oldline(l);
        }
        fclose(lfile);
        fclose(lfile2);
-       if (verbose) {
+       if (verbose)
+       {
                fclose(sfile);
-               if (! kp_temps) unlink(sname);
+               if (!kp_temps)
+                       unlink(sname);
        }
 }
 
-
 STATIC il_extptab(ptab)
-       proc_p ptab;
+    proc_p ptab;
 {
        /* Allocate space for extension of proctable entries.
         * Also, initialise some of the fields just allocated.
@@ -238,7 +253,8 @@ STATIC il_extptab(ptab)
 
        register proc_p p;
 
-       for (p = ptab; p != (proc_p) 0; p = p->p_next) {
+       for (p = ptab; p != (proc_p)0; p = p->p_next)
+       {
                p->p_extend = newilpx();
                p->P_ORGLABELS = p->p_nrlabels;
                p->P_ORGLOCALS = p->p_localbytes;
@@ -246,13 +262,14 @@ STATIC il_extptab(ptab)
 }
 
 STATIC il_cleanptab(ptab)
-       proc_p ptab;
+    proc_p ptab;
 {
        /* De-allocate space for extensions */
 
        register proc_p p;
 
-       for (p = ptab; p != (proc_p) 0; p = p->p_next) {
+       for (p = ptab; p != (proc_p)0; p = p->p_next)
+       {
                oldilpx(p->p_extend);
        }
 }
@@ -262,55 +279,55 @@ Sdiagnostics()
 {
        /* print statictical information */
 
-       fprintf(stderr,"STATISTICS:\n");
-       fprintf(stderr,"Info about procedures:\n");
-       fprintf(stderr,"environment accessed: %d\n",Senv);
-       fprintf(stderr,"recursive: %d\n",Srecursive);
-       fprintf(stderr,"too many locals: %d\n",Slocals);
-       fprintf(stderr,"instr. lab in data block: %d\n",Sinstrlab);
-       fprintf(stderr,"procedures removed: %d\n",Spremoved);
-       fprintf(stderr,"\nInfo about calls:\n");
-       fprintf(stderr,"total number of calls: %d\n",Scals);
-       fprintf(stderr,"total number of calls substituted: %d\n",Ssubst);
-       fprintf(stderr,"parser failed: %d\n",Sparsefails);
-       fprintf(stderr,"caller too big: %d\n",Sbig_caller);
-       fprintf(stderr,"caller dispensable: %d\n",Sdispensable);
-       fprintf(stderr,"callee is changed: %d\n",Schangedcallee);
-       fprintf(stderr,"callee too big: %d\n",Sbigcallee);
-       fprintf(stderr,"no space available: %d\n",Sspace);
-       fprintf(stderr,"zero ratio: %d\n",Szeroratio);
+       fprintf(stderr, "STATISTICS:\n");
+       fprintf(stderr, "Info about procedures:\n");
+       fprintf(stderr, "environment accessed: %d\n", Senv);
+       fprintf(stderr, "recursive: %d\n", Srecursive);
+       fprintf(stderr, "too many locals: %d\n", Slocals);
+       fprintf(stderr, "instr. lab in data block: %d\n", Sinstrlab);
+       fprintf(stderr, "procedures removed: %d\n", Spremoved);
+       fprintf(stderr, "\nInfo about calls:\n");
+       fprintf(stderr, "total number of calls: %d\n", Scals);
+       fprintf(stderr, "total number of calls substituted: %d\n", Ssubst);
+       fprintf(stderr, "parser failed: %d\n", Sparsefails);
+       fprintf(stderr, "caller too big: %d\n", Sbig_caller);
+       fprintf(stderr, "caller dispensable: %d\n", Sdispensable);
+       fprintf(stderr, "callee is changed: %d\n", Schangedcallee);
+       fprintf(stderr, "callee too big: %d\n", Sbigcallee);
+       fprintf(stderr, "no space available: %d\n", Sspace);
+       fprintf(stderr, "zero ratio: %d\n", Szeroratio);
 }
 #endif
 
-il_flags(p)
-       char *p;
+il_flags(p) char* p;
 {
-       switch(*p++) {
-       case 's':
-               while (*p != '\0') {
-                       space = 10*space +*p++ -'0';
-               }
-               break;
-       case 'a':
-               complete_program = 1;
-               break;
-       case 't':
-               strcpy(cname, ".");
-               strcpy(ccname, ".");
-               strcpy(sname, ".");
-               strcpy(cname2, ".");
-               kp_temps = 1;
-               break;
+       switch (*p++)
+       {
+               case 's':
+                       while (*p != '\0')
+                       {
+                               space = 10 * space + *p++ - '0';
+                       }
+                       break;
+               case 'a':
+                       complete_program = 1;
+                       break;
+               case 't':
+                       strcpy(cname, ".");
+                       strcpy(ccname, ".");
+                       strcpy(sname, ".");
+                       strcpy(cname2, ".");
+                       kp_temps = 1;
+                       break;
        }
 }
 
-main(argc,argv)
-       int argc;
-       char *argv[];
+main(argc, argv) int argc;
+char* argv[];
 {
-       FILE *f;
-       
-       go(argc,argv,no_action,no_action,no_action,il_flags);
+       FILEf;
+
+       go(argc, argv, no_action, no_action, no_action, il_flags);
        il_extptab(fproc); /* add extended data structures */
        strcat(cname, "/ego.i1.XXXXXX");
        strcat(ccname, "/ego.i2.XXXXXX");
@@ -320,18 +337,19 @@ main(argc,argv)
        mktemp(ccname);
        mktemp(sname);
        mktemp(cname2);
-       pass1(lname,bname,cname); /* grep calls, analyse procedures */
-       space = total_size * space / 100 ;
-       pass2(cname,space);  /* select calls to be expanded */
-       pass3(lname,lname2); /* do substitutions */
-       f = openfile(dname2,"w");
+       pass1(lname, bname, cname); /* grep calls, analyse procedures */
+       space = total_size * space / 100;
+       pass2(cname, space); /* select calls to be expanded */
+       pass3(lname, lname2); /* do substitutions */
+       f = openfile(dname2, "w");
        il_cleanptab(fproc); /* remove extended data structures */
-       putdtable(fdblock,f);
-       f = openfile(pname2,"w");
-       putptable(fproc,f,FALSE);
-       report("inline substitutions",Ssubst);
+       putdtable(fdblock, f);
+       f = openfile(pname2, "w");
+       putptable(fproc, f, FALSE);
+       report("inline substitutions", Ssubst);
 #ifdef VERBOSE
-       if (verbose_flag) {
+       if (verbose_flag)
+       {
                Sdiagnostics();
        }
 #endif