/*
 * C compiler
 * ==========
 *
 * Copyright 1989, 1990, 1991 Christoph van Wuellen.
 * Credits to Matthew Brandt.
 * All commercial rights reserved.
 *
 * This compiler may be redistributed as long there is no
 * commercial interest. The compiler must not be redistributed
 * without its full sources. This notice must stay intact.
 *
 * History:
 *
 * 1989   starting an 68000 C compiler, starting with material
 *        originally by M. Brandt
 * 1990   68000 C compiler further bug fixes
 *        started i386 port (December)
 * 1991   i386 port finished (January)
 *        further corrections in the front end and in the 68000
 *        code generator.
 *        The next port will be a SPARC port
 */

#ifndef _CGLBDEC_h
#define	_CGLBDEC_H

extern FHANDLE	input;		/* input source file */
extern FHANDLE	output;		/* output assembler file */
extern FHANDLE	errfile;	/* error listing file */
#ifdef LIST
extern FHANDLE	listfile;	/* source listing file */
#endif /* LIST */
#ifdef DEBUG
extern FHANDLE	debugfile;	/* output file for internal debugging */
#endif /* DEBUG */
extern LINE     act_line;	/* current line number being processed */
extern CHAR *	act_linetxt;	/* text of the current line */
extern char *	act_file;	/* current source file being processed */
extern LABEL    nextlabel;	/* next internally generated label */
extern BOOL	need_label;
extern char *	newline;	/* character(s) to use for a newline */

/* scanner values */
extern TOKEN	lastst;		/* last symbol token read by the scanner */
extern CHAR	*lastsym;	/* pointer to the last symbol */
extern size_t   lastsymlen;	/* length of the value in laststr */
extern UVAL	ival;		/* integral value */
#ifdef FLOAT_SUPPORT
extern RVAL	rval;		/* floating point value */
#endif /* FLOAT_SUPPORT */

extern char *	msgtable[];	/* table of messages output */

/* stack frame values */
extern SIZE     lc_auto;	/* the current size of the stack frame */
extern SIZE	lc_auto_max;	/* the maximum size that the stack frame has grown */

extern int      global_flag;	/* allocate memory for "permanent use */
extern int	error_resync;	/* prevent error message cascade */
extern int      total_errors;	/* number of errors currently encountered */

/* compiler options */
extern BOOL	align_option;	/* align structure fields to smallest alignment */
#ifdef ASM
extern BOOL	asm_option;	/* asm keyword allowed */
#endif /* ASM */
extern BOOL	bitfield_option;/* reverse allocation order of bitfields */
extern BOOL	code_option;	/* generate code */
#ifdef DEBUGOPT
extern BOOL	debug_option;	/* generate debugging information */
#endif /*DEBUGOPT*/
#ifdef EXTERNAL
extern BOOL	extern_option;	/* generate extern defintions for all globals */
#endif /* EXTERNAL */
#ifdef FLOAT_CHECK
extern BOOL	 fcheck_option;	/* warn about floating point operations */
#endif /* FLOAT_CHECK */
#ifdef MC680X0
extern int	frame_option;	/* register to use as the frame pointer */
#endif /* MC680X0 */
#ifdef DEBUG
extern int	internal_option;/* controls internal debugging options */
#endif /* DEBUG */
extern BOOL	lattice_option;	/* allow Lattice stype stdarg definitions */
extern BOOL	IandD_option;	/* separate Instruction and Data segments */
#ifdef MC680X0
extern BOOL	large_option;	/* allow static function calls >32K */
#endif /* MC680X0 */
#ifdef LIST
extern BOOL	list_option;	/* list the input source and symbol tables */
#endif /* LIST */
extern BOOL	longdouble_option;	/* long doubles are to be the same size as doubles */
extern BOOL	obsolete_option;/* future language directions defined obsolete feature */
extern BOOL	opt_option;	/* use the global optimiser */
extern BOOL	optimize_option;/* do "expensive" optimisations */
#ifdef PACKENUM
extern BOOL	packenum_option;/* enumerations are smallest integer type to hold values */
#endif /* PACKENUM */
extern BOOL	peep_option;	/* use the peep-hole optimiser */
extern BOOL	reg_option;	/* honour the "register" storage */
extern BOOL	short_option;	/* integers are to be the same size as shorts */
extern BOOL	small_option;	/* small model (8086) */
extern int	stackopt_option;/* Use lazy stack optimisation */
#ifdef TOPSPEED
extern BOOL	topspeed_option;/* Enable TopSpeed extentions */
#endif /* TOPSPEED */
extern BOOL	trad_option;	/* accept only K&R plus a few extras */
#ifdef TRANSLATE
extern BOOL	trans_option;	/* convert identifier > 8 character in output file */
#endif /* TRANSLATE */
extern BOOL	uchar_option;	/* char type to be unsigned */
extern BOOL	verbose_option;	/* output extra statistics */
extern int	error_option;	/* the current error message level */
extern int	warn_option;	/* the current warning message level */
extern BOOL	fpu_option;	/* generate code which contains floating point instructions */
extern BOOL	fpu_return_option; /* return FP value in FP register */
#ifdef INTEL_386
extern BOOL	fpret386_option;/* return FP values in edx:eax */
#endif /* INTEL_386 */
#ifdef ICODE
extern BOOL	icode_option;	/* generate an icode file */
#endif /* ICODE */
#ifdef TMS320C30
extern int	opt_delayed_branches;	/* allow delayed branched */
#endif /* TMS320C30 */
#ifdef PROBES
extern BOOL	probe_option;	/* generate stack probes on function entry */
#endif /* PROBE */
#ifdef FORMAT_CHECK
extern BOOL	format_option;	/* check fprintf and fscanf format strings */
#endif /* FORMAT_CHECK */
#ifdef STACK_CHECK
extern BOOL	stackcheck_option; /* check stack with run-time routine */
#endif /* STACK_CHECK */
#ifdef TRACE
extern BOOL	trace_option;	/* generate trace code */
#endif /* TRACE */
extern int	max_error_count;/* maximum number of errors before stopping */
#ifdef MC680X0
extern	BOOL	target_option;	/* Motorola code generation target */
#endif /* MC680X0 */

extern TYP	*ret_type;	/* function return type */
extern EXPR	*init_node;	/* initializations in compound statement */


#ifdef VERBOSE
/* statistics collected during the verbose mode */
extern clock_t  decl_time;	/* time spent parsing the declarations */
extern clock_t	parse_time;	/* time spend parsing the statments/expressions */
extern clock_t	opt_time;	/* time spend in the optimisers */
extern clock_t	gen_time;	/* time spend in the code generator */
extern clock_t	flush_time;	/* time spent writing out the code */
#endif /* VERBOSE */

extern BLOCK	init_block;	/* empty block table */
extern BOOL	errorloop;	/* prevents recussion during error recovery */

/* the basic types */
extern TYP	*tp_void;	/* void type */
extern TYP	*tp_char;	/* char type */
extern TYP	*tp_uchar;	/* unsigned char type */
extern TYP	*tp_schar;	/* signed char type */
extern TYP      *tp_int;	/* int type */
extern TYP      *tp_uint;	/* unsigned int type */
extern TYP      *tp_short;	/* short type */
extern TYP      *tp_ushort;	/* unsigned short type */
extern TYP	*tp_long;	/* long type */
extern TYP	*tp_ulong;	/* unsigned long type */
extern TYP	*tp_pointer;	/* pointer type */
extern TYP	*tp_array;	/* array type */
extern TYP	*tp_float;	/* float type */
extern TYP	*tp_double;	/* double type */
extern TYP	*tp_longdouble;	/* long double type */
extern TYP	*tp_enum;	/* enum type */
extern TYP	*tp_struct;	/* struct type */
extern TYP	*tp_union;	/* union type */
extern TYP	*tp_ellipsis;	/* ellipsis type */
extern TYP	*tp_func;	/* function type */
extern TYP	*tp_string;	/* pointer to char type */
extern TYP	*tp_wstring;	/* pointer to wchar_t type */

/* defined types */
extern TYP	*tp_wchar;	/* wchar_t type */
extern TYP	*tp_size;	/* size_t type */
extern TYP	*tp_ptrdiff;	/* ptrdiff_t type */

extern int      int_bits;	/* number of bits in an int */

/* names used in the parser and code generators */
extern CHAR	*alloca_name;	/* pointer to the name alloca */
extern CHAR	*printf_name;	/* pointer to the name printf */
extern CHAR	*fprintf_name;	/* pointer to the name fprintf */
extern CHAR	*sprintf_name;	/* pointer to the name sprintf */
extern CHAR	*scanf_name;	/* pointer to the name scanf */
extern CHAR	*fscanf_name;	/* pointer to the name fscanf */
extern CHAR	*sscanf_name;	/* pointer to the name sscanf */

extern struct slit *strtab;	/* table of strings to be output to the assembler file */
extern BOOL uses_structassign;	/* function uses a structure assignment */
extern BOOL is_leaf_function;	/* function doesn't call any other function */
extern BOOL is_parameter;	/* controls whether stack optimation is allowed */

#ifdef MC68000
extern BOOL	volatile_found;	/* the volatile keyword has been found */
#endif /* MC68000 */

#ifdef FLOAT_SUPPORT
/* floating point constants used within the compiler */
extern RVAL	F_zero;		/* contains the value  0.0 */
extern RVAL	F_one;		/* contains the value  1.0 */
extern RVAL	F_two;		/* contains the value  2.0 */
extern RVAL	F_ten;		/* contains the value 10.0 */
extern RVAL	F_half;		/* contains the value  0.5 */
#endif /* FLOAT_SUPPORT */

#ifdef CPU_DEFINED
/* code generator values */

#ifdef MULTIPLE_PROCESSORS
extern struct genfuncs	*GFuncs;
#ifdef MC68000
extern struct genfuncs	mc68k_funcs;
#endif /* MC68000 */
#ifdef INTEL_386
extern struct genfuncs	mc386_funcs;
#endif /* INTEL_386 */
#ifdef INTEL_86
extern struct genfuncs	mc86_funcs;
#endif /* INTEL_86 */
#ifdef ARM
extern struct genfuncs	mcarm_funcs;
#endif /* ARM */
#ifdef TMS320C30
extern struct genfuncs	mcc30_funcs;
#endif /* TMS320C30 */
#else
extern	SIZE	*g_alignments;	/* code generator alignment table */
#endif /* MULTIPLE_PROCESSORS */

#ifdef MULTIPLE_ASSEMBLERS
/*  Pointers to target code generator and assembler */
extern struct funcs	*Funcs;

#ifdef MC680X0
#ifdef TARGET_ACK
extern struct funcs	ack68k_funcs;
#endif /* TARGET_ACK */
#ifdef TARGET_GAS
extern struct funcs	gas68k_funcs;
#endif /* TARGET_GAS */
#ifdef TARGET_CPM
extern struct funcs	cpm68k_funcs;
#endif /* TARGET_CPM */
#ifdef TARGET_QMAC
extern struct funcs	qmac68k_funcs;
#endif /* TARGET_QMAC */
#endif /* MC680X0 */

#ifdef INTEL
#ifdef TARGET_MASM
extern struct funcs	masm386_funcs;
#endif /* TARGET_MASM */
#ifdef TARGET_BAS
extern struct funcs	bas386_funcs;
#endif /* TARGET_BAS */
#ifdef TARGET_GAS
extern struct funcs	gas386_funcs;
#endif /* TARGET_GAS */
#ifdef TARGET_SYSV
extern struct funcs	sysv386_funcs;
#endif /* TARGET_SYSV */
#endif /* INTEL */

#ifdef ARM
#ifdef TARGET_OBJ
extern struct funcs	armobj_funcs;
#endif /* TARGET_OBJ */
#endif /* ARM */

#ifdef TMS320C30
#ifdef TARGET_ROSSIN
extern struct funcs	rosc30_funcs;
#endif /* TARGET_ROSSIN */
#endif /* TMS320C30 */

#endif /* MULTIPLE_ASSEMBLERS */

extern char *external_prefix;	/* prefix for external/global symbols */
extern struct swtab *swtables;	/* switch jump tables to be output to the assembler file */
extern SIZE stack_offset;	/* the number of bytes to remove from the stack */
extern SIZE     max_scratch;	/* the maxmimum number of bytes allocated to temporary variables */
extern SIZE	act_scratch;	/* the current number of bytes allocated to temporary variables */
#endif /* CPU_DEFINED */

#endif /* _CGLBDEC_H */
