1 /* SDCCglobl.h - global macros etc required by all files */
16 * Define host port dependant constants etc.
19 #define UNIX_DIR_SEPARATOR_CHAR '/'
21 #if defined(__BORLANDC__) || defined(_MSC_VER)
22 #define STRCASECMP stricmp
23 #define STRNCASECMP strnicmp
25 #define STRCASECMP strcasecmp
26 #define STRNCASECMP strncasecmp
29 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
31 #ifndef HAVE_DOS_BASED_FILE_SYSTEM
32 #define HAVE_DOS_BASED_FILE_SYSTEM 1
35 #define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR_CHAR || (c) == UNIX_DIR_SEPARATOR_CHAR)
36 /* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
37 only semi-absolute. This is because the users of IS_ABSOLUTE_PATH
38 want to know whether to prepend the current working directory to
39 a file name, which should not be done with a name like d:foo. */
40 #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':')))
41 #define FILENAME_CMP(s1, s2) STRCASECMP(s1, s2)
43 #else /* not DOSish */
45 #define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR_CHAR)
46 #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
47 #define FILENAME_CMP(s1, s2) strcmp(s1, s2)
49 #endif /* not DOSish */
52 # define NATIVE_WIN32 1
54 # define PATH_MAX _MAX_PATH
60 #elif defined(_WIN32) && !defined(__MINGW32__)
63 # include "sdccconf.h"
71 #include <limits.h> /* PATH_MAX */
72 #if !defined(PATH_MAX) || (PATH_MAX < 2048)
74 # define PATH_MAX 2048 /* define a reasonable value */
77 #define MAX_REG_PARMS 1
81 # define max(a,b) (a > b ? a : b)
85 # define min(a,b) (a < b ? a : b)
97 #define CHARSIZE port->s.char_size
98 #define SHORTSIZE port->s.short_size
99 #define INTSIZE port->s.int_size
100 #define LONGSIZE port->s.long_size
101 #define PTRSIZE port->s.ptr_size
102 #define FPTRSIZE port->s.fptr_size
103 #define GPTRSIZE port->s.gptr_size
104 #define BITSIZE port->s.bit_size
105 #define FLOATSIZE port->s.float_size
106 #define MAXBASESIZE port->s.max_base_size
108 #define SMALL_MODEL 0
109 #define LARGE_MODEL 1
114 #define INITIAL_INLINEASM 4*1024
115 #define DEFPOOLSTACK(type,size) \
117 type *type##FreeStack [size] ; \
118 int type##StackPtr = 0 ;
120 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
121 #define PEEK(x) x##FreeStack[x##StackPtr-1]
122 #define POP(type) type##FreeStack[--type##StackPtr]
123 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
124 (assert(x##StackPtr),0)) */
126 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
128 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
132 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
135 /* general purpose stack related macros */
136 #define STACK_DCL(stack,type,size) \
137 typedef type t_##stack ; \
138 t_##stack stack[size] ; \
139 t_##stack (*p_##stack) = stack;
141 /* define extern stack */
142 #define EXTERN_STACK_DCL(stack,type,size) \
143 typedef type t_##stack ; \
144 extern t_##stack stack[size] ; \
145 extern t_##stack *p_##stack;
147 #define STACK_EMPTY(stack) ((p_##stack) <= stack )
148 #define STACK_FULL(stack) ((p_##stack) >= (stack + \
149 sizeof(stack)/sizeof(*stack)) )
151 #define STACK_PUSH_(stack, x) (*++p_##stack = (x))
152 #define STACK_POP_(stack) (*p_##stack--)
154 #define STACK_PUSH(stack, x) (STACK_FULL(stack) \
155 ? (STACK_ERR(1, stack), *p_##stack) \
156 : STACK_PUSH_(stack,x) )
158 #define STACK_POP(stack) (STACK_EMPTY(stack) \
159 ? (STACK_ERR(-1, stack), *p_##stack) \
160 : STACK_POP_(stack) )
162 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
163 ? (STACK_ERR(0, stack), *p_##stack) \
166 #define STACK_ERR(o, stack) (fatal(1, E_STACK_VIOLATION, #stack, \
173 /* optimization options */
175 * cloneOptimize function in SDCC.lex should be updated every time
176 * a new set is added to the optimize structure!
195 Used in options.model.A bit each as port.supported_models is an OR
205 MODEL_PAGE0 = 32, /* for the xa51 port */
206 MODEL_HUGE = 64 /* for banked support */
209 /* overlay segment name and the functions
210 that belong to it. used by pragma overlay */
212 char *osname; /* overlay segment name */
213 int nfuncs; /* number of functions in this overlay */
214 char *funcs[128]; /* function name that belong to this */
217 /* other command line options */
219 * cloneOptions function in SDCC.lex should be updated every time
220 * a new set is added to the options structure!
224 int model; /* see MODEL_* defines above */
225 int stackAuto; /* Stack Automatic */
226 int useXstack; /* use Xternal Stack */
227 int stack10bit; /* use 10 bit stack (flat24 model only) */
228 int dump_raw; /* dump after intermediate code generation */
229 int dump_gcse; /* dump after gcse */
230 int dump_loop; /* dump after loop optimizations */
231 int dump_kill; /* dump after dead code elimination */
232 int dump_range; /* dump after live range analysis */
233 int dump_pack; /* dump after register packing */
234 int dump_rassgn; /* dump after register assignment */
235 int dump_tree; /* dump front-end tree before lowering to iCode */
236 int cc_only; /* compile only flag */
237 int intlong_rent; /* integer & long support routines reentrant */
238 int float_rent; /* floating point routines are reentrant */
239 int out_fmt; /* 1 = motorola S19 format 0 = intel Hex format */
240 int cyclomatic; /* print cyclomatic information */
241 int noOverlay; /* don't overlay local variables & parameters */
242 int mainreturn; /* issue a return after main */
243 int xram_movc; /* use movc instead of movx to read xram (mcs51) */
244 int nopeep; /* no peep hole optimization */
245 int asmpeep; /* pass inline assembler thru peep hole */
246 int debug; /* generate extra debug info */
247 int c1mode; /* Act like c1 - no pre-proc, asm or link */
248 char *peep_file; /* additional rules for peep hole */
249 int nostdlib; /* Don't use standard lib files */
250 int nostdinc; /* Don't use standard include files */
251 int noRegParams; /* Disable passing some parameters in registers */
252 int verbose; /* Show what the compiler is doing */
253 int shortis8bits; /* treat short like int or char */
254 int lessPedantic; /* disable some warnings */
255 int profile; /* Turn on extra profiling information */
256 int ommitFramePtr; /* Turn off the frame pointer. */
257 int useAccelerator; /* use ds390 Arithmetic Accelerator */
258 int noiv; /* do not generate irq vector table entries */
259 int all_callee_saves; /* callee saves for all functions */
260 int stack_probe; /* insert call to function __stack_probe */
261 int tini_libid; /* library ID for TINI */
262 int protect_sp_update; /* DS390 - will disable interrupts during ESP:SP updates */
263 int parms_in_bank1; /* DS390 - use reg bank1 to pass parameters */
264 int stack_size; /* MCS51/DS390 - Tells the linker to allocate this space for stack */
265 int no_pack_iram; /* MCS51/DS390 - Tells the linker not to pack variables in internal ram */
266 int acall_ajmp; /* MCS51 - Use acall/ajmp instead of lcall/ljmp */
267 /* starting address of the segments */
268 int xstack_loc; /* initial location of external stack */
269 int stack_loc; /* initial value of internal stack pointer */
270 int xdata_loc; /* xternal ram starts at address */
271 int data_loc; /* interram start location */
272 int idata_loc; /* indirect address space */
273 int code_loc; /* code location start */
274 int iram_size; /* internal ram size (used only for error checking) */
275 int xram_size; /* external ram size (used only for error checking) */
276 bool xram_size_set; /* since xram_size=0 is a possibility */
277 int code_size; /* code size (used only for error checking) */
278 int verboseExec; /* show what we are doing */
279 int noXinitOpt; /* don't optimize initialized xdata */
280 int noCcodeInAsm; /* hide c-code from asm */
281 int iCodeInAsm; /* show i-code in asm */
282 int noPeepComments; /* hide peephole optimizer comments */
283 int verboseAsm; /* include comments generated with gen.c */
284 int printSearchDirs; /* display the directories in the compiler's search path */
285 int vc_err_style; /* errors and warnings are compatible with Micro$oft visual studio */
286 int use_stdout; /* send errors to stdout instead of stderr */
287 int no_std_crt0; /* for the z80/gbz80 do not link default crt0.o*/
288 int std_c99; /* enable C99 keywords/constructs */
289 int std_sdcc; /* enable SDCC extensions to C */
290 int dollars_in_ident; /* zero means dollar signs are punctuation */
291 int unsigned_char; /* use unsigned for char without signed/unsigned modifier */
292 char *code_seg; /* segment name to use instead of CSEG */
293 char *const_seg; /* segment name to use instead of CONST */
295 set *calleeSavesSet; /* list of functions using callee save */
296 set *excludeRegsSet; /* registers excluded from saving */
297 /* set *olaysSet; * not implemented yet: overlay segments used in #pragma OVERLAY */
300 /* forward definition for variables accessed globally */
301 extern int noAssemble; /* no assembly, stop after code generation */
303 extern char *lexFilename; /* lex idea of current file name */
304 extern int lexLineno; /* lex idea of line number of the current file */
305 extern char *fullSrcFileName; /* full name for the source file; */
306 /* can be NULL while linking without compiling */
307 extern char *fullDstFileName; /* full name for the output file; */
308 /* only given by -o, otherwise NULL */
309 extern char *dstFileName; /* destination file name without extension */
310 extern char *dstPath; /* path for the output files; */
311 /* "" is equivalent with cwd */
312 extern char *moduleName; /* module name is source file without path and extension */
313 /* can be NULL while linking without compiling */
314 extern int seqPointNo; /* current sequence point */
315 extern FILE *yyin; /* */
316 extern FILE *asmFile; /* assembly output file */
317 extern FILE *cdbFile; /* debugger symbol file */
318 extern int NestLevel; /* NestLevel SDCC.y */
319 extern int stackPtr; /* stack pointer SDCC.y */
320 extern int xstackPtr; /* external stack pointer SDCC.y */
321 extern int reentrant; /* /X flag has been sent SDCC.y */
322 extern char buffer[PATH_MAX * 2];/* general buffer SDCCmain.c */
323 extern int currRegBank; /* register bank being used SDCCgens.c */
324 extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */
325 extern int BitBankUsed; /* MB: overlayable bit bank SDCCmain.c */
326 extern struct symbol *currFunc; /* current function SDCCgens.c */
327 extern int cNestLevel; /* block nest level SDCCval.c */
328 extern int currBlockno; /* sequentail block number */
329 extern struct optimize optimize;
330 extern struct options options;
331 extern unsigned maxInterrupts;
332 extern int ignoreTypedefType;
334 /* Visible from SDCCmain.c */
335 extern set *preArgvSet;
336 extern set *relFilesSet;
337 extern set *libFilesSet;
338 extern set *libPathsSet;
339 extern set *libDirsSet; /* list of lib search directories */
341 void setParseWithComma (set **, const char *);
343 /** An assert() macro that will go out through sdcc's error
346 #define wassertl(a,s) ((a) ? 0 : \
347 (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
349 #define wassert(a) wassertl(a,"code generator internal error")
352 #define DUMP_RAW1 DUMP_RAW0+1
353 #define DUMP_CSE DUMP_RAW1+1
354 #define DUMP_DFLOW DUMP_CSE+1
355 #define DUMP_GCSE DUMP_DFLOW+1
356 #define DUMP_DEADCODE DUMP_GCSE+1
357 #define DUMP_LOOP DUMP_DEADCODE+1
358 #define DUMP_LOOPG DUMP_LOOP+1
359 #define DUMP_LOOPD DUMP_LOOPG+1
360 #define DUMP_RANGE DUMP_LOOPD+1
361 #define DUMP_PACK DUMP_RANGE+1
362 #define DUMP_RASSGN DUMP_PACK+1
363 #define DUMP_LRANGE DUMP_RASSGN+1
371 extern struct _dumpFiles dumpFiles[];
373 /* Buffer which can be used to hold a file name; assume it will
374 * be trashed by any function call within SDCC.
376 extern char scratchFileName[PATH_MAX];
378 /* Define well known filenos if the system does not define them. */
380 # define STDIN_FILENO 0
382 #ifndef STDOUT_FILENO
383 # define STDOUT_FILENO 1
385 #ifndef STDERR_FILENO
386 # define STDERR_FILENO 2