replace FILENAME_MAX with PATH_MAX
[fw/sdcc] / src / SDCCglobl.h
1 /* SDCCglobl.h - global macros etc required by all files */
2 #ifndef SDCCGLOBL_H
3 #define SDCCGLOBL_H
4 #include <memory.h>
5 #include <assert.h>
6 #include <stdlib.h>
7 #include <setjmp.h>
8 #include <stdio.h>
9
10 /*
11  * Define host port dependant constants etc.
12  */
13
14 #define DOS_DIR_SEPARATOR_CHAR      '\\'
15 #define DOS_DIR_SEPARATOR_STRING   "\\"
16 #define UNIX_DIR_SEPARATOR_CHAR    '/'
17 #define UNIX_DIR_SEPARATOR_STRING  "/"
18
19 #if defined(__BORLANDC__)       /* Borland Turbo C/Win32 Host */
20
21 #define NATIVE_WIN32            1
22 #define DIR_SEPARATOR_CHAR          DOS_DIR_SEPARATOR_CHAR
23 #define DIR_SEPARATOR_STRING        DOS_DIR_SEPARATOR_STRING
24
25 #elif defined(_MSC_VER)         /* Miscosoft VC6/Win32 Host */
26
27 #define NATIVE_WIN32            1
28 #include "sdcc_vc.h"
29 #define DIR_SEPARATOR_CHAR          DOS_DIR_SEPARATOR_CHAR
30 #define DIR_SEPARATOR_STRING        DOS_DIR_SEPARATOR_STRING
31
32 #elif defined(__MINGW32__)      /* MINGW32 DOS Host */
33
34 #define NATIVE_WIN32            1
35 #define DIR_SEPARATOR_CHAR          DOS_DIR_SEPARATOR_CHAR
36 #define DIR_SEPARATOR_STRING        DOS_DIR_SEPARATOR_STRING
37
38 #else /* Assume Un*x style system */
39
40 #include "sdccconf.h"
41 #define DIR_SEPARATOR_CHAR          UNIX_DIR_SEPARATOR_CHAR
42 #define DIR_SEPARATOR_STRING        UNIX_DIR_SEPARATOR_STRING
43
44 #endif // _MSC_VER
45
46 #include "SDCCerr.h"
47
48 #define SPACE ' '
49 #define ZERO  0
50
51 #include <limits.h>             /* PATH_MAX                  */
52 #ifndef PATH_MAX                /* POSIX, but not required   */
53 #define PATH_MAX 255            /* define a reasonable value */
54 #endif
55
56 #define  MAX_FNAME_LEN  128
57 #define  MAX_REG_PARMS  1
58 typedef int bool;
59
60 #ifndef max
61 #define max(a,b) (a > b ? a : b)
62 #endif
63
64 #ifndef min
65 #define min(a,b) (a < b ? a : b)
66 #endif
67
68 #ifndef THROWS
69 #define THROWS
70 #define THROW_NONE  0
71 #define THROW_SRC   1
72 #define THROW_DEST  2
73 #define THROW_BOTH  3
74 #endif
75
76 /* size's in bytes  */
77 #define CHARSIZE    port->s.char_size
78 #define SHORTSIZE   port->s.short_size
79 #define INTSIZE     port->s.int_size
80 #define LONGSIZE    port->s.long_size
81 #define PTRSIZE     port->s.ptr_size
82 #define FPTRSIZE    port->s.fptr_size
83 #define GPTRSIZE    port->s.gptr_size
84 #define BITSIZE     port->s.bit_size
85 #define FLOATSIZE   port->s.float_size
86 #define MAXBASESIZE port->s.max_base_size
87
88
89 #define PRAGMA_SAVE        "SAVE"
90 #define PRAGMA_RESTORE     "RESTORE"
91 #define PRAGMA_NOINDUCTION "NOINDUCTION"
92 #define PRAGMA_NOINVARIANT "NOINVARIANT"
93 #define PRAGMA_NOLOOPREV   "NOLOOPREVERSE"
94 #define PRAGMA_INDUCTION   "INDUCTION"
95 #define PRAGMA_STACKAUTO   "STACKAUTO"
96 #define PRAGMA_NOJTBOUND   "NOJTBOUND"
97 #define PRAGMA_NOGCSE      "NOGCSE"
98 #define PRAGMA_NOOVERLAY   "NOOVERLAY"
99 #define PRAGMA_CALLEESAVES "CALLEE-SAVES"
100 #define PRAGMA_EXCLUDE     "EXCLUDE"
101 #define  SMALL_MODEL 0
102 #define  LARGE_MODEL 1
103 #define  TRUE 1
104 #define  FALSE 0
105
106 #define MAX_TVAR 6
107 #define INITIAL_INLINEASM 4*1024
108 #define DEFPOOLSTACK(type,size)     \
109     type       *type##Pool        ; \
110     type *type##FreeStack [size]  ; \
111     int   type##StackPtr = 0      ;
112
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)) */
118 #ifdef UNIX
119 #define EMPTY(x)        (x##StackPtr <= 1 ? 1 : 0)
120 #else
121 #define EMPTY(x)        (x##StackPtr == 0 ? 1 : 0)
122 #endif
123
124
125 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
126
127
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);   \
133
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;
139
140 #define  STACK_FULL(stack)    ((p_##stack) <= stack )
141 #define  STACK_EMPTY(stack)   ((p_##stack) >= (stack +      \
142                               sizeof(stack)/sizeof(*stack)) )
143
144 #define  STACK_PUSH_(stack,x) (*--p_##stack = (x))
145 #define  STACK_POP_(stack)    (*p_##stack++)
146
147 #define  STACK_PUSH(stack,x)  (STACK_FULL(stack)                  \
148                               ?((t_##stack)(long)(STACK_ERR(1)))  \
149                               : STACK_PUSH_(stack,x)              )
150
151 #define  STACK_POP(stack)     (STACK_EMPTY(stack)                 \
152                               ?((t_##stack)(long)(STACK_ERR(0)))  \
153                               : STACK_POP_(stack)                 )
154
155 #define  STACK_PEEK(stack)    (STACK_EMPTY(stack)                 \
156                               ?((t_##stack) NULL)                 \
157                               : *p_##stack                        )
158
159 #define  STACK_ERR(o)         ( o                                 \
160                               ? fprintf(stderr,"stack Overflow\n")\
161                               : fprintf(stderr,"stack underflow\n"))
162
163 /* optimization options */
164 struct optimize
165   {
166     unsigned global_cse;
167     unsigned ptrArithmetic;
168     unsigned label1;
169     unsigned label2;
170     unsigned label3;
171     unsigned label4;
172     unsigned loopInvariant;
173     unsigned loopInduction;
174     unsigned noJTabBoundary;
175     unsigned noLoopReverse;
176   };
177
178 /** Build model.
179     Used in options.model.A bit each as port.supported_models is an OR
180     of these. 
181 */
182 enum
183   {
184     MODEL_SMALL = 1,
185     MODEL_COMPACT = 2,
186     MODEL_MEDIUM = 4,
187     MODEL_LARGE = 8,
188     MODEL_FLAT24 = 16
189   };
190
191 /* other command line options */
192 struct options
193   {
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 genericPtr;             /* use generic pointers */
199     int dump_raw;               /* dump after intermediate code generation */
200     int dump_gcse;              /* dump after gcse */
201     int dump_loop;              /* dump after loop optimizations */
202     int dump_kill;              /* dump after dead code elimination */
203     int dump_range;             /* dump after live range analysis */
204     int dump_pack;              /* dump after register packing */
205     int dump_rassgn;            /* dump after register assignment */
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 nopeep;                 /* no peep hole optimization */
214     int asmpeep;                /* pass inline assembler thru peep hole */
215     int debug;                  /* generate extra debug info */
216     int stackOnData;            /* stack after data segment  */
217     int c1mode;                 /* Act like c1 - no pre-proc, asm or link */
218     char *peep_file;            /* additional rules for peep hole */
219     char *out_name;             /* Asm output name for c1 mode */
220     int nostdlib;               /* Don't use standard lib files */
221     int nostdinc;               /* Don't use standard include files */
222     int noRegParams;            /* Disable passing some parameters in registers */
223     int verbose;                /* Show what the compiler is doing */
224     int shortis8bits;           /* treat short like int or char */
225     int lessPedantic;           /* disable some warnings */
226     int profile;                /* Turn on extra profiling information */
227     int ommitFramePtr;          /* Turn off the frame pointer. */
228
229     char *calleeSaves[128];     /* list of functions using callee save */
230     char *excludeRegs[32];      /* registers excluded from saving */
231
232     /* starting address of the segments */
233     int xstack_loc;             /* initial location of external stack */
234     int stack_loc;              /* initial value of internal stack pointer */
235     int xdata_loc;              /* xternal ram starts at address */
236     int data_loc;               /* interram start location       */
237     int idata_loc;              /* indirect address space        */
238     int code_loc;               /* code location start           */
239     int iram_size;              /* internal ram size (used only for error checking) */
240   };
241
242 /* forward definition for variables accessed globally */
243 extern int noAssemble;         /* no assembly, stop after code generation */
244 extern char *yytext;
245 extern char *currFname;
246 extern char *srcFileName;       /* source file name without the extenstion */
247 extern char *moduleName;        /* source file name without path & extension */
248 extern int currLineno;          /* current line number    */
249 extern int yylineno;            /* line number of the current file SDCC.lex */
250 extern FILE *yyin;              /* */
251 extern FILE *asmFile;           /* assembly output file */
252 extern FILE *cdbFile;           /* debugger symbol file */
253 extern int NestLevel;           /* NestLevel                 SDCC.y   */
254 extern int stackPtr;            /* stack pointer             SDCC.y   */
255 extern int xstackPtr;           /* external stack pointer    SDCC.y   */
256 extern int reentrant;           /* /X flag has been sent     SDCC.y */
257 extern char buffer[];           /* general buffer      SDCCgen.c   */
258 extern int currRegBank;         /* register bank being used   SDCCgens.c   */
259 extern struct symbol *currFunc; /* current function    SDCCgens.c */
260 extern int cNestLevel;          /* block nest level  SDCCval.c      */
261 extern int currBlockno;         /* sequentail block number */
262 extern struct optimize optimize;
263 extern struct options options;
264 extern unsigned maxInterrupts;
265
266 /* Visible from SDCCmain.c */
267 extern int nrelFiles;
268 extern char *relFiles[128];
269 extern char *libFiles[128];
270 extern int nlibFiles;
271 extern char *libPaths[128];
272 extern int nlibPaths;
273
274 extern bool verboseExec ;
275
276 void parseWithComma (char **, char *);
277
278 /** Creates a temporary file a'la tmpfile which avoids the bugs
279     in cygwin wrt c:\tmp.
280     Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
281 */
282 FILE *tempfile (void);
283
284 /** Creates a temporary file name a'la tmpnam which avoids the bugs
285     in cygwin wrt c:\tmp.
286     Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
287 */
288 char *
289 tempfilename (void);
290
291 /** An assert() macro that will go out through sdcc's error
292     system.
293 */
294 #define wassertl(a,s)   ((a) ? 0 : \
295         (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
296
297 #define wassert(a)    wassertl(a,"code generator internal error")
298
299 #define DUMP_RAW0 1
300 #define DUMP_RAW1 DUMP_RAW0+1
301 #define DUMP_CSE DUMP_RAW1+1
302 #define DUMP_DFLOW DUMP_CSE+1
303 #define DUMP_GCSE DUMP_DFLOW+1
304 #define DUMP_DEADCODE DUMP_GCSE+1
305 #define DUMP_LOOP DUMP_DEADCODE+1
306 #define DUMP_LOOPG DUMP_LOOP+1
307 #define DUMP_LOOPD DUMP_LOOPG+1
308 #define DUMP_RANGE DUMP_LOOPD+1
309 #define DUMP_PACK DUMP_RANGE+1
310 #define DUMP_RASSGN DUMP_PACK+1
311 #define DUMP_LRANGE DUMP_RASSGN+1
312
313 struct _dumpFiles {
314   int id;
315   char *ext;
316   FILE *filePtr;
317 };
318
319 extern struct _dumpFiles dumpFiles[];
320
321 /* Buffer which can be used to hold a file name; assume it will
322  * be trashed by any function call within SDCC.
323  */
324 extern char scratchFileName[PATH_MAX];
325
326 #endif