NAME
     gen_code - generates assembly codes.
     gen_load - loads from the top of the stack.
     gen_store - stores to address or register.
     gen_call_before - required before a function call.
     gen_call_after - required after a function call.
     gen_label - produces a label.
     gen_cmpr - cmpares registers.

SYNOPSIS
     #include "getsym.h"
     #include "table.h"
     code_generator.c

     void 
     gen_code(int sign);

     void
     gen_load(char *target);

     void
     gen_store(char *tmp);

     void
     gen_call_before(struct list *local_table);

     void
     gen_call_after(struct list *local_table);

     void
     gen_label(int local_label);

     void gen_cmpr(char *target, char *source);

DESCRIPTION
     The file "code_generator.c" contains all the functions mentioned 
     above. All the functions are used to produce assembly codes. 

     gen_code function produces assembly codes depending on the sign
     passed to this function. It takes the top two values(either
     IDENTIFIER or NUMBER) from the stack as 'sign's operands. For
     example, the following condition in the stack will produce
     assembly codes equivalent to: 2 * x (assuming sign == TIMES).
                                   ^^^^^

           STACK                  STACK
           -----                  -----
           top -> 4 |     |                |     |
	             -----                  -----
	          3 |  x  |       top -> 3 |     |    Here,
	             -----                  -----
	          2 |  2  |              2 |  T0 |      T0 = 2 * x
	             -----                  -----
	            |  y  |              1 |  y  |
	

     gen_load Loads from the top of the stack to the 'target'.
     
           STACK                  STACK
           -----                  -----
           top -> 4 |     |                |     |
	             -----                  -----
	          3 |  x  |       top -> 3 |     |   if target = 'r3' 
	             -----                  -----
	          2 |  2  |              2 |  2  |      r3 = x
	             -----                  -----
	            |  y  |              1 |  y  |

     gen_store function stores contents of the register 'r3' to 'tmp'.

     gen_call_before  function is called before a function call. However, 
     it should only be called after the parameters are passed
     (actually stored). Point to remember that it increases:
	
           SP(stack pointer) = SP + number of variables in the table;
	   BR(base register) = BR + number of variables in the table + 1;

     gen_call_after function is called when a function call is made from 
     the source program. Point to remember that it decreases:
      
           SP(stack pointer) = SP - number of variables in the table;
	   BR(base register) = BR - number of variables in the table - 1;

     gen_label produces a labe based on the local_label passed to it.

     gen_cmpr compares target to source like:

	   cmpr  target, source
FILES
     table.h 
     getsym.h
     code_generator.c

WARNING
     The following variables are declared as extern variables:

          extern  TOKEN   tok;    
          extern  FILE    *infile;
          extern  FILE    *outfile;

          extern  TOKEN   stack[100];
          extern  int     top;
          extern  int     procedure_flag;
          extern  struct  list    *Table;
          extern  struct  list    *procedure_table;

     These variables should be declared somewhere before explicitly used.
     Here, these variables were declared in main.c.

     TEMP? variables are used to implement the expression. TEMP? variables
     base address is declared like:

	  #define BASE_TEMP_ADDRESS    1000

     which means that data segment can't expan more than 999 byte. It can
     be redifined like:

	  #define BASE_TEMP_ADDRESS    permitted_address_level 

SEE ALSO
     statement, procedure, table. 

AUTHOR
     Chakma Junan <jchakma@yahoo.com> 
     Information and Computer Sciences
     Toyohashi University of Technology.
     (It was originially implemented by: ohno@edu.tut.ac.jp)

     Last Updated: Mon Feb 14 20:32:56 JST 2000

