// (c) 1995-2007 Electronic Arts Inc.

/*
	CYMBAL.H

		Header file for cymbal tool.

	History:
		Created 1-Dec-1995, Y. King.
 */

#ifndef CYMBAL_H
#define CYMBAL_H

/* Object types. The OPTobjtype option determines which
   preprocessor to invoke to collect symbol information. */

#define SGI 		1
#define U64 		2
#define WATCOM		3
#define PSX 		4
#define PS2 		5
#define GC			6

/* Max number of symbols and files user can explicitly
   request information for. */

#define MAX_SYMBOLS 	256
#define MAX_OBJS		2048
#define MAX_FILES		32

/* Size of hash table used for symbols. */

#define HASH_BUCKETS	256

/* -- Types -- */

/* Symbol types. */

typedef enum
{
	UNKNOWN = 0,
	FUNCTION = 1,
	DATA = 2
}
	SYMTYPE;

/* Symbol scopes. */

typedef enum
{
	GLOBAL = 1,
	LOCAL = 2
}
	SYMSCOPE;

/* Symbol info. Stored as a linked list. */

typedef struct _tagsymbol
{
	char		*name;
	SYMTYPE 	type;
	SYMSCOPE	scope;
	int 		size;
	struct _tagfileinfo *file;

	struct _tagsymbol	*next;
}
	SYMBOL;

/* Linked list of pointers to symbols. */
typedef struct _tagsymlist
{
	SYMBOL	*symbol;

	struct _tagsymlist	*next;
}
	SYMLIST;

/* Info on files. */
typedef struct _tagfileinfo
{
	char	*name;
	char	*libraryname;
	char	*sourcename;
	int    sourcedate;
	int 	size;
	SYMLIST *defines;
	SYMLIST *refers;

	struct _tagfileinfo *next;
}
	FILEINFO;

/* Linked list of pointers to file info. */
typedef struct _tagfilelist
{
	FILEINFO	*file;
	int 		info;
	SYMBOL		*symbol;

	struct _tagfilelist *next;
}
	FILELIST;

	/* Top level info stored for symbols and files. */
typedef struct
{
	SYMLIST 	*symtable;			/* Symbol hash table. */
	FILEINFO	*files; 			/* List of file info. */
}
	CYMINFO;

/* -- Prototypes -- */

/* Top level .cym file processing. */
int 		cymbal(char *cymfname, char *reportfname);
CYMINFO 	*cymload(char *cymfname);
int 		cymreport(char *reportfname, CYMINFO *cyminfo,
			  char *symbols[], int nsymbols,
			  char *files[], int nfiles,
			  int define, int refer, int need, int recurse);
int 		cymfilereport(FILE *report, CYMINFO *cyminfo,
				  char *files[], int nfiles,
				  int define, int refer, int need, int recurse);
int 		cymsymbolreport(FILE *report, CYMINFO *cyminfo,
				 char *symbols[], int nsymbols,
					int define, int refer, int need, int recurse);

/* Symbol info internal functions. */
CYMINFO 	*cinew(void);
FILEINFO	*finew(const char *fname, const char *libname);
SYMBOL		*symnew(char *name, SYMTYPE type, SYMSCOPE scope, int size);
SYMLIST 	*slnew(void);
SYMBOL		*symadd(SYMLIST *table, SYMBOL *symbol);
SYMBOL		*symfind(SYMLIST *table, char *name);
SYMBOL		*symfindnth(SYMLIST *table, char *name, int n);
FILELIST	*symneedfiles(SYMBOL *sym, FILELIST *files, int recurse, int level);
int 		symhash(char *name);

char		*symname(SYMBOL *sym);
char		*symfile(SYMBOL *sym);
char		*symtype(SYMBOL *sym);
char		*symscope(SYMBOL *sym);
int 		symsize(SYMBOL *sym);

/* .cym file generation functions (platform-specific). */
int 		watcym(char *srcname, char *dstname);
int 		sgicym(char *srcname, char *dstname);

#endif // CYMBAL_H

