home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / iconc / ctrans.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  5KB  |  185 lines

  1. /*
  2.  * ctrans.c - main control of the translation process.
  3.  */
  4. #include "::h:gsupport.h"
  5. #include "cglobals.h"
  6. #include "ctrans.h"
  7. #include "csym.h"
  8. #include "ctree.h"
  9. #include "ctoken.h"
  10. #include "ccode.h"
  11. #include "cproto.h"
  12.  
  13. /*
  14.  * Prototypes.
  15.  */
  16. hidden novalue    trans1        Params((char *filename));
  17.  
  18. /*
  19.  * Variables.
  20.  */
  21. int tfatals = 0;        /* total number of fatal errors */
  22. int twarns = 0;            /* total number of warnings */
  23. int nocode;            /* set by lexer; unused in compiler */
  24. int in_line;            /* current input line number */
  25. int incol;            /* current input column number */
  26. int peekc;            /* one-character look ahead */
  27. struct srcfile *srclst = NULL;    /* list of source files to translate */
  28.  
  29. static char *lpath;        /* LPATH value */
  30.  
  31. /*
  32.  * translate a number of files, returning an error count
  33.  */
  34. int trans()
  35.    {
  36.    register struct pentry *proc;
  37.    struct srcfile *sf;
  38.  
  39. #ifdef EnvVars
  40.    lpath = getenv("LPATH");    /* else remains null */
  41. #endif                    /* EnvVars */
  42.  
  43.    for (sf = srclst; sf != NULL; sf = sf->next)
  44.       trans1(sf->name);    /* translate each file in turn */
  45.  
  46.    if (!pponly) {
  47.       /*
  48.        * Resolve undeclared references.
  49.        */
  50.       for (proc = proc_lst; proc != NULL; proc = proc->next)
  51.          resolve(proc);
  52.    
  53. #ifdef DeBug
  54.       symdump();
  55. #endif                    /* DeBug */
  56.    
  57.       if (tfatals == 0) {
  58.          chkstrinv();  /* see what needs be available for string invocation */
  59.          chkinv();     /* perform "naive" optimizations */
  60.          }
  61.    
  62.       if (tfatals == 0)
  63.          typeinfer();        /* perform type inference */
  64.    
  65.       if (just_type_trace)
  66.          return tfatals;     /* stop without generating code */
  67.    
  68.       if (tfatals == 0) {
  69.          var_dcls();         /* output declarations for globals and statics */
  70.          const_blks();       /* output blocks for cset and real literals */
  71.          for (proc = proc_lst; proc != NULL; proc = proc->next)
  72.             proccode(proc);  /* output code for a procedure */
  73.          recconstr(rec_lst); /* output code for record constructors */
  74.          }
  75.       }
  76.  
  77.    /*
  78.     * Report information about errors and warnings and be correct about it.
  79.     */
  80.    if (tfatals == 1)
  81.       fprintf(stderr, "1 error; ");
  82.    else if (tfatals > 1)
  83.       fprintf(stderr, "%d errors; ", tfatals);
  84.    else if (verbose > 0)
  85.       fprintf(stderr, "No errors; ");
  86.  
  87.    if (twarns == 1)
  88.       fprintf(stderr, "1 warning\n");
  89.    else if (twarns > 1)
  90.       fprintf(stderr, "%d warnings\n", twarns);
  91.    else if (verbose > 0)
  92.       fprintf(stderr, "no warnings\n");
  93.    else if (tfatals > 0)
  94.       fprintf(stderr, "\n");
  95.  
  96. #ifdef TranStats
  97.    tokdump();
  98. #endif                    /* TranStats */
  99.  
  100.    return tfatals;
  101.    }
  102.  
  103. /*
  104.  * translate one file.
  105.  */
  106. static novalue trans1(filename)
  107. char *filename;
  108.    {
  109.    in_line = 1;            /* start with line 1, column 0 */
  110.    incol = 0;
  111.    peekc = 0;            /* clear character lookahead */
  112.  
  113.    if (!ppinit(filename,m4pre)) {
  114.       tfatal(filename, "cannot open source file");
  115.       return;
  116.       }
  117.    ppdef("_COMPILED", "1");
  118.    if (!largeints)        /* undefine predef symbol if no -l option */
  119.       ppdef("_LARGE_INTEGERS", (char *)NULL);
  120.    ppdef("_MULTITASKING", (char *)NULL);    /* never defined in compiler */
  121.    ppdef("_EVENT_MONITOR", (char *)NULL);
  122.    ppdef("_MEMORY_MONITOR", (char *)NULL);
  123.    ppdef("_VISUALIZATION", (char *)NULL);
  124.    ppdef("_EXECUTABLE_IMAGES", (char *)NULL);
  125.  
  126.    if (strcmp(filename,"-") == 0)
  127.       filename = "stdin";
  128.    if (verbose > 0)
  129.       fprintf(stderr, "%s:\n",filename);
  130.  
  131.    tok_loc.n_file = filename;
  132.    in_line = 1;
  133.  
  134.    if (pponly)
  135.       ppecho();            /* preprocess only */
  136.    else
  137.    yyparse();                /* Parse the input */
  138.       }
  139.  
  140. /*
  141.  * writecheck - check the return code from a stdio output operation
  142.  */
  143. novalue writecheck(rc)
  144.    int rc;
  145.  
  146.    {
  147.    if (rc < 0)
  148.       quit("unable to write to icode file");
  149.    }
  150.  
  151. /*
  152.  * lnkdcl - find file locally or on LPATH and add to source list.
  153.  */
  154. novalue lnkdcl(name)
  155. char *name;
  156. {
  157.    struct srcfile **pp;
  158.    struct srcfile *p;
  159.    char buf[MaxFileName];
  160.  
  161.    if (pathfind(buf, lpath, name, SourceSuffix))
  162.       src_file(buf);
  163.    else
  164.       tfatal("cannot resolve reference to file name", name);
  165.       }
  166.  
  167. /*
  168.  * src_file - add the file name to the list of source files to be translated,
  169.  *   if it is not already on the list.
  170.  */
  171. novalue src_file(name)
  172. char *name;
  173.    {
  174.    struct srcfile **pp;
  175.    struct srcfile *p;
  176.  
  177.    for (pp = &srclst; *pp != NULL; pp = &(*pp)->next)
  178.      if (strcmp((*pp)->name, name) == 0)
  179.         return;
  180.    p = NewStruct(srcfile);
  181.    p->name = salloc(name);
  182.    p->next = NULL;
  183.    *pp = p;
  184. }
  185.