home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / SOURCE / LIST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  5.7 KB  |  178 lines

  1. /*
  2.  * 68K/386 32-bit C compiler.
  3.  *
  4.  * copyright (c) 1996, David Lindauer
  5.  * 
  6.  * This compiler is intended for educational use.  It may not be used
  7.  * for profit without the express written consent of the author.
  8.  *
  9.  * It may be freely redistributed, as long as this notice remains intact
  10.  * and sources are distributed along with any executables derived from them.
  11.  *
  12.  * The author is not responsible for damages, either direct or consequential,
  13.  * that may arise from use of this software.
  14.  *
  15.  * v1.5 August 1996
  16.  * David Lindauer, gclind01@starbase.spd.louisville.edu
  17.  *
  18.  * Credits to Mathew Brandt for original K&R C compiler
  19.  *
  20.  */
  21. #include        <stdio.h>
  22. #include        "expr.h"
  23. #include        "c.h"
  24. #include        "gen.h"
  25. #include        "cglbdec.h"
  26.  
  27. extern int prm_listfile;
  28. extern HASHREC **globalhash;
  29.  
  30. char *tn_unnamed = "<no name> ";
  31.  
  32. void put_sc(int scl)
  33. {
  34.   if (!prm_listfile)
  35.     return;
  36.        switch(scl) {
  37.                 case sc_static:
  38.                         fprintf(listFile,"Static      ");
  39.                         break;
  40.                 case sc_auto:
  41.                         fprintf(listFile,"Auto        ");
  42.                         break;
  43.                 case sc_autoreg:
  44.                 case sc_memberreg:
  45.                         fprintf(listFile,"Register    ");
  46.                         break;
  47.                 case sc_global:
  48.                         fprintf(listFile,"Global      ");
  49.                         break;
  50.                 case sc_abs:
  51.                         fprintf(listFile,"Absolute    ");
  52.                         break;
  53.                 case sc_external:
  54.                 case sc_externalfunc:
  55.                         fprintf(listFile,"External    ");
  56.                         break;
  57.                 case sc_type:
  58.                         fprintf(listFile,"Type        ");
  59.                         break;
  60.                 case sc_const:
  61.                         fprintf(listFile,"Constant    ");
  62.                         break;
  63.                 case sc_member:
  64.                         fprintf(listFile,"Member      ");
  65.                         break;
  66.                 case sc_label:
  67.                         fprintf(listFile,"Label");
  68.                         break;
  69.                 case sc_ulabel:
  70.                         fprintf(listFile,"Undefined label");
  71.                         break;
  72.                 }
  73. }
  74.  
  75. void put_ty(TYP *tp)
  76. {       if((tp == 0) || (!prm_listfile))
  77.                 return;
  78.         switch(tp->type) {
  79.                                 case bt_matchall:
  80.                                                 fprintf(listFile,"Undefined");
  81.                                                 break;
  82.                 case bt_char:
  83.                         fprintf(listFile,"Char");
  84.                         break;
  85.                 case bt_short:
  86.                         fprintf(listFile,"Short");
  87.                         break;
  88.                 case bt_enum:
  89.                         fprintf(listFile,"enum ");
  90.                         goto ucont;
  91.                 case bt_long:
  92.                         fprintf(listFile,"Long");
  93.                         break;
  94.                 case bt_unsigned:
  95.                         fprintf(listFile,"Unsigned Long");
  96.                         break;
  97.                 case bt_float:
  98.                         fprintf(listFile,"Float");
  99.                         break;
  100.                 case bt_double:
  101.                         fprintf(listFile,"Double");
  102.                         break;
  103.                 case bt_longdouble:
  104.                         fprintf(listFile,"Long Double");
  105.                         break;
  106.                 case bt_pointer:
  107.                         if( tp->val_flag == 0)
  108.                                 fprintf(listFile,"Pointer to ");
  109.                         else
  110.                                 fprintf(listFile,"Array of ");
  111.                         put_ty(tp->btp);
  112.                         break;
  113.                 case bt_union:
  114.                         fprintf(listFile,"union ");
  115.                         goto ucont;
  116.                 case bt_struct:
  117.                         fprintf(listFile,"struct ");
  118. ucont:                  if(tp->sname == 0)
  119.                                 fprintf(listFile,tn_unnamed);
  120.                         else
  121.                                 fprintf(listFile,"%s ",tp->sname);
  122.                         break;
  123.                                 case bt_void:
  124.                                                 fprintf(listFile,"Void");
  125.                                                 break;
  126.                                 case bt_ptrfunc:
  127.                         fprintf(listFile,"Pointer to ");
  128.                 case bt_ifunc:
  129.                 case bt_func:
  130.                         fprintf(listFile,"Function returning ");
  131.                         put_ty(tp->btp);
  132.                         break;
  133.                 }
  134.     if (tp->startbit != -1)
  135.         fprintf(listFile,"  Bits %d to %d",tp->startbit,tp->startbit+tp->bits-1);
  136. }
  137.  
  138. void list_var(SYM *sp, int i)
  139. {       int     j;
  140.                 if (!prm_listfile)
  141.                     return;
  142.         for(j = i; j; --j)
  143.                 fprintf(listFile,"    ");
  144.         fprintf(listFile,"%-10s =%06x ",sp->name,sp->value.u);
  145.         put_sc(sp->storage_class);
  146.         put_ty(sp->tp);
  147.         fprintf(listFile,"\n");
  148.         if(sp->tp == 0)
  149.                 return;
  150.         if((sp->tp->type == bt_struct || sp->tp->type == bt_union) &&
  151.                 sp->storage_class == sc_type)
  152.                 list_table(&(sp->tp->lst),i+1);
  153. }
  154.  
  155. void list_table(TABLE *t,int j)
  156. {       SYM     *sp;
  157.                 int i;
  158.                 if (!prm_listfile)
  159.                     return;
  160.                 if (t == &gsyms) {
  161.                     for (i=0; i < HASHTABLESIZE; i++) {
  162.                         if ((sp=(SYM *) globalhash[i]) != 0) {
  163.                             while (sp) {
  164.                                 list_var(sp,j);
  165.                          sp = sp->next;
  166.                             }
  167.                         }
  168.                     }
  169.                 }
  170.                 else {
  171.             sp = t->head;
  172.             while(sp != NULL) {
  173.                 list_var(sp,j);
  174.                 sp = sp->next;
  175.                 }
  176.                 }
  177.             
  178. }