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