/******************************************************
 *      swbus.h: Lambda Beta to code Compiler
 ******************************************************/
/***********************************
     (C) Copyright 1992-1993; dit/upm
     Distributed under the conditions stated in the
     TOPO General Public License (see file LICENSE)
 ***********************************
 $Log: swbus.h,v $
 * Revision 2.9  1994/07/20  17:15:54  lotos
 * Commented still not used code for unused variables due to a bug
 *
 * Revision 2.8  1993/08/02  17:02:09  lotos
 * modificado los castings y tipados de las listas de puertas.
 * Se incrementa el garbage collector cada vez que se comparte
 *   una lista de puertas.
 * Adaptado al nuevo EPS (desaparece funcion get_gte).
 *
 * Revision 2.7  1993/06/16  14:11:11  lotos
 * colours c_light y c_from become public
 * remove option -i
 * add #line (and option -l to inhibit it)
 * transformation phase becomes independent: no global variables
 * data names pay attention to annotation CALL
 *
 * Revision 2.6  1993/01/18  18:14:46  lotos
 * distribution issues
 *
 * Revision 2.5  1993/01/12  20:20:58  lotos
 * portability issues
 *
 * Revision 2.4  1993/01/12  14:23:18  lotos
 * use conf.h for portability
 *
 * Revision 2.3  1993/01/11  18:33:09  lotos
 * overall bug fixing
 * new variable specpar: # of parameters in the lotos spec
 * formal parameters in processes are not compacted any longer
 * reverse -i meaning
 * add -C to remove would-be-generated files
 * generates code for if and use annotations
 * it is valid to split into 1 piece (no effect, really)
 * remove tbil.hh, replaced by conf.h
 *
 * Revision 2.2  1992/11/19  11:43:20  lotos
 * fix file naming
 * close brackets in code generated for guards and predicates
 *
 * Revision 2.1  1992/11/17  17:37:29  lotos
 * variables are compacted per sort
 * split generated code into several files
 * generates *.hh
 * admit option to change basename
 * adapted to use c_cui's
 * modify sort tables
 * code generation is more rational (needs further polishing ...)
 * adapted to new data type conventions
 * adopt new naming convention
 * include var declaration list in light BUTs
 *
 * Revision 1.4  1992/11/17  17:15:47  lotos
 * collect all others' changes
 *
 * Revision 1.3  1992/09/11  16:49:00  lotos
 * bug fixing
 *
 * Revision 1.2  1992/09/02  17:15:10  lotos
 * colour c_pr is included in 'colours.h'. Delted from here.
 *
 * Revision 1.1  1992/09/02  16:58:07  lotos
 * Initial revision
 *
 ************************************/

#define PUBLIC
#define PRIVATE static
#define SHARED extern

# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# include <assert.h>
# include "version.h"

# include "rag.hh"
# include "omnodes.h"
# include "omgrc.h"

# include "counter.h"

#define l2s(idx) (char*)(SymbolTable->data[(int)(ATable->data[(int)idx].value1)])

/* Debido a la chapuza de no poner el c_ui compactado en el lsa,
   he tenido que sacar el siguiente define como una funcion.
   Que hay que tener pelotas.

#define id2ui(idx) (int)(ATfind(ATable,(int)(idx),c_ui)->value)
*/
int id2ui ();

/* Y a este imbecil le pasa igual. ?Para que optimizar? 
#define id2sort(idx) (int)(ATfind(ATable,(int)(ATfind(ATable,(int)(idx),c_sort)->value),c_ui)->value)
*/
int id2sort ();

# define idclass(idx)   (int)(ATable->data[(int)(idx)].value0)

# define IsExtSrt(idx)  (ATfind (ATable, (int)(idx), c_extern) != NULL)

# define IsExtVar(idx)  (ATfind (ATable, (int)ATfind (ATable, (int)(idx), c_sort)->value, c_extern) != NULL)

# define takeclr(clr, nd)       (find_attr(clr, nd)->value)

/*+++++ +++++*/
# define TSPEC  1
# define TTYPE  2
# define TSORT  3
# define TOPN   4
# define TPROC  5
# define TGATE  6
# define TVAL   7
/*+++++ +++++*/

# include "omcolours.h"

/* -------------------- CONSTANTS --------------------------*/

#define c_lbc_id		149
#define c_entry			150
#define c_lentry		151
#define c_gate_decl_list	152
#define c_gate_actual_list	153
#define c_var_decl_list		154
#define c_local_var_decl	155

#define c_decl_gate		157
#define c_decl_var		158
#define c_number_exp		159
#define c_number_off		160
#define c_number_var		161
#define c_pred_number		162
#define c_product		163
#define c_sort_code		164
#define c_sort_list		165

#define c_value_exp_used	166

#define c_num_delays		167
#define c_num_waits		168
#define c_this_BUT_ui		169
#define c_sort_decl_list	170

/* Common types */

typedef struct varsort {
  int sort;             /* The Unique Identifier of the sort */
  int num;              /* The number of variables of this sort */
  int pos;              /* The positions */
  struct varsort *next; /* Some are chained for one but */
} tvarsort;

/* -------------------- VARIABLES --------------------------*/

/* From gen.c */
SHARED int	max_val;
/* SHARED int	*used_var_tbl; */
SHARED tvarsort	**tvs;

/* From omlbc.c */

SHARED TNODE	*lbmroot;
SHARED char	*progname;
SHARED char	*specname;
SHARED char	*basename;
SHARED char	*codename;
SHARED char	*incname;
SHARED char	*ldcname;
SHARED AT	*ATable;
SHARED IT	*pred_tbl;
SHARED IAT	*sort_tbl;
SHARED INTlist  *paramtbl;
SHARED int	lastBUTnumber;
SHARED int	lastVARnumber;
SHARED int	luid;
SHARED int	debuging;
SHARED int	debug_code;
SHARED int	genline;
SHARED int	split_flag;
SHARED int	split_parts;
SHARED int	split_counter;
SHARED int      split_digits;
SHARED int	but_counter;
SHARED int	but_per_part;
SHARED int      but_redundant;

/* From transform.c */

/* -------------------- FUNCTIONS --------------------------*/

/* From aux.c */
char     *emalloc ();
FILE     *efopen ();
void     fatal_error ();
int      hay_color ();
int      sizeIT ();
INTlist  INTmerge ();
int      INTmax ();
int      is_cte_ve ();
/*
int      *create_uvt ();
void     init_uvt ();
*/
INTlist  varl2sortl ();
int      vslength ();
int      totallength ();
tvarsort *PosVS ();
void     uptvs ();
void     uptvs_position ();
char     *mkstr ();
void     genfilenames ();
void     remove_files ();

/* From gen.c */
void    gencode ();

/* From transform.c */
int     do_transform ();


