1 /*
2 	qfcc.h
3 
4 	QuakeForge Code Compiler (main program)
5 
6 	Copyright (C) 1996-1997 id Software, Inc.
7 	Copyright (C) 2001 Jeff Teunissen <deek@quakeforge.net>
8 	Copyright (C) 2001 Bill Currie <bill@taniwha.org>
9 
10 	This program is free software; you can redistribute it and/or
11 	modify it under the terms of the GNU General Public License
12 	as published by the Free Software Foundation; either version 2
13 	of the License, or (at your option) any later version.
14 
15 	This program is distributed in the hope that it will be useful,
16 	but WITHOUT ANY WARRANTY; without even the implied warranty of
17 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 	See the GNU General Public License for more details.
20 
21 	You should have received a copy of the GNU General Public License
22 	along with this program; if not, write to:
23 
24 		Free Software Foundation, Inc.
25 		59 Temple Place - Suite 330
26 		Boston, MA  02111-1307, USA
27 
28 */
29 
30 #ifndef __qfcc_h
31 #define __qfcc_h
32 
33 /** \defgroup qfcc QuakeC compiler
34 */
35 
36 #include <stdio.h>
37 #include "QF/pr_comp.h"
38 
39 /** \defgroup qfcc_general General functions
40 	\ingroup qfcc
41 */
42 //@{
43 
44 typedef struct srcline_s srcline_t;
45 struct srcline_s {
46 	srcline_t  *next;
47 	string_t    source_file;
48 	int         source_line;
49 };
50 
51 /**	Output generated by prog parsing.
52 */
53 typedef struct pr_info_s {
54 	struct type_s	*types;
55 
56 	struct function_s *func_head;
57 	struct function_s **func_tail;
58 	dfunction_t		*functions;
59 	int				num_functions;
60 
61 	struct strpool_s *strings;			///< progs string data
62 	struct codespace_s *code;			///< progs code data
63 	struct defspace_s *near_data;		///< data directly addressable by
64 										///< statments (address < 64k)
65 	struct defspace_s *far_data;		///< data that might not be directly
66 										///< addressabe by statements (address
67 										///< possibly > 64k)
68 	struct defspace_s *entity_data;		///< entity field address space. no
69 										///< data is stored in the progs file
70 	struct defspace_s *type_data;		///< encoded type information.
71 
72 	struct symtab_s *symtab;
73 	struct symtab_s *entity_fields;
74 
75 	srcline_t      *srcline_stack;
76 	string_t        source_file;
77 	int             source_line;
78 	int             error_count;
79 
80 	struct reloc_s *relocs;
81 
82 	struct pr_auxfunction_s *auxfunctions;
83 	int             auxfunctions_size;
84 	int             num_auxfunctions;
85 
86 	struct pr_lineno_s *linenos;
87 	int             linenos_size;
88 	int             num_linenos;
89 } pr_info_t;
90 
91 extern	pr_info_t	pr;
92 
93 #define GETSTR(s)			(pr.strings->strings + (s))
94 #define D_var(t, d)			((d)->space->data[(d)->offset].t##_var)
95 #define	D_FLOAT(d)			D_var (float, d)
96 #define	D_INT(d)			D_var (integer, d)
97 #define	D_VECTOR(d)			D_var (vector, d)
98 #define	D_QUAT(d)			D_var (quat, d)
99 #define	D_STRING(d)			D_var (string, d)
100 #define	D_GETSTR(d)			GETSTR (D_STRING (d))
101 #define	D_FUNCTION(d)		D_var (func, d)
102 #define D_POINTER(t,d)		((t *)((d)->space->data + (d)->offset))
103 #define D_STRUCT(t,d)		(*D_POINTER (t, d))
104 
105 #define G_POINTER(s,t,o)	((t *)((s)->data + o))
106 #define G_STRUCT(s,t,o)		(*G_POINTER (s, t, o))
107 
108 #define POINTER_OFS(s,p)	((pr_type_t *) (p) - (s)->data)
109 
110 const char *strip_path (const char *filename);
111 
112 extern FILE *qc_yyin;
113 extern FILE *qp_yyin;
114 int qc_yyparse (void);
115 int qp_yyparse (void);
116 extern int qc_yydebug;
117 extern int qp_yydebug;
118 
119 #ifdef _WIN32
120 char *fix_backslash (char *path);
121 #define NORMALIZE(x) fix_backslash (x)
122 #else
123 #define NORMALIZE(x) x
124 #endif
125 
126 /**	Round \a x up to the next multiple of \a a.
127 	\note \a a must be a power of two or this will break.
128 	\note There are no side effects on \a x.
129 	\param x		The value to be rounded up.
130 	\param a		The rounding factor.
131 	\return			The rounded value.
132 */
133 #define RUP(x,a) (((x) + ((a) - 1)) & ~((a) - 1))
134 
135 //@}
136 
137 #endif//__qfcc_h
138