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