Added options --code-size and --xram-size
[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_REG_PARMS  1
57 typedef int bool;
58
59 #ifndef max
60 #define max(a,b) (a > b ? a : b)
61 #endif
62
63 #ifndef min
64 #define min(a,b) (a < b ? a : b)
65 #endif
66
67 #ifndef THROWS
68 #define THROWS
69 #define THROW_NONE  0
70 #define THROW_SRC   1
71 #define THROW_DEST  2
72 #define THROW_BOTH  3
73 #endif
74
75 /* size's in bytes  */
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
86
87
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
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     MODEL_PAGE0 = 32 /* for the xa51 port */
190   };
191
192 /* overlay segment name and the functions
193    that belong to it. used by pragma overlay */
194 typedef struct {
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 */
198 } olay;
199
200 /* other command line options */
201 struct options
202   {
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 dump_raw;               /* dump after intermediate code generation */
208     int dump_gcse;              /* dump after gcse */
209     int dump_loop;              /* dump after loop optimizations */
210     int dump_kill;              /* dump after dead code elimination */
211     int dump_range;             /* dump after live range analysis */
212     int dump_pack;              /* dump after register packing */
213     int dump_rassgn;            /* dump after register assignment */
214     int dump_tree;              /* dump front-end tree before lowering to iCode */
215     int cc_only;                /* compile only flag              */
216     int intlong_rent;           /* integer & long support routines reentrant */
217     int float_rent;             /* floating point routines are reentrant */
218     int out_fmt;                /* 1 = motorola S19 format 0 = intel Hex format */
219     int cyclomatic;             /* print cyclomatic information */
220     int noOverlay;              /* don't overlay local variables & parameters */
221     int mainreturn;             /* issue a return after main */
222     int xram_movc;              /* use movc instead of movx to read xram (mcs51) */
223     int nopeep;                 /* no peep hole optimization */
224     int asmpeep;                /* pass inline assembler thru peep hole */
225     int debug;                  /* generate extra debug info */
226     int c1mode;                 /* Act like c1 - no pre-proc, asm or link */
227     char *peep_file;            /* additional rules for peep hole */
228     int nostdlib;               /* Don't use standard lib files */
229     int nostdinc;               /* Don't use standard include files */
230     int noRegParams;            /* Disable passing some parameters in registers */
231     int verbose;                /* Show what the compiler is doing */
232     int shortis8bits;           /* treat short like int or char */
233     int lessPedantic;           /* disable some warnings */
234     int profile;                /* Turn on extra profiling information */
235     int ommitFramePtr;          /* Turn off the frame pointer. */
236     int useAccelerator;         /* use ds390 Arithmetic Accelerator */
237     char *calleeSaves[128];     /* list of functions using callee save */
238     char *excludeRegs[32];      /* registers excluded from saving */
239     int all_callee_saves;       /* callee saves for all functions */
240     int stack_probe;            /* insert call to function __stack_probe */
241     int tini_libid;             /* library ID for TINI */
242     int protect_sp_update;      /* DS390 - will disable interrupts during ESP:SP updates */
243     int parms_in_bank1;         /* DS390 - use reg bank1 to pass parameters */
244     olay olays[128];            /* overlay segments used in #pragma OVERLAY */
245     /* starting address of the segments */
246     int xstack_loc;             /* initial location of external stack */
247     int stack_loc;              /* initial value of internal stack pointer */
248     int xdata_loc;              /* xternal ram starts at address */
249     int data_loc;               /* interram start location       */
250     int idata_loc;              /* indirect address space        */
251     int code_loc;               /* code location start           */
252     int iram_size;              /* internal ram size (used only for error checking) */    
253     int xram_size;              /* external ram size (used only for error checking) */    
254     int code_size;              /* code size (used only for error checking) */    
255   };
256
257 /* forward definition for variables accessed globally */
258 extern int noAssemble;         /* no assembly, stop after code generation */
259 extern char *yytext;
260 extern char *currFname;
261 extern char *fullSrcFileName;   /* full name for the source file; */
262                                 /* can be NULL while linking without compiling */
263 extern char *fullDstFileName;   /* full name for the output file; */
264                                 /* only given by -o, otherwise NULL */
265 extern char *dstFileName;       /* destination file name without extension */
266 extern char *dstPath;           /* path for the output files; */
267                                 /* "" is equivalent with cwd */
268 extern char *moduleName;        /* module name is source file without path and extension */
269                                 /* can be NULL while linking without compiling */
270 extern int currLineno;          /* current line number    */
271 extern int yylineno;            /* line number of the current file SDCC.lex */
272 extern FILE *yyin;              /* */
273 extern FILE *asmFile;           /* assembly output file */
274 extern FILE *cdbFile;           /* debugger symbol file */
275 extern int NestLevel;           /* NestLevel                 SDCC.y   */
276 extern int stackPtr;            /* stack pointer             SDCC.y   */
277 extern int xstackPtr;           /* external stack pointer    SDCC.y   */
278 extern int reentrant;           /* /X flag has been sent     SDCC.y */
279 extern char buffer[];           /* general buffer      SDCCgen.c   */
280 extern int currRegBank;         /* register bank being used   SDCCgens.c   */
281 extern int RegBankUsed[4];      /* JCF: register banks used       SDCCmain.c   */
282 extern struct symbol *currFunc; /* current function    SDCCgens.c */
283 extern int cNestLevel;          /* block nest level  SDCCval.c      */
284 extern int currBlockno;         /* sequentail block number */
285 extern struct optimize optimize;
286 extern struct options options;
287 extern unsigned maxInterrupts;
288
289 /* Visible from SDCCmain.c */
290 extern int nrelFiles;
291 extern char *relFiles[128];
292 extern char *libFiles[128];
293 extern int nlibFiles;
294 extern char *libPaths[128];
295 extern int nlibPaths;
296
297 extern bool verboseExec;
298 extern bool noXinitOpt;
299
300 void parseWithComma (char **, char *);
301
302 /** Creates a temporary file a'la tmpfile which avoids the bugs
303     in cygwin wrt c:\tmp.
304     Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
305 */
306 FILE *tempfile (void);
307
308 /** Creates a temporary file name a'la tmpnam which avoids the bugs
309     in cygwin wrt c:\tmp.
310     Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
311 */
312 char *
313 tempfilename (void);
314
315 /** An assert() macro that will go out through sdcc's error
316     system.
317 */
318 #define wassertl(a,s)   ((a) ? 0 : \
319         (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
320
321 #define wassert(a)    wassertl(a,"code generator internal error")
322
323 #define DUMP_RAW0 1
324 #define DUMP_RAW1 DUMP_RAW0+1
325 #define DUMP_CSE DUMP_RAW1+1
326 #define DUMP_DFLOW DUMP_CSE+1
327 #define DUMP_GCSE DUMP_DFLOW+1
328 #define DUMP_DEADCODE DUMP_GCSE+1
329 #define DUMP_LOOP DUMP_DEADCODE+1
330 #define DUMP_LOOPG DUMP_LOOP+1
331 #define DUMP_LOOPD DUMP_LOOPG+1
332 #define DUMP_RANGE DUMP_LOOPD+1
333 #define DUMP_PACK DUMP_RANGE+1
334 #define DUMP_RASSGN DUMP_PACK+1
335 #define DUMP_LRANGE DUMP_RASSGN+1
336
337 struct _dumpFiles {
338   int id;
339   char *ext;
340   FILE *filePtr;
341 };
342
343 extern struct _dumpFiles dumpFiles[];
344
345 /* Buffer which can be used to hold a file name; assume it will
346  * be trashed by any function call within SDCC.
347  */
348 extern char scratchFileName[PATH_MAX];
349
350 #endif