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