home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OBJASM.ZIP / OREPORT.C < prev    next >
C/C++ Source or Header  |  1990-11-03  |  7KB  |  240 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "o.h"
  5.  
  6. /*
  7. ** Local Prototypes
  8. */
  9.  
  10. char *ext_type[] = {
  11.     "ABS",                  /* Or Unknown */
  12.     "NEAR",
  13.     "FAR",
  14.     "BYTE",
  15.     "WORD",
  16.     "DWORD",
  17.     "FWORD",
  18.     "QWORD",
  19.     "TBYTE"
  20. };
  21.  
  22. void print_ext( ext_rec )
  23.     EXT_T   *ext_rec;
  24. {
  25.     char            operand[80];
  26.     char            *var_type;
  27.     char            *label;
  28.     int             type;
  29.     NODE_T          *pub_node;
  30.     PUB_T           *pub_rec;
  31.  
  32.     /*
  33.     ** Make sure name doesn't already exist as a public symbol
  34.     */
  35.     pub_node = start( public_tree, RIGHT );
  36.     while ( pub_node != public_tree ) {
  37.         pub_rec = (PUB_T *)pub_node->data;
  38.         if ( strcmp(pub_rec->name, ext_rec->name) == 0 ) {
  39.             return;
  40.         }
  41.         pub_node = traverse( pub_node, RIGHT );
  42.     }
  43.  
  44.     if ( ext_rec->scope ) {
  45.         label = "";
  46.     } else {
  47.         label = ";Static";
  48.     }
  49.  
  50.     if ( ext_rec->com_ext == 0 ) {
  51.         if ( ext_rec->type == UNKNOWN && ext_rec->pos_abs == FALSE ) {
  52.             ext_rec->type = NEAR;
  53.         }
  54.         sprintf( operand, "%s:%s", ext_rec->name, ext_type[ext_rec->type] );
  55.         out_label( label );
  56.         out_opcode( "EXTRN" );
  57.         tab_seek(3);
  58.         out_operand( operand );
  59.     } else {
  60.         switch( ext_rec->var_type ) {
  61.             case 0x61:
  62.                 var_type = "COMM FAR";
  63.                 break;
  64.             case 0x62:
  65.                 var_type = "COMM";
  66.                 break;
  67.             default:
  68.                 fmt_error( "Unknown Communal Variable Type" );
  69.                 break;
  70.         }
  71.         type = ext_rec->type;
  72.  
  73.         sprintf( operand, "%s:%s:%ld", ext_rec->name, ext_type[type], 
  74.                                                             ext_rec->size );
  75.         out_label( label );
  76.         if ( ext_rec->var_type == 0x62 ) {
  77.             tab_seek(3);
  78.         }
  79.         out_opcode( var_type );
  80.         out_operand( operand );
  81.     }
  82. }
  83.  
  84. void list_ext()
  85. {
  86.     NODE_T          *seg_node;
  87.     NODE_T          *ext_node;
  88.     EXT_T           *ext_rec;
  89.     int             data_index;
  90.  
  91.     data_index = 0;
  92.     seg_node = start( segment_tree, RIGHT );
  93.     while ( seg_node != segment_tree ) {
  94.         seg_rec = (SEG_T *)seg_node->data;
  95.         if ( stricmp(seg_rec->class->name, "DATA") == 0 ) {
  96.             data_index = seg_rec->index;
  97.             break;
  98.         }
  99.         seg_node = traverse( seg_node, RIGHT );
  100.     }
  101.  
  102.     out_newline();
  103.     ext_node = start( extern_tree, LEFT );
  104.     while ( ext_node != extern_tree ) {
  105.         ext_rec = (EXT_T *)ext_node->data;
  106.         if ( ext_rec->used == 0 || ext_rec->used == -1 ) {
  107.             if ( compatibility == 2 && data_index != 0 ) {
  108.                 if ( ext_rec->type == 2 || ext_rec->type == 3 ||
  109.                      ext_rec->type == 4 || ext_rec->type == 5 ) {
  110.                     if ( ext_rec->used == 0 ) {
  111.                         sex_insert( data_index, ext_rec );
  112.                         ext_rec->used = data_index;
  113.                     }
  114.                 } else {
  115.                     print_ext( ext_rec );
  116.                 }
  117.             } else {
  118.                 print_ext( ext_rec );
  119.             }
  120.         }
  121.         ext_node = traverse( ext_node, LEFT );
  122.     }
  123. }
  124.  
  125. void list_pub()
  126. {
  127.     NODE_T          *pub_node;
  128.     PUB_T           *pub_rec;
  129.     char            comment[50];
  130.     char            *label;
  131.  
  132.     out_newline();
  133.     pub_node = start( public_tree, RIGHT );
  134.     while ( pub_node != public_tree ) {
  135.         pub_rec = (PUB_T *)pub_node->data;
  136.         if ( pub_rec->scope ) {
  137.             label = "";
  138.         } else {
  139.             label = ";Static";
  140.         }
  141.         if ( pub_rec->domain == PUBLIC ) {
  142.             sprintf( comment, "Located at %d:%04lXh Type = %d", pub_rec->seg_idx, pub_rec->offset, pub_rec->type );
  143.             out_label( label );
  144.             out_opcode( "PUBLIC" );
  145.             tab_seek(3);
  146.             out_operand( pub_rec->name );
  147.             out_comment( comment );
  148.         } else {
  149. #ifdef DEBUG
  150.             sprintf( comment, "Located at %d:%04lXh Type = %d", pub_rec->seg_idx, pub_rec->offset, pub_rec->type );
  151.             out_label( label );
  152.             out_opcode( "PRIV" );
  153.             tab_seek(3);
  154.             out_operand( pub_rec->name );
  155.             out_comment( comment );
  156. #endif
  157.         }
  158.         pub_node = traverse( pub_node, RIGHT );
  159.     }
  160. }
  161.  
  162. void list_struc()
  163. {
  164.     NODE_T          *struc_node;
  165.     STRUC_T         *struc_rec;
  166.     char            temp[50];
  167.     int             index;
  168.     char            *cp;
  169.     char            ch;
  170.     unsigned long   dup_cnt;
  171.     int             type;
  172.     int             mem_cnt;
  173.     int             times;
  174.  
  175.     index = 0;
  176.     out_newline();
  177.     struc_node = start( struc_tree, RIGHT );
  178.     while ( struc_node != struc_tree ) {
  179.         struc_rec = (STRUC_T *)struc_node->data;
  180.  
  181.         struc_rec->index = index;
  182.         cp = struc_rec->form;
  183.  
  184.         sprintf( temp, "struct_%d", index );
  185.         out_line( temp, "struc", "", "" );
  186.  
  187.         mem_cnt = 0;
  188.         while ( (ch=*cp) != '\0' ) {
  189.             switch( ch ) {
  190.                 case '(':
  191.                     dup_cnt = atol( cp+1 );
  192.                     break;
  193.                 case ',':
  194.                     type = atoi( cp+1 );
  195.                     break;
  196.                 case ')':
  197.                     sprintf( temp, "s%dm_%d", index, mem_cnt );
  198.                     out_label( temp );
  199.                     out_directive( size_to_opcode(type_to_size(type), ×) );
  200.                     if ( dup_cnt == 1L ) {
  201.                         strcpy( temp, "?" );
  202.                     } else {
  203.                         sprintf( temp, "%ld dup (?)", dup_cnt );
  204.                     }
  205.                     out_operand( temp );
  206.                     out_endline();
  207.                     mem_cnt++;
  208.                 default:
  209.                     break;
  210.             }
  211.             cp++;
  212.         }
  213.  
  214.         sprintf( temp, "struct_%d", index );
  215.         out_line( temp, "ends", "", "" );
  216.  
  217.         out_newline();
  218.  
  219.         index++;
  220.         struc_node = traverse( struc_node, RIGHT );
  221.     }
  222. }
  223.  
  224. void list_fix()
  225. {
  226.     NODE_T          *fix_node;
  227.     FIX_T           *fix_rec;
  228.     char            comment[50];
  229.  
  230.     out_newline();
  231.     fix_node = start( fix_tree, RIGHT );
  232.     while ( fix_node != fix_tree ) {
  233.         fix_rec = (FIX_T *)fix_node->data;
  234.         sprintf( comment, "Fixup at 0%02Xh:0%04Xh:0%04Xh", fix_rec->seg_idx,
  235.                 fix_rec->dat_offset, fix_rec->offset );
  236.         out_line( "", ";", comment, "" );
  237.         fix_node = traverse( fix_node, RIGHT );
  238.     }
  239. }
  240.