1 /* SDCCglobl.h - global macros etc required by all files */
13 #define GC_malloc malloc
15 #define GC_realloc realloc
16 #define GC_malloc_atomic malloc
26 #define MAX_FNAME_LEN 128
27 #define MAX_REG_PARMS 1
31 #define max(a,b) (a > b ? a : b)
35 #define min(a,b) (a < b ? a : b)
59 #define PRAGMA_SAVE "SAVE"
60 #define PRAGMA_RESTORE "RESTORE"
61 #define PRAGMA_NOINDUCTION "NOINDUCTION"
62 #define PRAGMA_NOINVARIANT "NOINVARIANT"
63 #define PRAGMA_NOLOOPREV "NOLOOPREVERSE"
64 #define PRAGMA_INDUCTION "INDUCTION"
65 #define PRAGMA_STACKAUTO "STACKAUTO"
66 #define PRAGMA_NOJTBOUND "NOJTBOUND"
67 #define PRAGMA_NOGCSE "NOGCSE"
68 #define PRAGMA_NOOVERLAY "NOOVERLAY"
69 #define PRAGMA_CALLEESAVES "CALLEE-SAVES"
70 #define PRAGMA_EXCLUDE "EXCLUDE"
71 #define PRAGMA_NOREGPARMS "NOREGPARMS"
78 #define MAX_INLINEASM 4*1024
79 #define DEFPOOLSTACK(type,size) \
81 type *type##FreeStack [size] ; \
82 int type##StackPtr = 0 ;
84 #define ALLOCTYPE(type,size) if (!(type##Pool = GC_malloc(size*sizeof(type)))) \
86 werror(E_OUT_OF_MEM,__FILE__,(long) size); \
90 #define PUSH(x,y) x##FreeStack[x##StackPtr++] = y
91 #define PEEK(x) x##FreeStack[x##StackPtr-1]
92 #define POP(type) type##FreeStack[--type##StackPtr]
93 /* #define POP(x) (x##StackPtr ? x##FreeStack[--x##StackPtr] : \
94 (assert(x##StackPtr),0)) */
96 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
98 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
101 #define ALLOC(x,sz) if (!(x = GC_malloc(sz))) \
103 werror(E_OUT_OF_MEM,__FILE__,(long) sz);\
107 #define ALLOC_ATOMIC(x,sz) if (!(x = GC_malloc_atomic(sz))) \
109 werror(E_OUT_OF_MEM,__FILE__,(long) sz); \
113 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
116 /* generalpurpose stack related macros */
117 #define STACK_DCL(stack,type,size) \
118 typedef type t_##stack ; \
119 t_##stack stack[size] ; \
120 t_##stack (*p_##stack) = stack + (size); \
122 /* define extern stack */
123 #define EXTERN_STACK_DCL(stack,type,size) \
124 typedef type t_##stack ; \
125 extern t_##stack stack[size] ; \
126 extern t_##stack *p_##stack;
128 #define STACK_FULL(stack) ((p_##stack) <= stack )
129 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
130 sizeof(stack)/sizeof(*stack)) )
132 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
133 #define STACK_POP_(stack) (*p_##stack++)
135 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
136 ?((t_##stack)(long)(STACK_ERR(1))) \
137 : STACK_PUSH_(stack,x) )
139 #define STACK_POP(stack) (STACK_EMPTY(stack) \
140 ?((t_##stack)(long)(STACK_ERR(0))) \
141 : STACK_POP_(stack) )
143 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
144 ?((t_##stack) NULL) \
147 #define STACK_ERR(o) ( o \
148 ? fprintf(stderr,"stack Overflow\n")\
149 : fprintf(stderr,"stack underflow\n"))
151 /* optimization options */
153 unsigned global_cse : 1 ;
154 unsigned ptrArithmetic :1;
155 unsigned label1 : 1 ;
156 unsigned label2 : 1 ;
157 unsigned label3 : 1 ;
158 unsigned label4 : 1 ;
159 unsigned loopInvariant: 1;
160 unsigned loopInduction: 1;
161 unsigned noJTabBoundary:1;
162 unsigned noLoopReverse :1;
165 /* other command line options */
167 int model : 1 ; /* LARGE == 1 */
168 int stackAuto : 3 ; /* Stack Automatic */
169 int useXstack : 3 ; /* use Xternal Stack */
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 stackOnData:1 ; /* stack after data segment */
190 int noregparms: 1 ; /* do not pass parameters in registers */
191 char *peep_file ; /* additional rules for peep hole */
193 char *calleeSaves[128]; /* list of functions using callee save */
194 char *excludeRegs[32] ; /* registers excluded from saving */
196 /* starting address of the segments */
197 int xstack_loc ; /* initial location of external stack */
198 int stack_loc ; /* initial value of internal stack pointer */
199 int xdata_loc ; /* xternal ram starts at address */
200 int data_loc ; /* interram start location */
201 int idata_loc ; /* indirect address space */
202 int code_loc ; /* code location start */
203 int iram_size ; /* internal ram size (used only for error checking) */
206 /* forward definition for variables accessed globally */
207 extern char *currFname ;
208 extern char *srcFileName; /* source file name without the extenstion */
209 extern char *moduleName ; /* source file name without path & extension */
210 extern int currLineno ; /* current line number */
211 extern int yylineno ; /* line number of the current file SDCC.lex */
212 extern FILE *yyin ; /* */
213 extern FILE *asmFile ; /* assembly output file */
214 extern FILE *cdbFile ; /* debugger symbol file */
215 extern int NestLevel ; /* NestLevel SDCC.y */
216 extern int stackPtr ; /* stack pointer SDCC.y */
217 extern int xstackPtr ; /* external stack pointer SDCC.y */
218 extern int reentrant ; /* /X flag has been sent SDCC.y */
219 extern char buffer[] ;/* general buffer SDCCgen.c */
220 extern int currRegBank; /* register bank being used SDCCgens.c */
221 extern struct symbol *currFunc; /* current function SDCCgens.c */
222 extern int cNestLevel; /* block nest level SDCCval.c */
223 extern int currBlockno; /* sequentail block number */
224 extern struct optimize optimize ;
225 extern struct options options;
226 extern int maxInterrupts;
227 void parseWithComma (char **,char *) ;