home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / sozobon2 / top.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-23  |  3.8 KB  |  185 lines

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