/* proj3.h */
/* Author: Edward A. Green */
/* description: header file for all modules of project 3 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/***************************************/
/* TYPE DEFINITIONS FOR PROGRAM BLOCKS */
/***************************************/

/* USE LIST AND MODIFIED, NEXT USE LIST FOR A PROGRAM */
typedef struct MOD
  {
  char *var;            /* variable name */
  int  next_line;       /* next line in block when variable is used */
  struct MOD *next;     /* link to other modified variables */
  } MOD;

/* STRUCTURE TO HOLD A QUAD; LINKED TO OTHER QUADS OF A PROCEDURE */
typedef struct CODE
  {
  int  line;            /* relative line in program */
  int  basic;           /* basic block designation */
  char *flds[5];        /* quad fields */
  MOD  *used;           /* list of used variables */
  MOD  *mod;            /* list of modified and next uses */
  struct CODE *last;    /* links to previous code */
  struct CODE *next;    /*  "    "  following code */
  } CODE;

/* STRUCTURE TO HOLD THE SYMBOL TABLE */
typedef struct SYMTBL
  {
  char *symbol;         /* Ascii reprosentation */
  int  offset;          /* Offset */
  char *mem;		/* ascii representation of memory location */
  char stype;           /* simple type ("i"nt, "r"eal, "u"nknown, " " ) */
  char ctype;           /* composite type ("s"calar, "a"rray */
			/*                 "p"rocedure or function */
  int  from;            /* starting index for array */
  int  to;              /* ending index for array */
  int  nparms;          /* number of parameters */
  int  next_use;        /* line number of last use or modification */
  char mod_use;         /* "m"od or "u"se */
  struct SYMTBL *parms; /* chain to parameter types for procs, funcs. */
  struct SYMTBL *next;  /* link to next symbol in table */
  } SYMTBL;


/* STRUCTURE TO HOLD A PROCEDURE BLOCK-LINKED TO FORM A PROGRAM */
typedef struct BLOCK
  {
  CODE   *lead;         /* pointer to the lead line in the block */
  SYMTBL *table;        /* pointer to the first symbol in the table */
  int    memsize;       /* memory requirements for local var storage */
  struct BLOCK *next;   /* pointer to the previous program block */
  struct BLOCK *last;   /* pointer to the next program block */
  } BLOCK;

/************************************************/
/* TYPE DEFINITIONS FOR EXTRACTING BASIC BLOCKS */
/************************************************/

/* List of lines where labels are found */
typedef struct LABELS
  {
  char field;		/* Quad field where label occurred:  */
			/*   'L' label field; 'G' goto field */
  char *label;		/* Label string */
  int  line;    	/* Program line number of this label occurrence */
  struct LABELS *next;  /* Link to the next label record */
  } LABELS;


/* Sorted linked list of block leaders */
typedef struct LEADS
  {
  int line;		/* Line number of the leaders */
  struct LEADS *next;   /* Link to the next leader */
  } LEADS;

/********************/
/* CONNECTION TABLE */
/********************/

/* structure for basic block adjacency list */
typedef struct CONNECT
  {
  int from;              /* tail of arrow in connection graph */
  int to[2];		 /* destins. in connection graph (-1: no conn.) */
  struct CONNECT *next;  /* next entry in table */
  } CONNECT;
