1 /* SDCCglobl.h - global macros etc required by all files */
11 * Define host port dependant constants etc.
14 #define DOS_DIR_SEPARATOR_CHAR '\\'
15 #define DOS_DIR_SEPARATOR_STRING "\\"
16 #define UNIX_DIR_SEPARATOR_CHAR '/'
17 #define UNIX_DIR_SEPARATOR_STRING "/"
19 #if defined(__BORLANDC__) /* Borland Turbo C/Win32 Host */
21 #define NATIVE_WIN32 1
22 #define DIR_SEPARATOR_CHAR DOS_DIR_SEPARATOR_CHAR
23 #define DIR_SEPARATOR_STRING DOS_DIR_SEPARATOR_STRING
25 #elif defined(_MSC_VER) /* Miscosoft VC6/Win32 Host */
27 #define NATIVE_WIN32 1
29 #define DIR_SEPARATOR_CHAR DOS_DIR_SEPARATOR_CHAR
30 #define DIR_SEPARATOR_STRING DOS_DIR_SEPARATOR_STRING
32 #elif defined(__MINGW32__) /* MINGW32 DOS Host */
34 #define NATIVE_WIN32 1
35 #define DIR_SEPARATOR_CHAR DOS_DIR_SEPARATOR_CHAR
36 #define DIR_SEPARATOR_STRING DOS_DIR_SEPARATOR_STRING
38 #else /* Assume Un*x style system */
41 #define DIR_SEPARATOR_CHAR UNIX_DIR_SEPARATOR_CHAR
42 #define DIR_SEPARATOR_STRING UNIX_DIR_SEPARATOR_STRING
51 #define MAX_FNAME_LEN 128
52 #define MAX_REG_PARMS 1
56 #define max(a,b) (a > b ? a : b)
60 #define min(a,b) (a < b ? a : b)
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
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"
102 #define MAX_INLINEASM 4*1024
103 #define DEFPOOLSTACK(type,size) \
105 type *type##FreeStack [size] ; \
106 int type##StackPtr = 0 ;
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)) */
114 #define EMPTY(x) (x##StackPtr <= 1 ? 1 : 0)
116 #define EMPTY(x) (x##StackPtr == 0 ? 1 : 0)
120 #define COPYTYPE(start,end,from) (end = getSpec (start = from))
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); \
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;
135 #define STACK_FULL(stack) ((p_##stack) <= stack )
136 #define STACK_EMPTY(stack) ((p_##stack) >= (stack + \
137 sizeof(stack)/sizeof(*stack)) )
139 #define STACK_PUSH_(stack,x) (*--p_##stack = (x))
140 #define STACK_POP_(stack) (*p_##stack++)
142 #define STACK_PUSH(stack,x) (STACK_FULL(stack) \
143 ?((t_##stack)(long)(STACK_ERR(1))) \
144 : STACK_PUSH_(stack,x) )
146 #define STACK_POP(stack) (STACK_EMPTY(stack) \
147 ?((t_##stack)(long)(STACK_ERR(0))) \
148 : STACK_POP_(stack) )
150 #define STACK_PEEK(stack) (STACK_EMPTY(stack) \
151 ?((t_##stack) NULL) \
154 #define STACK_ERR(o) ( o \
155 ? fprintf(stderr,"stack Overflow\n")\
156 : fprintf(stderr,"stack underflow\n"))
158 /* optimization options */
161 unsigned global_cse:1;
162 unsigned ptrArithmetic:1;
167 unsigned loopInvariant:1;
168 unsigned loopInduction:1;
169 unsigned noJTabBoundary:1;
170 unsigned noLoopReverse:1;
174 Used in options.model.A bit each as port.supported_models is an OR
186 /* other command line options */
189 int model; /* see MODEL_* defines above */
190 int stackAuto:3; /* Stack Automatic */
191 int useXstack:3; /* use Xternal Stack */
192 int stack10bit:3; /* use 10 bit stack (flat24 model only) */
193 int genericPtr:1; /* use generic pointers */
194 int regExtend:1; /* don't use extended registers */
195 int dump_raw:1; /* dump after intermediate code generation */
196 int dump_gcse:1; /* dump after gcse */
197 int dump_loop:1; /* dump after loop optimizations */
198 int dump_kill:1; /* dump after dead code elimination */
199 int dump_range:1; /* dump after live range analysis */
200 int dump_pack:1; /* dump after register packing */
201 int dump_rassgn:1; /* dump after register assignment */
202 int cc_only:1; /* compile only flag */
203 int intlong_rent:1; /* integer & long support routines reentrant */
204 int float_rent:1; /* floating point routines are reentrant */
205 int out_fmt:1; /* 1 = motorola S19 format 0 = intel Hex format */
206 int cyclomatic:1; /* print cyclomatic information */
207 int noOverlay:1; /* don't overlay local variables & parameters */
208 int mainreturn:1; /* issue a return after main */
209 int nopeep:1; /* no peep hole optimization */
210 int asmpeep:1; /* pass inline assembler thru peep hole */
211 int debug:1; /* generate extra debug info */
212 int nodebug:1; /* Generate no debug info. */
213 int stackOnData:1; /* stack after data segment */
214 int c1mode:1; /* 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:1; /* Don't use standard lib files */
218 int nostdinc:1; /* Don't use standard include files */
219 int verbose:1; /* Show what the compiler is doing */
221 char *calleeSaves[128]; /* list of functions using callee save */
222 char *excludeRegs[32]; /* registers excluded from saving */
224 /* starting address of the segments */
225 int xstack_loc; /* initial location of external stack */
226 int stack_loc; /* initial value of internal stack pointer */
227 int xdata_loc; /* xternal ram starts at address */
228 int data_loc; /* interram start location */
229 int idata_loc; /* indirect address space */
230 int code_loc; /* code location start */
231 int iram_size; /* internal ram size (used only for error checking) */
234 /* forward definition for variables accessed globally */
235 extern char *currFname;
236 extern char *srcFileName; /* source file name without the extenstion */
237 extern char *moduleName; /* source file name without path & extension */
238 extern int currLineno; /* current line number */
239 extern int yylineno; /* line number of the current file SDCC.lex */
240 extern FILE *yyin; /* */
241 extern FILE *asmFile; /* assembly output file */
242 extern FILE *cdbFile; /* debugger symbol file */
243 extern int NestLevel; /* NestLevel SDCC.y */
244 extern int stackPtr; /* stack pointer SDCC.y */
245 extern int xstackPtr; /* external stack pointer SDCC.y */
246 extern int reentrant; /* /X flag has been sent SDCC.y */
247 extern char buffer[]; /* general buffer SDCCgen.c */
248 extern int currRegBank; /* register bank being used SDCCgens.c */
249 extern struct symbol *currFunc; /* current function SDCCgens.c */
250 extern int cNestLevel; /* block nest level SDCCval.c */
251 extern int currBlockno; /* sequentail block number */
252 extern struct optimize optimize;
253 extern struct options options;
254 extern unsigned maxInterrupts;
256 /* Visible from SDCCmain.c */
257 extern int nrelFiles;
258 extern char *relFiles[128];
259 extern char *libFiles[128];
260 extern int nlibFiles;
261 extern bool verboseExec ;
264 void buildCmdLine(char *into, char **args, const char **cmds,
265 const char *p1, const char *p2,
266 const char *p3, const char **list);
267 int my_system (const char *cmd, char **cmd_argv);
270 void parseWithComma (char **, char *);
272 /** Creates a temporary file a'la tmpfile which avoids the bugs
273 in cygwin wrt c:\tmp.
274 Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
276 FILE *tempfile (void);
278 /** Creates a duplicate of the string 'sz' a'la strdup but using
281 char *gc_strdup (const char *sz);
283 /** An assert() macro that will go out through sdcc's error
286 #define wassertl(a,s) ((a) ? 0 : \
287 (werror (E_INTERNAL_ERROR,__FILE__,__LINE__, s), 0))
289 #define wassert(a) wassertl(a,"code generator internal error")