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 #if !defined(PATH_MAX) || (PATH_MAX < 2048)
43 # define PATH_MAX 2048 /* define a reasonable value */
46 #define MAX_REG_PARMS 1
50 # define max(a,b) (a > b ? a : b)
54 # define min(a,b) (a < b ? a : b)
66 #define CHARSIZE port->s.char_size
67 #define SHORTSIZE port->s.short_size
68 #define INTSIZE port->s.int_size
69 #define LONGSIZE port->s.long_size
70 #define PTRSIZE port->s.ptr_size
71 #define FPTRSIZE port->s.fptr_size
72 #define GPTRSIZE port->s.gptr_size
73 #define BITSIZE port->s.bit_size
74 #define FLOATSIZE port->s.float_size
75 #define MAXBASESIZE port->s.max_base_size
83 #define INITIAL_INLINEASM 4*1024
84 #define DEFPOOLSTACK(type,size) \
86 type *type##FreeStack [size] ; \
87 int type##StackPtr = 0 ;
89 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
90 #define PEEK(x) x##FreeStack[x##StackPtr-1]
91 #define POP(type) type##FreeStack[--type##StackPtr]
92 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
93 (assert(x##StackPtr),0)) */
95 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
97 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
101 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
104 /* general purpose stack related macros */
105 #define STACK_DCL(stack,type,size) \
106 typedef type t_##stack ; \
107 t_##stack stack[size] ; \
108 t_##stack (*p_##stack) = stack;
110 /* define extern stack */
111 #define EXTERN_STACK_DCL(stack,type,size) \
112 typedef type t_##stack ; \
113 extern t_##stack stack[size] ; \
114 extern t_##stack *p_##stack;
116 #define STACK_EMPTY(stack) ((p_##stack) <= stack )
117 #define STACK_FULL(stack) ((p_##stack) >= (stack + \
118 sizeof(stack)/sizeof(*stack)) )
120 #define STACK_PUSH_(stack, x) (*++p_##stack = (x))
121 #define STACK_POP_(stack) (*p_##stack--)
123 #define STACK_PUSH(stack, x) (STACK_FULL(stack) \
124 ? (STACK_ERR(1, stack), *p_##stack) \
125 : STACK_PUSH_(stack,x) )
127 #define STACK_POP(stack) (STACK_EMPTY(stack) \
128 ? (STACK_ERR(-1, stack), *p_##stack) \
129 : STACK_POP_(stack) )
131 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
132 ? (STACK_ERR(0, stack), *p_##stack) \
135 #define STACK_ERR(o, stack) (fatal(1, E_STACK_VIOLATION, #stack, \
142 /* optimization options */
144 * cloneOptimize function in SDCC.lex should be updated every time
145 * a new set is added to the optimize structure!
150 unsigned ptrArithmetic;
155 unsigned loopInvariant;
156 unsigned loopInduction;
157 unsigned noJTabBoundary;
158 unsigned noLoopReverse;
164 Used in options.model.A bit each as port.supported_models is an OR
174 MODEL_PAGE0 = 32, /* for the xa51 port */
175 MODEL_HUGE = 64 /* for banked support */
178 /* overlay segment name and the functions
179 that belong to it. used by pragma overlay */
181 char *osname; /* overlay segment name */
182 int nfuncs; /* number of functions in this overlay */
183 char *funcs[128]; /* function name that belong to this */
186 /* other command line options */
188 * cloneOptions function in SDCC.lex should be updated every time
189 * a new set is added to the options structure!
193 int model; /* see MODEL_* defines above */
194 int stackAuto; /* Stack Automatic */
195 int useXstack; /* use Xternal Stack */
196 int stack10bit; /* use 10 bit stack (flat24 model only) */
197 int dump_raw; /* dump after intermediate code generation */
198 int dump_gcse; /* dump after gcse */
199 int dump_loop; /* dump after loop optimizations */
200 int dump_kill; /* dump after dead code elimination */
201 int dump_range; /* dump after live range analysis */
202 int dump_pack; /* dump after register packing */
203 int dump_rassgn; /* dump after register assignment */
204 int dump_tree; /* dump front-end tree before lowering to iCode */
205 int cc_only; /* compile only flag */
206 int intlong_rent; /* integer & long support routines reentrant */
207 int float_rent; /* floating point routines are reentrant */
208 int out_fmt; /* 1 = motorola S19 format 0 = intel Hex format */
209 int cyclomatic; /* print cyclomatic information */
210 int noOverlay; /* don't overlay local variables & parameters */
211 int mainreturn; /* issue a return after main */
212 int xram_movc; /* use movc instead of movx to read xram (mcs51) */
213 int nopeep; /* no peep hole optimization */
214 int asmpeep; /* pass inline assembler thru peep hole */
215 int debug; /* generate extra debug info */
216 int c1mode; /* Act like c1 - no pre-proc, asm or link */
217 char *peep_file; /* additional rules for peep hole */
218 int nostdlib; /* Don't use standard lib files */
219 int nostdinc; /* Don't use standard include files */
220 int noRegParams; /* Disable passing some parameters in registers */
221 int verbose; /* Show what the compiler is doing */
222 int shortis8bits; /* treat short like int or char */
223 int lessPedantic; /* disable some warnings */
224 int profile; /* Turn on extra profiling information */
225 int ommitFramePtr; /* Turn off the frame pointer. */
226 int useAccelerator; /* use ds390 Arithmetic Accelerator */
227 int noiv; /* do not generate irq vector table entries */
228 int all_callee_saves; /* callee saves for all functions */
229 int stack_probe; /* insert call to function __stack_probe */
230 int tini_libid; /* library ID for TINI */
231 int protect_sp_update; /* DS390 - will disable interrupts during ESP:SP updates */
232 int parms_in_bank1; /* DS390 - use reg bank1 to pass parameters */
233 int stack_size; /* MCS51/DS390 - Tells the linker to allocate this space for stack */
234 int no_pack_iram; /* MCS51/DS390 - Tells the linker not to pack variables in internal ram */
235 /* starting address of the segments */
236 int xstack_loc; /* initial location of external stack */
237 int stack_loc; /* initial value of internal stack pointer */
238 int xdata_loc; /* xternal ram starts at address */
239 int data_loc; /* interram start location */
240 int idata_loc; /* indirect address space */
241 int code_loc; /* code location start */
242 int iram_size; /* internal ram size (used only for error checking) */
243 int xram_size; /* external ram size (used only for error checking) */
244 bool xram_size_set; /* since xram_size=0 is a possibility */
245 int code_size; /* code size (used only for error checking) */
246 int verboseExec; /* show what we are doing */
247 int noXinitOpt; /* don't optimize initialized xdata */
248 int noCcodeInAsm; /* hide c-code from asm */
249 int iCodeInAsm; /* show i-code in asm */
250 int noPeepComments; /* hide peephole optimizer comments */
251 int printSearchDirs; /* display the directories in the compiler's search path */
252 int vc_err_style; /* errors and warnings are compatible with Micro$oft visual studio */
253 int use_stdout; /* send errors to stdout instead of stderr */
254 int no_std_crt0; /* for the z80/gbz80 do not link default crt0.o*/
255 int std_c99; /* enable C99 keywords/constructs */
256 int std_sdcc; /* enable SDCC extensions to C */
257 const char *code_seg; /* segment name to use instead of CSEG */
258 const char *const_seg; /* segment name to use instead of CONST */
260 set *calleeSavesSet; /* list of functions using callee save */
261 set *excludeRegsSet; /* registers excluded from saving */
262 /* set *olaysSet; * not implemented yet: overlay segments used in #pragma OVERLAY */
265 /* forward definition for variables accessed globally */
266 extern int noAssemble; /* no assembly, stop after code generation */
268 extern char *currFname;
269 extern char *fullSrcFileName; /* full name for the source file; */
270 /* can be NULL while linking without compiling */
271 extern char *fullDstFileName; /* full name for the output file; */
272 /* only given by -o, otherwise NULL */
273 extern char *dstFileName; /* destination file name without extension */
274 extern char *dstPath; /* path for the output files; */
275 /* "" is equivalent with cwd */
276 extern char *moduleName; /* module name is source file without path and extension */
277 /* can be NULL while linking without compiling */
278 extern int seqPointNo; /* current sequence point */
279 extern int currLineno; /* current line number */
280 extern int mylineno; /* line number of the current file SDCC.lex */
281 extern FILE *yyin; /* */
282 extern FILE *asmFile; /* assembly output file */
283 extern FILE *cdbFile; /* debugger symbol file */
284 extern int NestLevel; /* NestLevel SDCC.y */
285 extern int stackPtr; /* stack pointer SDCC.y */
286 extern int xstackPtr; /* external stack pointer SDCC.y */
287 extern int reentrant; /* /X flag has been sent SDCC.y */
288 extern char buffer[PATH_MAX * 2];/* general buffer SDCCmain.c */
289 extern int currRegBank; /* register bank being used SDCCgens.c */
290 extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */
291 extern struct symbol *currFunc; /* current function SDCCgens.c */
292 extern int cNestLevel; /* block nest level SDCCval.c */
293 extern int currBlockno; /* sequentail block number */
294 extern struct optimize optimize;
295 extern struct options options;
296 extern unsigned maxInterrupts;
297 extern int ignoreTypedefType;
299 /* Visible from SDCCmain.c */
300 extern set *preArgvSet;
301 extern set *relFilesSet;
302 extern set *libFilesSet;
303 extern set *libPathsSet;
304 extern set *libDirsSet; /* list of lib search directories */
306 void setParseWithComma (set **, char *);
308 /** Creates a temporary file a'la tmpfile which avoids the bugs
309 in cygwin wrt c:\tmp.
310 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
312 FILE *tempfile (void);
314 /** Creates a temporary file name a'la tmpnam which avoids the bugs
315 in cygwin wrt c:\tmp.
316 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
318 char *tempfilename (void);
320 /** An assert() macro that will go out through sdcc's error
323 #define wassertl(a,s) ((a) ? 0 : \
324 (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
326 #define wassert(a) wassertl(a,"code generator internal error")
329 #define DUMP_RAW1 DUMP_RAW0+1
330 #define DUMP_CSE DUMP_RAW1+1
331 #define DUMP_DFLOW DUMP_CSE+1
332 #define DUMP_GCSE DUMP_DFLOW+1
333 #define DUMP_DEADCODE DUMP_GCSE+1
334 #define DUMP_LOOP DUMP_DEADCODE+1
335 #define DUMP_LOOPG DUMP_LOOP+1
336 #define DUMP_LOOPD DUMP_LOOPG+1
337 #define DUMP_RANGE DUMP_LOOPD+1
338 #define DUMP_PACK DUMP_RANGE+1
339 #define DUMP_RASSGN DUMP_PACK+1
340 #define DUMP_LRANGE DUMP_RASSGN+1
348 extern struct _dumpFiles dumpFiles[];
350 /* Buffer which can be used to hold a file name; assume it will
351 * be trashed by any function call within SDCC.
353 extern char scratchFileName[PATH_MAX];
355 /* Define well known filenos if the system does not define them. */
357 # define STDIN_FILENO 0
359 #ifndef STDOUT_FILENO
360 # define STDOUT_FILENO 1
362 #ifndef STDERR_FILENO
363 # define STDERR_FILENO 2