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
82 #define INITIAL_INLINEASM 4*1024
83 #define DEFPOOLSTACK(type,size) \
85 type *type##FreeStack [size] ; \
86 int type##StackPtr = 0 ;
88 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
89 #define PEEK(x) x##FreeStack[x##StackPtr-1]
90 #define POP(type) type##FreeStack[--type##StackPtr]
91 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
92 (assert(x##StackPtr),0)) */
94 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
96 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
100 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
103 /* general purpose stack related macros */
104 #define STACK_DCL(stack,type,size) \
105 typedef type t_##stack ; \
106 t_##stack stack[size] ; \
107 t_##stack (*p_##stack) = stack;
109 /* define extern stack */
110 #define EXTERN_STACK_DCL(stack,type,size) \
111 typedef type t_##stack ; \
112 extern t_##stack stack[size] ; \
113 extern t_##stack *p_##stack;
115 #define STACK_EMPTY(stack) ((p_##stack) <= stack )
116 #define STACK_FULL(stack) ((p_##stack) >= (stack + \
117 sizeof(stack)/sizeof(*stack)) )
119 #define STACK_PUSH_(stack, x) (*++p_##stack = (x))
120 #define STACK_POP_(stack) (*p_##stack--)
122 #define STACK_PUSH(stack, x) (STACK_FULL(stack) \
123 ? (STACK_ERR(1, stack), *p_##stack) \
124 : STACK_PUSH_(stack,x) )
126 #define STACK_POP(stack) (STACK_EMPTY(stack) \
127 ? (STACK_ERR(-1, stack), *p_##stack) \
128 : STACK_POP_(stack) )
130 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
131 ? (STACK_ERR(0, stack), *p_##stack) \
134 #define STACK_ERR(o, stack) (fatal(1, E_STACK_VIOLATION, #stack, \
141 /* optimization options */
145 unsigned ptrArithmetic;
150 unsigned loopInvariant;
151 unsigned loopInduction;
152 unsigned noJTabBoundary;
153 unsigned noLoopReverse;
157 Used in options.model.A bit each as port.supported_models is an OR
167 MODEL_PAGE0 = 32 /* for the xa51 port */
170 /* overlay segment name and the functions
171 that belong to it. used by pragma overlay */
173 char *osname; /* overlay segment name */
174 int nfuncs; /* number of functions in this overlay */
175 char *funcs[128]; /* function name that belong to this */
178 /* other command line options */
181 int model; /* see MODEL_* defines above */
182 int stackAuto; /* Stack Automatic */
183 int useXstack; /* use Xternal Stack */
184 int stack10bit; /* use 10 bit stack (flat24 model only) */
185 int dump_raw; /* dump after intermediate code generation */
186 int dump_gcse; /* dump after gcse */
187 int dump_loop; /* dump after loop optimizations */
188 int dump_kill; /* dump after dead code elimination */
189 int dump_range; /* dump after live range analysis */
190 int dump_pack; /* dump after register packing */
191 int dump_rassgn; /* dump after register assignment */
192 int dump_tree; /* dump front-end tree before lowering to iCode */
193 int cc_only; /* compile only flag */
194 int intlong_rent; /* integer & long support routines reentrant */
195 int float_rent; /* floating point routines are reentrant */
196 int out_fmt; /* 1 = motorola S19 format 0 = intel Hex format */
197 int cyclomatic; /* print cyclomatic information */
198 int noOverlay; /* don't overlay local variables & parameters */
199 int mainreturn; /* issue a return after main */
200 int xram_movc; /* use movc instead of movx to read xram (mcs51) */
201 int nopeep; /* no peep hole optimization */
202 int asmpeep; /* pass inline assembler thru peep hole */
203 int debug; /* generate extra debug info */
204 int c1mode; /* Act like c1 - no pre-proc, asm or link */
205 char *peep_file; /* additional rules for peep hole */
206 int nostdlib; /* Don't use standard lib files */
207 int nostdinc; /* Don't use standard include files */
208 int noRegParams; /* Disable passing some parameters in registers */
209 int verbose; /* Show what the compiler is doing */
210 int shortis8bits; /* treat short like int or char */
211 int lessPedantic; /* disable some warnings */
212 int profile; /* Turn on extra profiling information */
213 int ommitFramePtr; /* Turn off the frame pointer. */
214 int useAccelerator; /* use ds390 Arithmetic Accelerator */
215 char *calleeSaves[128]; /* list of functions using callee save */
216 char *excludeRegs[32]; /* registers excluded from saving */
217 int noiv; /* do not generate irq vector table entries */
218 int all_callee_saves; /* callee saves for all functions */
219 int stack_probe; /* insert call to function __stack_probe */
220 int tini_libid; /* library ID for TINI */
221 int protect_sp_update; /* DS390 - will disable interrupts during ESP:SP updates */
222 int parms_in_bank1; /* DS390 - use reg bank1 to pass parameters */
223 olay olays[128]; /* overlay segments used in #pragma OVERLAY */
224 /* starting address of the segments */
225 int xstack_loc; /* initial location of external stack */
226 int stack_loc; /* initial value of internal stack pointer */
227 int xdata_loc; /* xternal ram starts at address */
228 int data_loc; /* interram start location */
229 int idata_loc; /* indirect address space */
230 int code_loc; /* code location start */
231 int iram_size; /* internal ram size (used only for error checking) */
232 int xram_size; /* external ram size (used only for error checking) */
233 bool xram_size_set; /* since xram_size=0 is a possibility */
234 int code_size; /* code size (used only for error checking) */
235 int verboseExec; /* show what we are doing */
236 int noXinitOpt; /* don't optimize initialized xdata */
237 int noCcodeInAsm; /* hide c-code from asm */
238 int iCodeInAsm; /* show i-code in asm */
241 /* forward definition for variables accessed globally */
242 extern int noAssemble; /* no assembly, stop after code generation */
244 extern char *currFname;
245 extern char *fullSrcFileName; /* full name for the source file; */
246 /* can be NULL while linking without compiling */
247 extern char *fullDstFileName; /* full name for the output file; */
248 /* only given by -o, otherwise NULL */
249 extern char *dstFileName; /* destination file name without extension */
250 extern char *dstPath; /* path for the output files; */
251 /* "" is equivalent with cwd */
252 extern char *moduleName; /* module name is source file without path and extension */
253 /* can be NULL while linking without compiling */
254 extern int currLineno; /* current line number */
255 extern int yylineno; /* line number of the current file SDCC.lex */
256 extern FILE *yyin; /* */
257 extern FILE *asmFile; /* assembly output file */
258 extern FILE *cdbFile; /* debugger symbol file */
259 extern int NestLevel; /* NestLevel SDCC.y */
260 extern int stackPtr; /* stack pointer SDCC.y */
261 extern int xstackPtr; /* external stack pointer SDCC.y */
262 extern int reentrant; /* /X flag has been sent SDCC.y */
263 extern char buffer[PATH_MAX * 2];/* general buffer SDCCmain.c */
264 extern int currRegBank; /* register bank being used SDCCgens.c */
265 extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */
266 extern struct symbol *currFunc; /* current function SDCCgens.c */
267 extern int cNestLevel; /* block nest level SDCCval.c */
268 extern int currBlockno; /* sequentail block number */
269 extern struct optimize optimize;
270 extern struct options options;
271 extern unsigned maxInterrupts;
273 /* Visible from SDCCmain.c */
274 extern int nrelFiles;
275 extern char *relFiles[128];
276 extern char *libFiles[128];
277 extern int nlibFiles;
278 extern char *libPaths[128];
279 extern int nlibPaths;
281 void setParseWithComma (set **, char *);
282 void parseWithComma (char **, char *);
284 /** Creates a temporary file a'la tmpfile which avoids the bugs
285 in cygwin wrt c:\tmp.
286 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
288 FILE *tempfile (void);
290 /** Creates a temporary file name a'la tmpnam which avoids the bugs
291 in cygwin wrt c:\tmp.
292 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
294 char *tempfilename (void);
296 /** An assert() macro that will go out through sdcc's error
299 #define wassertl(a,s) ((a) ? 0 : \
300 (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
302 #define wassert(a) wassertl(a,"code generator internal error")
305 #define DUMP_RAW1 DUMP_RAW0+1
306 #define DUMP_CSE DUMP_RAW1+1
307 #define DUMP_DFLOW DUMP_CSE+1
308 #define DUMP_GCSE DUMP_DFLOW+1
309 #define DUMP_DEADCODE DUMP_GCSE+1
310 #define DUMP_LOOP DUMP_DEADCODE+1
311 #define DUMP_LOOPG DUMP_LOOP+1
312 #define DUMP_LOOPD DUMP_LOOPG+1
313 #define DUMP_RANGE DUMP_LOOPD+1
314 #define DUMP_PACK DUMP_RANGE+1
315 #define DUMP_RASSGN DUMP_PACK+1
316 #define DUMP_LRANGE DUMP_RASSGN+1
324 extern struct _dumpFiles dumpFiles[];
326 /* Buffer which can be used to hold a file name; assume it will
327 * be trashed by any function call within SDCC.
329 extern char scratchFileName[PATH_MAX];