1 /* SDCCglobl.h - global macros etc required by all files */
11 * Define host port dependant constants etc.
14 #define DOS_DIR_SEPARATOR_CHAR '\\'
15 #define DOS_DIR_SEPARATOR_STRING "\\"
16 #define UNIX_DIR_SEPARATOR_CHAR '/'
17 #define UNIX_DIR_SEPARATOR_STRING "/"
19 #ifdef _WIN32 /* WIN32 native */
21 #define NATIVE_WIN32 1
22 #ifdef __MINGW32__ /* GCC MINGW32 depends on configure */
26 #define PATH_MAX _MAX_PATH
28 #define DIR_SEPARATOR_CHAR DOS_DIR_SEPARATOR_CHAR
29 #define DIR_SEPARATOR_STRING DOS_DIR_SEPARATOR_STRING
31 #else /* Assume Un*x style system */
34 #define DIR_SEPARATOR_CHAR UNIX_DIR_SEPARATOR_CHAR
35 #define DIR_SEPARATOR_STRING UNIX_DIR_SEPARATOR_STRING
44 #include <limits.h> /* PATH_MAX */
45 #ifndef PATH_MAX /* POSIX, but not required */
46 #define PATH_MAX 255 /* define a reasonable value */
49 #define MAX_REG_PARMS 1
53 #define max(a,b) (a > b ? a : b)
57 #define min(a,b) (a < b ? a : b)
69 #define CHARSIZE port->s.char_size
70 #define SHORTSIZE port->s.short_size
71 #define INTSIZE port->s.int_size
72 #define LONGSIZE port->s.long_size
73 #define PTRSIZE port->s.ptr_size
74 #define FPTRSIZE port->s.fptr_size
75 #define GPTRSIZE port->s.gptr_size
76 #define BITSIZE port->s.bit_size
77 #define FLOATSIZE port->s.float_size
78 #define MAXBASESIZE port->s.max_base_size
81 #define PRAGMA_SAVE "SAVE"
82 #define PRAGMA_RESTORE "RESTORE"
83 #define PRAGMA_NOINDUCTION "NOINDUCTION"
84 #define PRAGMA_NOINVARIANT "NOINVARIANT"
85 #define PRAGMA_NOLOOPREV "NOLOOPREVERSE"
86 #define PRAGMA_INDUCTION "INDUCTION"
87 #define PRAGMA_STACKAUTO "STACKAUTO"
88 #define PRAGMA_NOJTBOUND "NOJTBOUND"
89 #define PRAGMA_NOGCSE "NOGCSE"
90 #define PRAGMA_NOOVERLAY "NOOVERLAY"
91 #define PRAGMA_CALLEESAVES "CALLEE-SAVES"
92 #define PRAGMA_EXCLUDE "EXCLUDE"
93 #define PRAGMA_NOIV "NOIV"
94 #define PRAGMA_OVERLAY "OVERLAY"
101 #define INITIAL_INLINEASM 4*1024
102 #define DEFPOOLSTACK(type,size) \
104 type *type##FreeStack [size] ; \
105 int type##StackPtr = 0 ;
107 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
108 #define PEEK(x) x##FreeStack[x##StackPtr-1]
109 #define POP(type) type##FreeStack[--type##StackPtr]
110 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
111 (assert(x##StackPtr),0)) */
113 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
115 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
119 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
122 /* generalpurpose stack related macros */
123 #define STACK_DCL(stack,type,size) \
124 typedef type t_##stack ; \
125 t_##stack stack[size] ; \
126 t_##stack (*p_##stack) = stack + (size); \
128 /* define extern stack */
129 #define EXTERN_STACK_DCL(stack,type,size) \
130 typedef type t_##stack ; \
131 extern t_##stack stack[size] ; \
132 extern t_##stack *p_##stack;
134 #define STACK_FULL(stack) ((p_##stack) <= stack )
135 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
136 sizeof(stack)/sizeof(*stack)) )
138 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
139 #define STACK_POP_(stack) (*p_##stack++)
141 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
142 ?((t_##stack)(long)(STACK_ERR(1))) \
143 : STACK_PUSH_(stack,x) )
145 #define STACK_POP(stack) (STACK_EMPTY(stack) \
146 ?((t_##stack)(long)(STACK_ERR(0))) \
147 : STACK_POP_(stack) )
149 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
150 ?((t_##stack) NULL) \
153 #define STACK_ERR(o) ( o \
154 ? fprintf(stderr,"stack Overflow\n")\
155 : fprintf(stderr,"stack underflow\n"))
157 /* optimization options */
161 unsigned ptrArithmetic;
166 unsigned loopInvariant;
167 unsigned loopInduction;
168 unsigned noJTabBoundary;
169 unsigned noLoopReverse;
173 Used in options.model.A bit each as port.supported_models is an OR
183 MODEL_PAGE0 = 32 /* for the xa51 port */
186 /* overlay segment name and the functions
187 that belong to it. used by pragma overlay */
189 char *osname; /* overlay segment name */
190 int nfuncs; /* number of functions in this overlay */
191 char *funcs[128]; /* function name that belong to this */
194 /* other command line options */
197 int model; /* see MODEL_* defines above */
198 int stackAuto; /* Stack Automatic */
199 int useXstack; /* use Xternal Stack */
200 int stack10bit; /* use 10 bit stack (flat24 model only) */
201 int dump_raw; /* dump after intermediate code generation */
202 int dump_gcse; /* dump after gcse */
203 int dump_loop; /* dump after loop optimizations */
204 int dump_kill; /* dump after dead code elimination */
205 int dump_range; /* dump after live range analysis */
206 int dump_pack; /* dump after register packing */
207 int dump_rassgn; /* dump after register assignment */
208 int dump_tree; /* dump front-end tree before lowering to iCode */
209 int cc_only; /* compile only flag */
210 int intlong_rent; /* integer & long support routines reentrant */
211 int float_rent; /* floating point routines are reentrant */
212 int out_fmt; /* 1 = motorola S19 format 0 = intel Hex format */
213 int cyclomatic; /* print cyclomatic information */
214 int noOverlay; /* don't overlay local variables & parameters */
215 int mainreturn; /* issue a return after main */
216 int xram_movc; /* use movc instead of movx to read xram (mcs51) */
217 int nopeep; /* no peep hole optimization */
218 int asmpeep; /* pass inline assembler thru peep hole */
219 int debug; /* generate extra debug info */
220 int c1mode; /* Act like c1 - no pre-proc, asm or link */
221 char *peep_file; /* additional rules for peep hole */
222 int nostdlib; /* Don't use standard lib files */
223 int nostdinc; /* Don't use standard include files */
224 int noRegParams; /* Disable passing some parameters in registers */
225 int verbose; /* Show what the compiler is doing */
226 int shortis8bits; /* treat short like int or char */
227 int lessPedantic; /* disable some warnings */
228 int profile; /* Turn on extra profiling information */
229 int ommitFramePtr; /* Turn off the frame pointer. */
230 int useAccelerator; /* use ds390 Arithmetic Accelerator */
231 char *calleeSaves[128]; /* list of functions using callee save */
232 char *excludeRegs[32]; /* registers excluded from saving */
233 int noiv; /* do not generate irq vector table entries */
234 int all_callee_saves; /* callee saves for all functions */
235 int stack_probe; /* insert call to function __stack_probe */
236 int tini_libid; /* library ID for TINI */
237 int protect_sp_update; /* DS390 - will disable interrupts during ESP:SP updates */
238 int parms_in_bank1; /* DS390 - use reg bank1 to pass parameters */
239 olay olays[128]; /* overlay segments used in #pragma OVERLAY */
240 /* starting address of the segments */
241 int xstack_loc; /* initial location of external stack */
242 int stack_loc; /* initial value of internal stack pointer */
243 int xdata_loc; /* xternal ram starts at address */
244 int data_loc; /* interram start location */
245 int idata_loc; /* indirect address space */
246 int code_loc; /* code location start */
247 int iram_size; /* internal ram size (used only for error checking) */
248 int xram_size; /* external ram size (used only for error checking) */
249 bool xram_size_set; /* since xram_size=0 is a possibility */
250 int code_size; /* code size (used only for error checking) */
251 int verboseExec; /* show what we are doing */
252 int noXinitOpt; /* don't optimize initialized xdata */
253 int noCcodeInAsm; /* hide c-code from asm */
254 int iCodeInAsm; /* show i-code in asm */
257 /* forward definition for variables accessed globally */
258 extern int noAssemble; /* no assembly, stop after code generation */
260 extern char *currFname;
261 extern char *fullSrcFileName; /* full name for the source file; */
262 /* can be NULL while linking without compiling */
263 extern char *fullDstFileName; /* full name for the output file; */
264 /* only given by -o, otherwise NULL */
265 extern char *dstFileName; /* destination file name without extension */
266 extern char *dstPath; /* path for the output files; */
267 /* "" is equivalent with cwd */
268 extern char *moduleName; /* module name is source file without path and extension */
269 /* can be NULL while linking without compiling */
270 extern int currLineno; /* current line number */
271 extern int yylineno; /* line number of the current file SDCC.lex */
272 extern FILE *yyin; /* */
273 extern FILE *asmFile; /* assembly output file */
274 extern FILE *cdbFile; /* debugger symbol file */
275 extern int NestLevel; /* NestLevel SDCC.y */
276 extern int stackPtr; /* stack pointer SDCC.y */
277 extern int xstackPtr; /* external stack pointer SDCC.y */
278 extern int reentrant; /* /X flag has been sent SDCC.y */
279 extern char buffer[PATH_MAX * 2];/* general buffer SDCCmain.c */
280 extern int currRegBank; /* register bank being used SDCCgens.c */
281 extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */
282 extern struct symbol *currFunc; /* current function SDCCgens.c */
283 extern int cNestLevel; /* block nest level SDCCval.c */
284 extern int currBlockno; /* sequentail block number */
285 extern struct optimize optimize;
286 extern struct options options;
287 extern unsigned maxInterrupts;
289 /* Visible from SDCCmain.c */
290 extern int nrelFiles;
291 extern char *relFiles[128];
292 extern char *libFiles[128];
293 extern int nlibFiles;
294 extern char *libPaths[128];
295 extern int nlibPaths;
297 void parseWithComma (char **, char *);
299 /** Creates a temporary file a'la tmpfile which avoids the bugs
300 in cygwin wrt c:\tmp.
301 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
303 FILE *tempfile (void);
305 /** Creates a temporary file name a'la tmpnam which avoids the bugs
306 in cygwin wrt c:\tmp.
307 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
309 char *tempfilename (void);
311 /** An assert() macro that will go out through sdcc's error
314 #define wassertl(a,s) ((a) ? 0 : \
315 (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
317 #define wassert(a) wassertl(a,"code generator internal error")
320 #define DUMP_RAW1 DUMP_RAW0+1
321 #define DUMP_CSE DUMP_RAW1+1
322 #define DUMP_DFLOW DUMP_CSE+1
323 #define DUMP_GCSE DUMP_DFLOW+1
324 #define DUMP_DEADCODE DUMP_GCSE+1
325 #define DUMP_LOOP DUMP_DEADCODE+1
326 #define DUMP_LOOPG DUMP_LOOP+1
327 #define DUMP_LOOPD DUMP_LOOPG+1
328 #define DUMP_RANGE DUMP_LOOPD+1
329 #define DUMP_PACK DUMP_RANGE+1
330 #define DUMP_RASSGN DUMP_PACK+1
331 #define DUMP_LRANGE DUMP_RASSGN+1
339 extern struct _dumpFiles dumpFiles[];
341 /* Buffer which can be used to hold a file name; assume it will
342 * be trashed by any function call within SDCC.
344 extern char scratchFileName[PATH_MAX];