bug 434350: filename buffer too small.
[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 #define  MAX_FNAME_LEN  128
52 #define  MAX_REG_PARMS  1
53 typedef int bool;
54
55 #ifndef max
56 #define max(a,b) (a > b ? a : b)
57 #endif
58
59 #ifndef min
60 #define min(a,b) (a < b ? a : b)
61 #endif
62
63 #ifndef THROWS
64 #define THROWS
65 #define THROW_NONE  0
66 #define THROW_SRC   1
67 #define THROW_DEST  2
68 #define THROW_BOTH  3
69 #endif
70
71 /* size's in bytes  */
72 #define CHARSIZE    port->s.char_size
73 #define SHORTSIZE   port->s.short_size
74 #define INTSIZE     port->s.int_size
75 #define LONGSIZE    port->s.long_size
76 #define PTRSIZE     port->s.ptr_size
77 #define FPTRSIZE    port->s.fptr_size
78 #define GPTRSIZE    port->s.gptr_size
79 #define BITSIZE     port->s.bit_size
80 #define FLOATSIZE   port->s.float_size
81 #define MAXBASESIZE port->s.max_base_size
82
83
84 #define PRAGMA_SAVE        "SAVE"
85 #define PRAGMA_RESTORE     "RESTORE"
86 #define PRAGMA_NOINDUCTION "NOINDUCTION"
87 #define PRAGMA_NOINVARIANT "NOINVARIANT"
88 #define PRAGMA_NOLOOPREV   "NOLOOPREVERSE"
89 #define PRAGMA_INDUCTION   "INDUCTION"
90 #define PRAGMA_STACKAUTO   "STACKAUTO"
91 #define PRAGMA_NOJTBOUND   "NOJTBOUND"
92 #define PRAGMA_NOGCSE      "NOGCSE"
93 #define PRAGMA_NOOVERLAY   "NOOVERLAY"
94 #define PRAGMA_CALLEESAVES "CALLEE-SAVES"
95 #define PRAGMA_EXCLUDE     "EXCLUDE"
96 #define  SMALL_MODEL 0
97 #define  LARGE_MODEL 1
98 #define  TRUE 1
99 #define  FALSE 0
100
101 #define MAX_TVAR 6
102 #define INITIAL_INLINEASM 4*1024
103 #define DEFPOOLSTACK(type,size)     \
104     type       *type##Pool        ; \
105     type *type##FreeStack [size]  ; \
106     int   type##StackPtr = 0      ;
107
108 #define PUSH(x,y)   x##FreeStack[x##StackPtr++] = y
109 #define PEEK(x)     x##FreeStack[x##StackPtr-1]
110 #define POP(type)   type##FreeStack[--type##StackPtr]
111 /* #define POP(x)    (x##StackPtr ? x##FreeStack[--x##StackPtr] :       \
112    (assert(x##StackPtr),0)) */
113 #ifdef UNIX
114 #define EMPTY(x)        (x##StackPtr <= 1 ? 1 : 0)
115 #else
116 #define EMPTY(x)        (x##StackPtr == 0 ? 1 : 0)
117 #endif
118
119
120 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
121
122
123 /* generalpurpose stack related macros */
124 #define  STACK_DCL(stack,type,size)                   \
125          typedef  type  t_##stack   ;                 \
126          t_##stack   stack[size]    ;                 \
127          t_##stack   (*p_##stack) = stack + (size);   \
128
129 /* define extern stack */
130 #define EXTERN_STACK_DCL(stack,type,size)             \
131         typedef type t_##stack     ;                  \
132         extern t_##stack stack[size] ;                \
133         extern t_##stack *p_##stack;
134
135 #define  STACK_FULL(stack)    ((p_##stack) <= stack )
136 #define  STACK_EMPTY(stack)   ((p_##stack) >= (stack +      \
137                               sizeof(stack)/sizeof(*stack)) )
138
139 #define  STACK_PUSH_(stack,x) (*--p_##stack = (x))
140 #define  STACK_POP_(stack)    (*p_##stack++)
141
142 #define  STACK_PUSH(stack,x)  (STACK_FULL(stack)                  \
143                               ?((t_##stack)(long)(STACK_ERR(1)))  \
144                               : STACK_PUSH_(stack,x)              )
145
146 #define  STACK_POP(stack)     (STACK_EMPTY(stack)                 \
147                               ?((t_##stack)(long)(STACK_ERR(0)))  \
148                               : STACK_POP_(stack)                 )
149
150 #define  STACK_PEEK(stack)    (STACK_EMPTY(stack)                 \
151                               ?((t_##stack) NULL)                 \
152                               : *p_##stack                        )
153
154 #define  STACK_ERR(o)         ( o                                 \
155                               ? fprintf(stderr,"stack Overflow\n")\
156                               : fprintf(stderr,"stack underflow\n"))
157
158 /* optimization options */
159 struct optimize
160   {
161     unsigned global_cse;
162     unsigned ptrArithmetic;
163     unsigned label1;
164     unsigned label2;
165     unsigned label3;
166     unsigned label4;
167     unsigned loopInvariant;
168     unsigned loopInduction;
169     unsigned noJTabBoundary;
170     unsigned noLoopReverse;
171   };
172
173 /** Build model.
174     Used in options.model.A bit each as port.supported_models is an OR
175     of these. 
176 */
177 enum
178   {
179     MODEL_SMALL = 1,
180     MODEL_COMPACT = 2,
181     MODEL_MEDIUM = 4,
182     MODEL_LARGE = 8,
183     MODEL_FLAT24 = 16
184   };
185
186 /* other command line options */
187 struct options
188   {
189     int model;                  /* see MODEL_* defines above */
190     int stackAuto;              /* Stack Automatic  */
191     int useXstack;              /* use Xternal Stack */
192     int stack10bit;             /* use 10 bit stack (flat24 model only) */
193     int genericPtr;             /* use generic pointers */
194     int regExtend;              /* don't use extended registers */
195     int dump_raw;               /* dump after intermediate code generation */
196     int dump_gcse;              /* dump after gcse */
197     int dump_loop;              /* dump after loop optimizations */
198     int dump_kill;              /* dump after dead code elimination */
199     int dump_range;             /* dump after live range analysis */
200     int dump_pack;              /* dump after register packing */
201     int dump_rassgn;            /* dump after register assignment */
202     int cc_only;                /* compile only flag              */
203     int intlong_rent;           /* integer & long support routines reentrant */
204     int float_rent;             /* floating point routines are reentrant */
205     int out_fmt;                /* 1 = motorola S19 format 0 = intel Hex format */
206     int cyclomatic;             /* print cyclomatic information */
207     int noOverlay;              /* don't overlay local variables & parameters */
208     int mainreturn;             /* issue a return after main */
209     int nopeep;                 /* no peep hole optimization */
210     int asmpeep;                /* pass inline assembler thru peep hole */
211     int debug;                  /* generate extra debug info */
212     int nodebug;                /* Generate no debug info. */
213     int stackOnData;            /* stack after data segment  */
214     int c1mode;                 /* Act like c1 - no pre-proc, asm or link */
215     char *peep_file;            /* additional rules for peep hole */
216     char *out_name;             /* Asm output name for c1 mode */
217     int nostdlib;               /* Don't use standard lib files */
218     int nostdinc;               /* Don't use standard include files */
219     int verbose;                /* Show what the compiler is doing */
220     int shortisint;             /* treat short like int or char */
221
222     char *calleeSaves[128];     /* list of functions using callee save */
223     char *excludeRegs[32];      /* registers excluded from saving */
224
225     /* starting address of the segments */
226     int xstack_loc;             /* initial location of external stack */
227     int stack_loc;              /* initial value of internal stack pointer */
228     int xdata_loc;              /* xternal ram starts at address */
229     int data_loc;               /* interram start location       */
230     int idata_loc;              /* indirect address space        */
231     int code_loc;               /* code location start           */
232     int iram_size;              /* internal ram size (used only for error checking) */
233   };
234
235 /* forward definition for variables accessed globally */
236 extern char *currFname;
237 extern char *srcFileName;       /* source file name without the extenstion */
238 extern char *moduleName;        /* source file name without path & extension */
239 extern int currLineno;          /* current line number    */
240 extern int yylineno;            /* line number of the current file SDCC.lex */
241 extern FILE *yyin;              /* */
242 extern FILE *asmFile;           /* assembly output file */
243 extern FILE *cdbFile;           /* debugger symbol file */
244 extern int NestLevel;           /* NestLevel                 SDCC.y   */
245 extern int stackPtr;            /* stack pointer             SDCC.y   */
246 extern int xstackPtr;           /* external stack pointer    SDCC.y   */
247 extern int reentrant;           /* /X flag has been sent     SDCC.y */
248 extern char buffer[];           /* general buffer      SDCCgen.c   */
249 extern int currRegBank;         /* register bank being used   SDCCgens.c   */
250 extern struct symbol *currFunc; /* current function    SDCCgens.c */
251 extern int cNestLevel;          /* block nest level  SDCCval.c      */
252 extern int currBlockno;         /* sequentail block number */
253 extern struct optimize optimize;
254 extern struct options options;
255 extern unsigned maxInterrupts;
256
257 /* Visible from SDCCmain.c */
258 extern int nrelFiles;
259 extern char *relFiles[128];
260 extern char *libFiles[128];
261 extern int nlibFiles;
262 extern bool verboseExec ;
263
264 void parseWithComma (char **, char *);
265
266 /** Creates a temporary file a'la tmpfile which avoids the bugs
267     in cygwin wrt c:\tmp.
268     Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
269 */
270 FILE *tempfile (void);
271
272 /** Creates a duplicate of the string 'sz' a'la strdup but using
273     libgc.
274 */
275 char *gc_strdup (const char *sz);
276
277 /** An assert() macro that will go out through sdcc's error
278     system.
279 */
280 #define wassertl(a,s)   ((a) ? 0 : \
281         (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
282
283 #define wassert(a)    wassertl(a,"code generator internal error")
284
285 #define DUMP_RAW0 1
286 #define DUMP_RAW1 DUMP_RAW0+1
287 #define DUMP_CSE DUMP_RAW1+1
288 #define DUMP_DFLOW DUMP_CSE+1
289 #define DUMP_GCSE DUMP_DFLOW+1
290 #define DUMP_DEADCODE DUMP_GCSE+1
291 #define DUMP_LOOP DUMP_DEADCODE+1
292 #define DUMP_LOOPG DUMP_LOOP+1
293 #define DUMP_LOOPD DUMP_LOOPG+1
294 #define DUMP_RANGE DUMP_LOOPD+1
295 #define DUMP_PACK DUMP_RANGE+1
296 #define DUMP_RASSGN DUMP_PACK+1
297 #define DUMP_LRANGE DUMP_RASSGN+1
298
299 struct _dumpFiles {
300   int id;
301   char *ext;
302   FILE *filePtr;
303 };
304
305 extern struct _dumpFiles dumpFiles[];
306
307 /* Buffer which can be used to hold a file name; assume it will
308  * be trashed by any function call within SDCC.
309  */
310 extern char scratchFileName[FILENAME_MAX];
311
312 #endif