Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[fw/sdcc] / src / SDCCglobl.h
1 /* SDCCglobl.h - global macros etc required by all files */
2
3 #ifndef SDCCGLOBL_H
4 #define SDCCGLOBL_H
5
6 #include <memory.h>
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <setjmp.h>
10 #include <stdio.h>
11
12 #include "SDCCset.h"
13
14
15 /*
16  * Define host port dependant constants etc.
17  */
18
19 #define UNIX_DIR_SEPARATOR_CHAR    '/'
20
21 #if defined(__BORLANDC__) || defined(_MSC_VER)
22 #define STRCASECMP stricmp
23 #define STRNCASECMP strnicmp
24 #else
25 #define STRCASECMP strcasecmp
26 #define STRNCASECMP strncasecmp
27 #endif
28
29 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
30
31 #ifndef HAVE_DOS_BASED_FILE_SYSTEM
32 #define HAVE_DOS_BASED_FILE_SYSTEM 1
33 #endif
34
35 #define IS_DIR_SEPARATOR(c)     ((c) == DIR_SEPARATOR_CHAR || (c) == UNIX_DIR_SEPARATOR_CHAR)
36 /* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
37    only semi-absolute.  This is because the users of IS_ABSOLUTE_PATH
38    want to know whether to prepend the current working directory to
39    a file name, which should not be done with a name like d:foo.  */
40 #define IS_ABSOLUTE_PATH(f)     (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':')))
41 #define FILENAME_CMP(s1, s2)    STRCASECMP(s1, s2)
42
43 #else  /* not DOSish */
44
45 #define IS_DIR_SEPARATOR(c)     ((c) == DIR_SEPARATOR_CHAR)
46 #define IS_ABSOLUTE_PATH(f)     (IS_DIR_SEPARATOR((f)[0]))
47 #define FILENAME_CMP(s1, s2)    strcmp(s1, s2)
48
49 #endif /* not DOSish */
50
51 #ifdef WIN32
52 # define NATIVE_WIN32          1
53 # ifndef __MINGW32__
54 #   define  PATH_MAX  _MAX_PATH
55 # endif
56 #endif
57
58 #ifdef HAVE_CONFIG_H
59 # include "config.h"
60 #elif defined(_WIN32) && !defined(__MINGW32__)
61 # include "sdcc_vc.h"
62 #else
63 # include "sdccconf.h"
64 #endif
65
66 #include "SDCCerr.h"
67
68 #define SPACE ' '
69 #define ZERO  0
70
71 #include <limits.h>             /* PATH_MAX                  */
72 #if !defined(PATH_MAX) || (PATH_MAX < 2048)
73 #  undef  PATH_MAX
74 #  define PATH_MAX 2048         /* define a reasonable value */
75 #endif
76
77 #define  MAX_REG_PARMS  1
78 typedef int bool;
79
80 #ifndef max
81 #  define max(a,b) (a > b ? a : b)
82 #endif
83
84 #ifndef min
85 #  define min(a,b) (a < b ? a : b)
86 #endif
87
88 #ifndef THROWS
89 #define THROWS
90 #define THROW_NONE  0
91 #define THROW_SRC   1
92 #define THROW_DEST  2
93 #define THROW_BOTH  3
94 #endif
95
96 /* size's in bytes  */
97 #define CHARSIZE    port->s.char_size
98 #define SHORTSIZE   port->s.short_size
99 #define INTSIZE     port->s.int_size
100 #define LONGSIZE    port->s.long_size
101 #define PTRSIZE     port->s.ptr_size
102 #define FPTRSIZE    port->s.fptr_size
103 #define GPTRSIZE    port->s.gptr_size
104 #define BITSIZE     port->s.bit_size
105 #define FLOATSIZE   port->s.float_size
106 #define MAXBASESIZE port->s.max_base_size
107
108 #define  SMALL_MODEL 0
109 #define  LARGE_MODEL 1
110 #define  TRUE 1
111 #define  FALSE 0
112
113 #define MAX_TVAR 6
114 #define INITIAL_INLINEASM 4*1024
115 #define DEFPOOLSTACK(type,size)     \
116     type       *type##Pool        ; \
117     type *type##FreeStack [size]  ; \
118     int   type##StackPtr = 0      ;
119
120 #define PUSH(x,y)   x##FreeStack[x##StackPtr++] = y
121 #define PEEK(x)     x##FreeStack[x##StackPtr-1]
122 #define POP(type)   type##FreeStack[--type##StackPtr]
123 /* #define POP(x)    (x##StackPtr ? x##FreeStack[--x##StackPtr] :       \
124    (assert(x##StackPtr),0)) */
125 #ifdef UNIX
126 #define EMPTY(x)        (x##StackPtr <= 1 ? 1 : 0)
127 #else
128 #define EMPTY(x)        (x##StackPtr == 0 ? 1 : 0)
129 #endif
130
131
132 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
133
134
135 /* general purpose stack related macros */
136 #define  STACK_DCL(stack,type,size)                                   \
137          typedef  type  t_##stack   ;                                 \
138          t_##stack   stack[size]    ;                                 \
139          t_##stack   (*p_##stack) = stack;
140
141 /* define extern stack */
142 #define EXTERN_STACK_DCL(stack,type,size)                             \
143         typedef type t_##stack     ;                                  \
144         extern t_##stack stack[size] ;                                \
145         extern t_##stack *p_##stack;
146
147 #define  STACK_EMPTY(stack)     ((p_##stack) <= stack )
148 #define  STACK_FULL(stack)      ((p_##stack) >= (stack +              \
149                                 sizeof(stack)/sizeof(*stack))         )
150
151 #define  STACK_PUSH_(stack, x)  (*++p_##stack = (x))
152 #define  STACK_POP_(stack)      (*p_##stack--)
153
154 #define  STACK_PUSH(stack, x)   (STACK_FULL(stack)                    \
155                                 ? (STACK_ERR(1, stack), *p_##stack)   \
156                                 : STACK_PUSH_(stack,x)                )
157
158 #define  STACK_POP(stack)       (STACK_EMPTY(stack)                   \
159                                 ? (STACK_ERR(-1, stack), *p_##stack)  \
160                                 : STACK_POP_(stack)                   )
161
162 #define  STACK_PEEK(stack)      (STACK_EMPTY(stack)                   \
163                                 ? (STACK_ERR(0, stack), *p_##stack)   \
164                                 : *p_##stack                          )
165
166 #define  STACK_ERR(o, stack)    (fatal(1, E_STACK_VIOLATION, #stack,  \
167                                         (o < 0)                       \
168                                         ? "underflow"                 \
169                                         : (o > 0)                     \
170                                           ? "overflow"                \
171                                           : "empty"))
172
173 /* optimization options */
174 /*
175  * cloneOptimize function in SDCC.lex should be updated every time
176  * a new set is added to the optimize structure!
177  */
178 struct optimize
179   {
180     int global_cse;
181     int ptrArithmetic;
182     int label1;
183     int label2;
184     int label3;
185     int label4;
186     int loopInvariant;
187     int loopInduction;
188     int noJTabBoundary;
189     int noLoopReverse;
190     int codeSpeed;
191     int codeSize;
192   };
193
194 /** Build model.
195     Used in options.model.A bit each as port.supported_models is an OR
196     of these.
197 */
198 enum
199   {
200     MODEL_SMALL = 1,
201     MODEL_COMPACT = 2,
202     MODEL_MEDIUM = 4,
203     MODEL_LARGE = 8,
204     MODEL_FLAT24 = 16,
205     MODEL_PAGE0 = 32, /* for the xa51 port */
206     MODEL_HUGE = 64 /* for banked support */
207   };
208
209 /* overlay segment name and the functions
210    that belong to it. used by pragma overlay */
211 typedef struct {
212     char *osname;       /* overlay segment name */
213     int  nfuncs;        /* number of functions in this overlay */
214     char *funcs[128];   /* function name that belong to this */
215 } olay;
216
217 /* other command line options */
218 /*
219  * cloneOptions function in SDCC.lex should be updated every time
220  * a new set is added to the options structure!
221  */
222 struct options
223   {
224     int model;                  /* see MODEL_* defines above */
225     int stackAuto;              /* Stack Automatic  */
226     int useXstack;              /* use Xternal Stack */
227     int stack10bit;             /* use 10 bit stack (flat24 model only) */
228     int dump_raw;               /* dump after intermediate code generation */
229     int dump_gcse;              /* dump after gcse */
230     int dump_loop;              /* dump after loop optimizations */
231     int dump_kill;              /* dump after dead code elimination */
232     int dump_range;             /* dump after live range analysis */
233     int dump_pack;              /* dump after register packing */
234     int dump_rassgn;            /* dump after register assignment */
235     int dump_tree;              /* dump front-end tree before lowering to iCode */
236     int cc_only;                /* compile only flag              */
237     int intlong_rent;           /* integer & long support routines reentrant */
238     int float_rent;             /* floating point routines are reentrant */
239     int out_fmt;                /* 1 = motorola S19 format 0 = intel Hex format */
240     int cyclomatic;             /* print cyclomatic information */
241     int noOverlay;              /* don't overlay local variables & parameters */
242     int mainreturn;             /* issue a return after main */
243     int xram_movc;              /* use movc instead of movx to read xram (mcs51) */
244     int nopeep;                 /* no peep hole optimization */
245     int asmpeep;                /* pass inline assembler thru peep hole */
246     int debug;                  /* generate extra debug info */
247     int c1mode;                 /* Act like c1 - no pre-proc, asm or link */
248     char *peep_file;            /* additional rules for peep hole */
249     int nostdlib;               /* Don't use standard lib files */
250     int nostdinc;               /* Don't use standard include files */
251     int noRegParams;            /* Disable passing some parameters in registers */
252     int verbose;                /* Show what the compiler is doing */
253     int shortis8bits;           /* treat short like int or char */
254     int lessPedantic;           /* disable some warnings */
255     int profile;                /* Turn on extra profiling information */
256     int ommitFramePtr;          /* Turn off the frame pointer. */
257     int useAccelerator;         /* use ds390 Arithmetic Accelerator */
258     int noiv;                   /* do not generate irq vector table entries */
259     int all_callee_saves;       /* callee saves for all functions */
260     int stack_probe;            /* insert call to function __stack_probe */
261     int tini_libid;             /* library ID for TINI */
262     int protect_sp_update;      /* DS390 - will disable interrupts during ESP:SP updates */
263     int parms_in_bank1;         /* DS390 - use reg bank1 to pass parameters */
264     int stack_size;             /* MCS51/DS390 - Tells the linker to allocate this space for stack */
265     int no_pack_iram;           /* MCS51/DS390 - Tells the linker not to pack variables in internal ram */
266     int acall_ajmp;             /* MCS51 - Use acall/ajmp instead of lcall/ljmp */
267     /* starting address of the segments */
268     int xstack_loc;             /* initial location of external stack */
269     int stack_loc;              /* initial value of internal stack pointer */
270     int xdata_loc;              /* xternal ram starts at address */
271     int data_loc;               /* interram start location       */
272     int idata_loc;              /* indirect address space        */
273     int code_loc;               /* code location start           */
274     int iram_size;              /* internal ram size (used only for error checking) */
275     int xram_size;              /* external ram size (used only for error checking) */
276     bool xram_size_set;         /* since xram_size=0 is a possibility */
277     int code_size;              /* code size (used only for error checking) */
278     int verboseExec;            /* show what we are doing */
279     int noXinitOpt;             /* don't optimize initialized xdata */
280     int noCcodeInAsm;           /* hide c-code from asm */
281     int iCodeInAsm;             /* show i-code in asm */
282     int noPeepComments;         /* hide peephole optimizer comments */
283     int verboseAsm;             /* include comments generated with gen.c */
284     int printSearchDirs;        /* display the directories in the compiler's search path */
285     int vc_err_style;           /* errors and warnings are compatible with Micro$oft visual studio */
286     int use_stdout;             /* send errors to stdout instead of stderr */
287     int no_std_crt0;            /* for the z80/gbz80 do not link default crt0.o*/
288     int std_c99;                /* enable C99 keywords/constructs */
289     int std_sdcc;               /* enable SDCC extensions to C */
290     int dollars_in_ident;       /* zero means dollar signs are punctuation */
291     int unsigned_char;          /* use unsigned for char without signed/unsigned modifier */
292     char *code_seg;             /* segment name to use instead of CSEG */
293     char *const_seg;            /* segment name to use instead of CONST */
294     /* sets */
295     set *calleeSavesSet;        /* list of functions using callee save */
296     set *excludeRegsSet;        /* registers excluded from saving */
297 /*  set *olaysSet;               * not implemented yet: overlay segments used in #pragma OVERLAY */
298   };
299
300 /* forward definition for variables accessed globally */
301 extern int noAssemble;          /* no assembly, stop after code generation */
302 extern char *yytext;
303 extern char *lexFilename;       /* lex idea of current file name */
304 extern int lexLineno;           /* lex idea of line number of the current file */
305 extern char *fullSrcFileName;   /* full name for the source file; */
306                                 /* can be NULL while linking without compiling */
307 extern char *fullDstFileName;   /* full name for the output file; */
308                                 /* only given by -o, otherwise NULL */
309 extern char *dstFileName;       /* destination file name without extension */
310 extern char *dstPath;           /* path for the output files; */
311                                 /* "" is equivalent with cwd */
312 extern char *moduleName;        /* module name is source file without path and extension */
313                                 /* can be NULL while linking without compiling */
314 extern int seqPointNo;          /* current sequence point */
315 extern FILE *yyin;              /* */
316 extern FILE *asmFile;           /* assembly output file */
317 extern FILE *cdbFile;           /* debugger symbol file */
318 extern int NestLevel;           /* NestLevel                 SDCC.y */
319 extern int stackPtr;            /* stack pointer             SDCC.y */
320 extern int xstackPtr;           /* external stack pointer    SDCC.y */
321 extern int reentrant;           /* /X flag has been sent     SDCC.y */
322 extern char buffer[PATH_MAX * 2];/* general buffer           SDCCmain.c */
323 extern int currRegBank;         /* register bank being used  SDCCgens.c */
324 extern int RegBankUsed[4];      /* JCF: register banks used  SDCCmain.c */
325 extern int BitBankUsed;         /* MB: overlayable bit bank  SDCCmain.c */
326 extern struct symbol *currFunc; /* current function    SDCCgens.c */
327 extern int cNestLevel;          /* block nest level  SDCCval.c */
328 extern int blockNo;             /* maximum sequential block number */
329 extern int currBlockno;         /* sequential block number */
330 extern struct optimize optimize;
331 extern struct options options;
332 extern unsigned maxInterrupts;
333 extern int ignoreTypedefType;
334
335 /* Visible from SDCCmain.c */
336 extern set *preArgvSet;
337 extern set *relFilesSet;
338 extern set *libFilesSet;
339 extern set *libPathsSet;
340 extern set *libDirsSet;         /* list of lib search directories */
341
342 void setParseWithComma (set **, const char *);
343
344 /** An assert() macro that will go out through sdcc's error
345     system.
346 */
347 #define wassertl(a,s)   ((a) ? 0 : \
348         (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
349
350 #define wassert(a)    wassertl(a,"code generator internal error")
351
352 #define DUMP_RAW0 1
353 #define DUMP_RAW1 DUMP_RAW0+1
354 #define DUMP_CSE DUMP_RAW1+1
355 #define DUMP_DFLOW DUMP_CSE+1
356 #define DUMP_GCSE DUMP_DFLOW+1
357 #define DUMP_DEADCODE DUMP_GCSE+1
358 #define DUMP_LOOP DUMP_DEADCODE+1
359 #define DUMP_LOOPG DUMP_LOOP+1
360 #define DUMP_LOOPD DUMP_LOOPG+1
361 #define DUMP_RANGE DUMP_LOOPD+1
362 #define DUMP_PACK DUMP_RANGE+1
363 #define DUMP_RASSGN DUMP_PACK+1
364 #define DUMP_LRANGE DUMP_RASSGN+1
365
366 struct _dumpFiles {
367   int id;
368   char *ext;
369   FILE *filePtr;
370 };
371
372 extern struct _dumpFiles dumpFiles[];
373
374 /* Buffer which can be used to hold a file name; assume it will
375  * be trashed by any function call within SDCC.
376  */
377 extern char scratchFileName[PATH_MAX];
378
379 /* Define well known filenos if the system does not define them.  */
380 #ifndef STDIN_FILENO
381 # define STDIN_FILENO   0
382 #endif
383 #ifndef STDOUT_FILENO
384 # define STDOUT_FILENO  1
385 #endif
386 #ifndef STDERR_FILENO
387 # define STDERR_FILENO  2
388 #endif
389
390 #endif