1 /* SDCCglobl.h - global macros etc required by all files */
13 #define NATIVE_WIN32 1
16 #define NATIVE_WIN32 1
19 # include "SDCCalloc.h"
24 #define MAX_FNAME_LEN 128
25 #define MAX_REG_PARMS 1
29 #define max(a,b) (a > b ? a : b)
33 #define min(a,b) (a < b ? a : b)
45 #define CHARSIZE port->s.char_size
46 #define SHORTSIZE port->s.short_size
47 #define INTSIZE port->s.int_size
48 #define LONGSIZE port->s.long_size
49 #define PTRSIZE port->s.ptr_size
50 #define FPTRSIZE port->s.fptr_size
51 #define GPTRSIZE port->s.gptr_size
52 #define BITSIZE port->s.bit_size
53 #define FLOATSIZE port->s.float_size
54 #define MAXBASESIZE port->s.max_base_size
57 #define PRAGMA_SAVE "SAVE"
58 #define PRAGMA_RESTORE "RESTORE"
59 #define PRAGMA_NOINDUCTION "NOINDUCTION"
60 #define PRAGMA_NOINVARIANT "NOINVARIANT"
61 #define PRAGMA_NOLOOPREV "NOLOOPREVERSE"
62 #define PRAGMA_INDUCTION "INDUCTION"
63 #define PRAGMA_STACKAUTO "STACKAUTO"
64 #define PRAGMA_NOJTBOUND "NOJTBOUND"
65 #define PRAGMA_NOGCSE "NOGCSE"
66 #define PRAGMA_NOOVERLAY "NOOVERLAY"
67 #define PRAGMA_CALLEESAVES "CALLEE-SAVES"
68 #define PRAGMA_EXCLUDE "EXCLUDE"
69 #define PRAGMA_NOREGPARMS "NOREGPARMS"
76 #define MAX_INLINEASM 4*1024
77 #define DEFPOOLSTACK(type,size) \
79 type *type##FreeStack [size] ; \
80 int type##StackPtr = 0 ;
82 #define ALLOCTYPE(type,size) if (!(type##Pool = GC_malloc(size*sizeof(type)))) \
84 werror(E_OUT_OF_MEM,__FILE__,(long) size); \
88 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
89 #define PEEK(x) x##FreeStack[x##StackPtr-1]
90 #define POP(type) type##FreeStack[--type##StackPtr]
91 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
92 (assert(x##StackPtr),0)) */
94 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
96 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
100 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
103 /* generalpurpose stack related macros */
104 #define STACK_DCL(stack,type,size) \
105 typedef type t_##stack ; \
106 t_##stack stack[size] ; \
107 t_##stack (*p_##stack) = stack + (size); \
109 /* define extern stack */
110 #define EXTERN_STACK_DCL(stack,type,size) \
111 typedef type t_##stack ; \
112 extern t_##stack stack[size] ; \
113 extern t_##stack *p_##stack;
115 #define STACK_FULL(stack) ((p_##stack) <= stack )
116 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
117 sizeof(stack)/sizeof(*stack)) )
119 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
120 #define STACK_POP_(stack) (*p_##stack++)
122 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
123 ?((t_##stack)(long)(STACK_ERR(1))) \
124 : STACK_PUSH_(stack,x) )
126 #define STACK_POP(stack) (STACK_EMPTY(stack) \
127 ?((t_##stack)(long)(STACK_ERR(0))) \
128 : STACK_POP_(stack) )
130 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
131 ?((t_##stack) NULL) \
134 #define STACK_ERR(o) ( o \
135 ? fprintf(stderr,"stack Overflow\n")\
136 : fprintf(stderr,"stack underflow\n"))
138 /* optimization options */
140 unsigned global_cse : 1 ;
141 unsigned ptrArithmetic :1;
142 unsigned label1 : 1 ;
143 unsigned label2 : 1 ;
144 unsigned label3 : 1 ;
145 unsigned label4 : 1 ;
146 unsigned loopInvariant: 1;
147 unsigned loopInduction: 1;
148 unsigned noJTabBoundary:1;
149 unsigned noLoopReverse :1;
153 Used in options.model.A bit each as port.supported_models is an OR
164 /* other command line options */
166 int model; /* see MODEL_* defines above */
167 int stackAuto : 3 ; /* Stack Automatic */
168 int useXstack : 3 ; /* use Xternal Stack */
169 int stack10bit : 3; /* use 10 bit stack (flat24 model only) */
170 int genericPtr: 1 ; /* use generic pointers */
171 int regExtend : 1 ; /* don't use extended registers */
172 int dump_raw : 1 ; /* dump after intermediate code generation */
173 int dump_gcse : 1 ; /* dump after gcse */
174 int dump_loop : 1 ; /* dump after loop optimizations */
175 int dump_kill : 1 ; /* dump after dead code elimination */
176 int dump_range: 1 ; /* dump after live range analysis */
177 int dump_pack : 1 ; /* dump after register packing */
178 int dump_rassgn:1 ; /* dump after register assignment */
179 int cc_only : 1 ; /* compile only flag */
180 int intlong_rent:1 ; /* integer & long support routines reentrant */
181 int float_rent: 1 ; /* floating point routines are reentrant */
182 int out_fmt : 1 ; /* 1 = motorola S19 format 0 = intel Hex format */
183 int cyclomatic: 1 ; /* print cyclomatic information */
184 int noOverlay : 1 ; /* don't overlay local variables & parameters */
185 int mainreturn: 1 ; /* issue a return after main */
186 int nopeep : 1 ; /* no peep hole optimization */
187 int asmpeep : 1 ; /* pass inline assembler thru peep hole */
188 int debug : 1 ; /* generate extra debug info */
189 int nodebug : 1 ; /* Generate no debug info. */
190 int stackOnData:1 ; /* stack after data segment */
191 int noregparms: 1 ; /* do not pass parameters in registers */
192 int c1mode : 1 ; /* Act like c1 - no pre-proc, asm or link */
193 char *peep_file ; /* additional rules for peep hole */
194 char *out_name ; /* Asm output name for c1 mode */
195 int nostdlib : 1 ; /* Don't use standard lib files */
196 int nostdinc : 1 ; /* Don't use standard include files */
197 int verbose : 1 ; /* Show what the compiler is doing */
199 char *calleeSaves[128]; /* list of functions using callee save */
200 char *excludeRegs[32] ; /* registers excluded from saving */
202 /* starting address of the segments */
203 int xstack_loc ; /* initial location of external stack */
204 int stack_loc ; /* initial value of internal stack pointer */
205 int xdata_loc ; /* xternal ram starts at address */
206 int data_loc ; /* interram start location */
207 int idata_loc ; /* indirect address space */
208 int code_loc ; /* code location start */
209 int iram_size ; /* internal ram size (used only for error checking) */
212 /* forward definition for variables accessed globally */
213 extern char *currFname ;
214 extern char *srcFileName; /* source file name without the extenstion */
215 extern char *moduleName ; /* source file name without path & extension */
216 extern int currLineno ; /* current line number */
217 extern int yylineno ; /* line number of the current file SDCC.lex */
218 extern FILE *yyin ; /* */
219 extern FILE *asmFile ; /* assembly output file */
220 extern FILE *cdbFile ; /* debugger symbol file */
221 extern int NestLevel ; /* NestLevel SDCC.y */
222 extern int stackPtr ; /* stack pointer SDCC.y */
223 extern int xstackPtr ; /* external stack pointer SDCC.y */
224 extern int reentrant ; /* /X flag has been sent SDCC.y */
225 extern char buffer[] ;/* general buffer SDCCgen.c */
226 extern int currRegBank; /* register bank being used SDCCgens.c */
227 extern struct symbol *currFunc; /* current function SDCCgens.c */
228 extern int cNestLevel; /* block nest level SDCCval.c */
229 extern int currBlockno; /* sequentail block number */
230 extern struct optimize optimize ;
231 extern struct options options;
232 extern int maxInterrupts;
234 /* Visible from SDCCmain.c */
235 extern int nrelFiles;
236 extern char *relFiles[128];
237 extern char *libFiles[128] ;
238 extern int nlibFiles;
239 void buildCmdLine(char *into, char **args, const char **cmds,
240 const char *p1, const char *p2,
241 const char *p3, const char **list);
242 int my_system (const char *cmd, char **cmd_argv);
244 void parseWithComma (char **,char *) ;
246 /** Creates a temporary file a'la tmpfile which avoids the bugs
247 in cygwin wrt c:\tmp.
248 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
250 FILE *tempfile(void);
252 /** Creates a duplicate of the string 'sz' a'la strdup but using
255 char *gc_strdup(const char *sz);
257 /** An assert() macro that will go out through sdcc's error
260 #define wassertl(a,s) ((a) ? 0 : \
261 (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
263 #define wassert(a) wassertl(a,"code generator internal error")