Announce SDCC 4.5.0 RC3.
[sdcc.git] / sdcc / src / SDCCglobl.h
blobe239883fb4b2c196120ebb5d6cd710b40995a78a
1 /*-------------------------------------------------------------------------
2 SDCCglobl.h - global macros etc required by all files
4 Copyright (C) 1998, Sandeep Dutta . sandeep.dutta@usa.net
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 -------------------------------------------------------------------------*/
21 #ifndef SDCCGLOBL_H
22 #define SDCCGLOBL_H
24 #include <memory.h>
25 #include <stdlib.h>
26 #include <setjmp.h>
27 #include <stdio.h>
28 #include <errno.h>
30 # ifndef __cplusplus
31 # include <stdbool.h>
32 # endif
34 # ifndef TRUE
35 # define TRUE true
36 # endif
37 # ifndef FALSE
38 # define FALSE false
39 # endif
41 #include "SDCCset.h"
45 * Define host port dependant constants etc.
48 #define UNIX_DIR_SEPARATOR_CHAR '/'
50 #if defined(__BORLANDC__) || defined(_MSC_VER)
51 # define STRCASECMP stricmp
52 # define STRNCASECMP strnicmp
53 #else
54 # define STRCASECMP strcasecmp
55 # define STRNCASECMP strncasecmp
56 #endif
58 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
60 # ifndef HAVE_DOS_BASED_FILE_SYSTEM
61 # define HAVE_DOS_BASED_FILE_SYSTEM 1
62 # endif
64 # define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR_CHAR || (c) == UNIX_DIR_SEPARATOR_CHAR)
65 /* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
66 only semi-absolute. This is because the users of IS_ABSOLUTE_PATH
67 want to know whether to prepend the current working directory to
68 a file name, which should not be done with a name like d:foo. */
69 # define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':')))
70 # define FILENAME_CMP(s1, s2) STRCASECMP(s1, s2)
72 #else /* not DOSish */
74 # define IS_DIR_SEPARATOR(c) ((c) == DIR_SEPARATOR_CHAR)
75 # define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]))
76 # define FILENAME_CMP(s1, s2) strcmp(s1, s2)
78 #endif /* not DOSish */
80 #ifdef WIN32
81 # define NATIVE_WIN32 1
82 # ifndef __MINGW32__
83 # define PATH_MAX _MAX_PATH
84 # endif
85 #endif
87 #ifdef HAVE_CONFIG_H
88 # include "config.h"
89 #elif defined(_WIN32) && !defined(__MINGW32__)
90 # include "sdcc_vc.h"
91 #else
92 # include "sdccconf.h"
93 #endif
95 #include "SDCCerr.h"
97 #define SPACE ' '
99 #include <limits.h> /* PATH_MAX */
100 #if !defined(PATH_MAX) || (PATH_MAX < 2048)
101 # undef PATH_MAX
102 # define PATH_MAX 2048 /* define a reasonable value */
103 #endif
105 #define MAX_REG_PARMS 1
107 /* C++ doesn't like min and max macros */
108 #ifndef __cplusplus
109 # ifndef max
110 # define max(a,b) (a > b ? a : b)
111 # endif
112 # ifndef min
113 # define min(a,b) (a < b ? a : b)
114 # endif
115 #endif /* __cplusplus */
117 #ifndef THROWS
118 # define THROWS
119 # define THROW_NONE 0
120 # define THROW_SRC 1
121 # define THROW_DEST 2
122 # define THROW_BOTH 3
123 #endif
125 /* sizes in bytes */
126 #define BOOLSIZE port->s.char_size
127 #define CHARSIZE port->s.char_size
128 #define SHORTSIZE port->s.short_size
129 #define INTSIZE port->s.int_size
130 #define LONGSIZE port->s.long_size
131 #define LONGLONGSIZE port->s.longlong_size
132 #define NEARPTRSIZE port->s.near_ptr_size
133 #define FARPTRSIZE port->s.far_ptr_size
134 #define GPTRSIZE port->s.ptr_size
135 #define FUNCPTRSIZE port->s.funcptr_size
136 #define BFUNCPTRSIZE port->s.banked_funcptr_size
137 #define BITSIZE port->s.bit_size
138 #define FLOATSIZE port->s.float_size
140 #define INITIAL_INLINEASM (4 * 1024)
141 #define DEFPOOLSTACK(type,size) \
142 type *type##Pool ; \
143 type *type##FreeStack [size] ; \
144 int type##StackPtr = 0 ;
146 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
147 #define PEEK(x) x##FreeStack[x##StackPtr - 1]
148 #define POP(type) type##FreeStack[--type##StackPtr]
149 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
150 (assert(x##StackPtr),0)) */
151 #ifdef UNIX
152 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
153 #else
154 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
155 #endif
158 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
161 /* general purpose stack related macros */
162 #define STACK_DCL(stack, type, size) \
163 typedef type t_##stack; \
164 t_##stack stack[size]; \
165 t_##stack (*p_##stack) = stack - 1;
167 #define STACK_EMPTY(stack) ((p_##stack) < stack)
168 #define STACK_FULL(stack) ((p_##stack) >= (stack + \
169 sizeof(stack) / sizeof(*stack) - 1) )
171 #define STACK_PUSH_(stack, x) (*++p_##stack = (x))
172 #define STACK_POP_(stack) (*p_##stack--)
174 #define STACK_PUSH(stack, x) (STACK_FULL(stack) \
175 ? (STACK_ERR(1, stack), *p_##stack) \
176 : STACK_PUSH_(stack,x) )
178 #define STACK_POP(stack) (STACK_EMPTY(stack) \
179 ? (STACK_ERR(-1, stack), *stack) \
180 : STACK_POP_(stack) )
182 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
183 ? (STACK_ERR(0, stack), *stack) \
184 : *p_##stack )
186 #define STACK_ERR(o, stack) (fatal(1, E_STACK_VIOLATION, #stack, \
187 (o < 0) \
188 ? "underflow" \
189 : (o > 0) \
190 ? "overflow" \
191 : "empty"))
193 /* for semantically partitioned nest level values */
194 #define LEVEL_UNIT 10000
195 #define SUBLEVEL_UNIT 1
197 /* optimization options */
198 struct optimize
200 int global_cse;
201 int ptrArithmetic;
202 int label1;
203 int label2;
204 int label3;
205 int label4;
206 int loopInvariant;
207 int loopInduction;
208 int noLoopReverse;
209 int codeSpeed;
210 int codeSize;
211 int lospre;
212 int genconstprop;
213 int allow_unsafe_read;
214 int noStdLibCall;
217 /** Build model.
218 Used in options.model.A bit each as port.supported_models is an OR
219 of these.
221 enum
223 NO_MODEL = 0, /* no model applicable */
224 MODEL_SMALL = 1,
225 MODEL_COMPACT = 2,
226 MODEL_MEDIUM = 4,
227 MODEL_LARGE = 8,
228 MODEL_FLAT24 = 16,
229 // MODEL_PAGE0 = 32, /* disabled, was for the xa51 port */
230 MODEL_HUGE = 64 /* for banked support */
233 /* overlay segment name and the functions
234 that belong to it. used by pragma overlay */
235 typedef struct {
236 char *osname; /* overlay segment name */
237 int nfuncs; /* number of functions in this overlay */
238 char *funcs[128]; /* function name that belong to this */
239 } olay;
241 enum
243 NO_DEPENDENCY_FILE_OPT = 0,
244 SYSTEM_DEPENDENCY_FILE_OPT = 1,
245 USER_DEPENDENCY_FILE_OPT = 2
248 /* other command line options */
250 * cloneOptions function in SDCC.lex should be updated every time
251 * a new set is added to the options structure!
253 struct options
255 int model; /* see MODEL_* defines above */
256 int stackAuto; /* Stack Automatic */
257 int useXstack; /* use Xternal Stack */
258 int stack10bit; /* use 10 bit stack (flat24 model only) */
259 int dump_ast; /* dump front-end tree before lowering to iCode */
260 int dump_i_code; /* dump iCode at various stages */
261 int dump_graphs; /* Dump graphs in .dot format (control-flow, conflict, etc) */
262 int syntax_only; /* Parse and check syntax only, generate no output files */
263 int no_assemble; /* Do not assemble, stop after code generation, generate asm */
264 int cc_only; /* compile and assemble only, generate asm and rel object */
265 int c1mode; /* Act like c1 - no pre-proc, asm or link, generate asm */
266 int intlong_rent; /* integer & long support routines reentrant */
267 int float_rent; /* floating point routines are reentrant */
268 int out_fmt; /* 0 = undefined, 'i' = intel Hex format, 's' = motorola S19 format, 'E' = elf format, 'Z' = gb format */
269 int cyclomatic; /* print cyclomatic information */
270 int noOverlay; /* don't overlay local variables & parameters */
271 int xram_movc; /* use movc instead of movx to read xram (mcs51) */
272 int nopeep; /* no peep hole optimization */
273 int asmpeep; /* pass inline assembler thru peep hole */
274 int peepReturn; /* enable peephole optimization for return instructions */
275 int debug; /* generate extra debug info */
276 char *peep_file; /* additional rules for peep hole */
277 int nostdlib; /* Don't use standard lib files */
278 int nostdinc; /* Don't use standard include files */
279 int noRegParams; /* Disable passing some parameters in registers */
280 int verbose; /* Show what the compiler is doing */
281 int lessPedantic; /* disable some warnings */
282 int omitFramePtr; /* Turn off the frame pointer. */
283 int useAccelerator; /* use ds390 Arithmetic Accelerator */
284 int noiv; /* do not generate irq vector table entries */
285 int all_callee_saves; /* callee saves for all functions */
286 int stack_probe; /* insert call to function __stack_probe */
287 int tini_libid; /* library ID for TINI */
288 int protect_sp_update; /* DS390 - will disable interrupts during ESP:SP updates */
289 int parms_in_bank1; /* DS390 - use reg bank1 to pass parameters */
290 int stack_size; /* MCS51/DS390 - Tells the linker to allocate this space for stack */
291 int acall_ajmp; /* MCS51 - Use acall/ajmp instead of lcall/ljmp */
292 int no_ret_without_call; /* MCS51 - Do not use ret independent of acall/lcall */
293 int use_non_free; /* Search / include non-free licensed libraries and header files */
294 /* starting address of the segments */
295 int xstack_loc; /* initial location of external stack */
296 int stack_loc; /* initial value of internal stack pointer */
297 int xdata_loc; /* xternal ram starts at address */
298 int data_loc; /* interram start location */
299 int idata_loc; /* indirect address space */
300 int code_loc; /* code location start */
301 int iram_size; /* internal ram size (used only for error checking) */
302 int xram_size; /* external ram size (used only for error checking) */
303 bool xram_size_set; /* since xram_size=0 is a possibility */
304 int code_size; /* code size (used only for error checking) */
305 int verboseExec; /* show what we are doing */
306 int noXinitOpt; /* don't optimize initialized xdata */
307 int noCcodeInAsm; /* hide c-code from asm */
308 int iCodeInAsm; /* show i-code in asm */
309 int noPeepComments; /* hide peephole optimizer comments */
310 int verboseAsm; /* include comments generated with gen.c */
311 int printSearchDirs; /* display the directories in the compiler's search path */
312 int vc_err_style; /* errors and warnings are compatible with Micro$oft visual studio */
313 int use_stdout; /* send errors to stdout instead of stderr */
314 int no_std_crt0; /* for the z80/sm83 do not link default crt0.o*/
315 int std_c95; /* enable C95 keywords/constructs */
316 int std_c99; /* enable C99 keywords/constructs */
317 int std_c11; /* enable C11 keywords/constructs */
318 int std_c23; /* enable C23 keywords/constructs */
319 int std_c2y; /* enable C2y keywords/constructs */
320 int std_sdcc; /* enable SDCC extensions to C */
321 int dollars_in_ident; /* zero means dollar signs are punctuation */
322 int signed_char; /* use signed for char without signed/unsigned modifier */
323 char *code_seg; /* segment name to use instead of CSEG */
324 char *const_seg; /* segment name to use instead of CONST */
325 char *data_seg; /* segment name to use instead of DATA */
326 int dependencyFileOpt; /* write dependencies to given file */
327 /* sets */
328 set *calleeSavesSet; /* list of functions using callee save */
329 set *excludeRegsSet; /* registers excluded from saving */
330 /* set *olaysSet; * not implemented yet: overlay segments used in #pragma OVERLAY */
331 int max_allocs_per_node; /* Maximum number of allocations / combinations considered at each node in the tree-decomposition based algorithms */
332 bool noOptsdccInAsm; /* Do not emit .optsdcc in asm */
333 bool oldralloc; /* Use old register allocator */
334 int sdcccall; /* ABI version */
335 bool allow_undoc_inst; /* Allow the use of undocumented instructions */
336 // int xdata_overlay; /* Place the overlay in 16-bit addressable memory to conserve ZP space */
337 int xdata_spill; /* Place the register spills in 16-bit addressable memory */
340 /* forward definition for variables accessed globally */
341 extern char *yytext;
342 extern char *lexFilename; /* lex idea of current file name */
343 extern int lexLineno; /* lex idea of line number of the current file */
344 extern const char *fullSrcFileName; /* full name for the source file; */
345 /* can be NULL while linking without compiling */
346 extern const char *fullDstFileName; /* full name for the output file; */
347 /* only given by -o, otherwise NULL */
348 extern const char *dstFileName; /* destination file name without extension */
349 extern const char *moduleName; /* module name is source file without path and extension */
350 /* can be NULL while linking without compiling */
351 extern int seqPointNo; /* current sequence point */
352 extern FILE *yyin; /* */
353 extern FILE *asmFile; /* assembly output file */
354 extern FILE *cdbFile; /* debugger symbol file */
355 extern long NestLevel; /* NestLevel SDCC.y */
356 extern int stackPtr; /* stack pointer SDCC.y */
357 extern int xstackPtr; /* external stack pointer SDCC.y */
358 extern int reentrant; /* /X flag has been sent SDCC.y */
359 extern char buffer[PATH_MAX * 2];/* general buffer SDCCmain.c */
360 extern int currRegBank; /* register bank being used SDCCgens.c */
361 extern int RegBankUsed[4]; /* JCF: register banks used SDCCmain.c */
362 extern int BitBankUsed; /* MB: overlayable bit bank SDCCmain.c */
363 extern struct symbol *currFunc; /* current function SDCCgens.c */
364 extern long cNestLevel; /* block nest level SDCCval.c */
365 extern int blockNo; /* maximum sequential block number */
366 extern int currBlockno; /* sequential block number */
367 extern struct optimize optimize;
368 extern struct options options;
369 extern unsigned maxInterrupts;
370 extern int ignoreTypedefType;
372 /* Visible from SDCCmain.c */
373 extern set *preArgvSet;
374 extern set *relFilesSet;
375 extern set *libFilesSet;
376 extern set *libPathsSet;
377 extern set *libDirsSet; /* list of lib search directories */
379 void setParseWithComma (set **, const char *);
381 /** An assert() macro that will go out through sdcc's error
382 system.
384 #define wassertl(a,s) (void)((a) ? 0 : \
385 (werror (E_INTERNAL_ERROR, __FILE__, __LINE__, s), 0))
387 #define wassert(a) wassertl(a,"code generator internal error")
389 enum {
390 DUMP_RAW0 = 1,
391 DUMP_RAW1,
392 DUMP_CSE,
393 DUMP_DFLOW,
394 DUMP_GCSE,
395 DUMP_DEADCODE,
396 DUMP_LOOP,
397 DUMP_LOOPG,
398 DUMP_LOOPD,
399 DUMP_LOSPRE,
400 DUMP_GENCONSTPROP,
401 DUMP_RANGE,
402 DUMP_PACK,
403 DUMP_RASSGN,
404 DUMP_LRANGE,
405 DUMP_CUSTOM0, // For temporary dump points
406 DUMP_CUSTOM1 // For temporary dump points
409 struct _dumpFiles {
410 int id;
411 char *ext;
412 FILE *filePtr;
415 extern struct _dumpFiles dumpFiles[];
417 /* Define well known filenos if the system does not define them. */
418 #ifndef STDIN_FILENO
419 # define STDIN_FILENO 0
420 #endif
421 #ifndef STDOUT_FILENO
422 # define STDOUT_FILENO 1
423 #endif
424 #ifndef STDERR_FILENO
425 # define STDERR_FILENO 2
426 #endif
428 #endif