home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / new / dev / c / hce / hcesource / top / source / top.h < prev    next >
C/C++ Source or Header  |  1992-09-02  |  4KB  |  200 lines

  1. /* Copyright (c) 1988,1991 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  *
  11.  * Modified by Detlef Wuerkner for AMIGA
  12.  * Changes marked with TETISOFT
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <ctype.h>
  17.  
  18. /* ADDED BY TETISOFT */
  19. #include <stdlib.h>
  20.  
  21. #include "inst.h"
  22. #include "opcodes.h"
  23.  
  24. #define    DEBUG        /* enable debug code */
  25.  
  26. #ifdef    DEBUG
  27. #define    DBG(x)        if (debug) { x; }
  28. #else
  29. #define    DBG(x)
  30. #endif
  31.  
  32. #ifndef    void
  33. #define    void    int
  34. #endif
  35.  
  36. /*
  37.  * Basic defines and declarations for the optimizer.
  38.  */
  39.  
  40. typedef    int    bool;
  41.  
  42. #ifndef    FALSE
  43. #define    FALSE    0
  44. #define    TRUE    1
  45. #endif
  46.  
  47. /*
  48.  * Basic Block:
  49.  *
  50.  * References a linked list of instructions that make up the block.
  51.  * Each block can be exited via one of two branches, which are
  52.  * represented by pointers to two other blocks, or null.
  53.  */
  54. struct    block {
  55.     int    flags;            /* flags relating to this block */
  56.     int    ref;            /* # of references to this block */
  57.     int    bcode;            /* type of exiting branch */
  58.     char    *name;            /* symbol name that starts the block */
  59.  
  60.     struct    inst    *first,        /* first instruction in block */
  61.             *last;        /* last instruction in block */
  62.  
  63.     /*
  64.      * Execution traversals
  65.      */
  66.     struct    block    *bcond,        /* conditional branch (or NULL) */
  67.             *bfall;        /* "fall through" branch */
  68.  
  69.     /*
  70.      * Logical traversals
  71.      */
  72.     struct    block    *chain;        /* links all blocks together */
  73.     struct    block    *next;        /* next block in the file */
  74.  
  75.     /*
  76.      * Information for data-flow analysis
  77.      */
  78.     int    rref;            /* registers ref'd before set */
  79.     int    rset;            /* registers modified by block */
  80. };
  81.  
  82. typedef    struct block    BLOCK;
  83. typedef    struct inst    INST;
  84.  
  85. /*
  86.  * Block flags
  87.  */
  88.  
  89. #define    B_GLOBAL    0x01        /* is the block's symbol global? */
  90. #define    B_TOUCHED    0x02        /* used in traversals */
  91. #define    B_LABEL        0x04        /* the block needs a label */
  92. #define    B_ISREACHED    0x08        /* block IS reached (for switches) */
  93. #define    B_RET        0x10        /* block terminates with a 'return' */
  94. #define    B_MARK        0x20        /* temporary 'touched' mark */
  95.  
  96. /*
  97.  * Global data
  98.  */
  99.  
  100. extern    FILE    *ifp, *ofp;        /* input and output file pointers */
  101.  
  102. /* ADDED BY TETISOFT */
  103. extern    FILE    *rfp, *cfp, *dfp, *bfp;    /* refs-code-data-bss file pointers */
  104.  
  105. /*
  106.  * Option flags set in main
  107.  */
  108. extern    bool    debug;
  109. extern    bool    do_peep;        /* enable peephole opt. */
  110. extern    bool    do_brev;        /* enable branch reversals */
  111. extern    bool    do_regs;        /* enable "registerizing" */
  112. extern    bool    do_lrot;        /* enable loop rotations */
  113. extern    bool    gflag;            /* set when using the debugger */
  114. extern    bool    verbose;
  115.  
  116. /* ADDED BY TETISOFT */
  117. extern    int    dest_hunk;
  118. #define    PUBLICMEM 0
  119. #define    CHIPMEM    1
  120.  
  121. /*
  122.  * Optimization stats
  123.  */
  124. extern    int    s_bdel;
  125. extern    int    s_badd;
  126. extern    int    s_brev;
  127. extern    int    s_peep1;
  128. extern    int    s_peep2;
  129. extern    int    s_peep3;
  130. extern    int    s_idel;
  131. extern    int    s_reg;
  132. extern    int    s_lrot;
  133.  
  134. /*
  135.  * These are set after calling readline.
  136.  */
  137. extern    char    *t_line;    /* text of the last line */
  138. extern    char    *t_lab;        /* label (if any) on the last line */
  139. extern    char    *t_op;        /* opcode */
  140. extern    char    *t_arg;        /* arguments */
  141.  
  142.  
  143. extern    char    *opnames[];    /* mnemonics for the instructions */
  144.  
  145. extern    BLOCK    *fhead;        /* head of the current function */
  146.  
  147. /*
  148.  * Function declarations
  149.  */
  150.  
  151. /*
  152.  * branch.c
  153.  */
  154. extern    void    bopt();
  155.  
  156. /*
  157.  * data.c
  158.  */
  159. extern    int    reg_ref(), reg_set();
  160. extern    bool    sets(), refs(), uses();
  161.  
  162. /*
  163.  * health.c
  164.  */
  165. extern    void    rhealth(), bprep();
  166.  
  167. /*
  168.  * inst.c
  169.  */
  170. extern    void    addinst(), delinst(), putinst();
  171. extern    bool    opeq();
  172.  
  173. /*
  174.  * io.c
  175.  */
  176. extern    bool    readline();
  177.  
  178. /*
  179.  * peep1.c
  180.  */
  181. extern    void    peep();
  182.  
  183. /*
  184.  * reg.c
  185.  */
  186. extern    void    addvar(), setreg(), clrvar();
  187.  
  188. /*
  189.  * util.c
  190.  */
  191. extern    char    *alloc();
  192. extern    char    *strsave();
  193.  
  194. /*
  195.  * sym.c
  196.  */
  197. extern    void    freeop(), freesym();
  198. extern    BLOCK    *getsym(), *mksym();
  199. extern    char    *mktmp();
  200.