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