* src/SDCCpeeph.c: made labelHashEntry global, made pcDistance, FBYNAME static,
[fw/sdcc] / src / port.h
1 /** @file port.h
2     Definitions for what a port must provide.
3     All ports are referenced in SDCCmain.c.
4 */
5 #ifndef PORT_INCLUDE
6 #define PORT_INCLUDE
7
8 #include "SDCCicode.h"
9 #include "SDCCargs.h"
10 #include "SDCCpeeph.h"
11 #include "mcs51/peep.h"
12
13 #define TARGET_ID_MCS51    1
14 #define TARGET_ID_GBZ80    2
15 #define TARGET_ID_Z80      3
16 #define TARGET_ID_AVR      4
17 #define TARGET_ID_DS390    5
18 #define TARGET_ID_PIC      6
19 #define TARGET_ID_PIC16    7
20 #define TARGET_ID_XA51     9
21 #define TARGET_ID_DS400    10
22 #define TARGET_ID_HC08     11
23
24 /* Macro to test the target we are compiling for.
25    Can only be used after SDCCmain has defined the port
26 */
27 #define TARGET_IS_MCS51 (port->id==TARGET_ID_MCS51)
28 #define TARGET_IS_GBZ80 (port->id==TARGET_ID_GBZ80)
29 #define TARGET_IS_Z80 (port->id==TARGET_ID_Z80)
30 #define TARGET_IS_AVR (port->id==TARGET_ID_AVR)
31 #define TARGET_IS_DS390 (port->id==TARGET_ID_DS390)
32 #define TARGET_IS_DS400 (port->id==TARGET_ID_DS400)
33 #define TARGET_IS_PIC   (port->id==TARGET_ID_PIC)
34 #define TARGET_IS_PIC16 (port->id==TARGET_ID_PIC16)
35 #define TARGET_IS_XA51 (port->id==TARGET_ID_XA51)
36 #define TARGET_IS_HC08 (port->id==TARGET_ID_HC08)
37
38 #define MAX_BUILTIN_ARGS        16
39 /* definition of builtin functions */
40 typedef struct builtins
41   {
42     char *name;                         /* name of builtin function */
43     char *rtype;                        /* return type as string : see typefromStr */
44     int  nParms;                        /* number of parms : max 8 */
45     char *parm_types[MAX_BUILTIN_ARGS]; /* each parm type as string : see typeFromStr */
46   } builtins;
47
48 struct ebbIndex;
49
50 /* pragma structure */
51 struct pragma_s
52   {
53     const char *name;
54     int id;
55     char deprecated;
56     int (*func)(int id, const char *name, const char *cp);
57   };
58
59 /* defined in SDCClex.lex */
60 int process_pragma_tbl(const struct pragma_s *pragma_tbl, const char *s);
61
62 /* Processor specific names */
63 typedef struct
64   {
65 /** Unique id for this target */
66     const int id;
67 /** Target name used for -m */
68     const char *target;
69
70 /** Target name string, used for --help */
71     const char *target_name;
72
73 /** Specific processor for the given target family. specified by -p */
74     char *processor;
75
76     struct
77       {
78         /** Pointer to glue function */
79         void (*do_glue)(void);
80         /** TRUE if all types of glue functions should be inserted into
81             the file that also defines main.
82             We dont want this in cases like the z80 where the startup
83             code is provided by a seperate module.
84         */
85         bool glue_up_main;
86         /* OR of MODEL_* */
87         int supported_models;
88         int default_model;
89       }
90     general;
91
92     /* assembler related information */
93     struct
94       {
95         /** Command to run and arguments (eg as-z80) */
96         const char **cmd;
97         /** Alternate macro based form. */
98         const char *mcmd;
99         /** Arguments for debug mode. */
100         const char *debug_opts;
101         /** Arguments for normal assembly mode. */
102         const char *plain_opts;
103         /* print externs as global */
104         int externGlobal;
105         /* assembler file extension */
106         const char *file_ext;
107         /** If non-null will be used to execute the assembler. */
108         void (*do_assemble) (set *);
109       }
110     assembler;
111
112     /* linker related info */
113     struct
114       {
115         /** Command to run (eg link-z80) */
116         const char **cmd;
117         /** Alternate macro based form. */
118         const char *mcmd;
119         /** If non-null will be used to execute the link. */
120         void (*do_link) (void);
121         /** Extension for object files (.rel, .obj, ...) */
122         const char *rel_ext;
123         /** 1 if port needs the .lnk file, 0 otherwise */
124         const int needLinkerScript;
125       }
126     linker;
127
128     struct
129       {
130 /** Default peephole rules */
131         char *default_rules;
132         int (*getSize)(lineNode *line);
133         bitVect * (*getRegsRead)(lineNode *line);
134         bitVect * (*getRegsWritten)(lineNode *line);
135         bool (*deadMove) (const char *op, lineNode *currPl, lineNode *head);
136       }
137     peep;
138
139 /** Basic type sizes */
140     struct
141       {
142         int char_size;
143         int short_size;
144         unsigned int int_size;
145         int long_size;
146         int ptr_size;       //near
147         int fptr_size;      //far
148         int gptr_size;      //generic
149         int bit_size;
150         int float_size;
151         int max_base_size;
152       }
153     s;
154
155 /** tags for far, near, xstack, code generic pointers */
156     struct
157       {
158         int tag_far;
159         int tag_near;
160         int tag_xstack;
161         int tag_code;
162       }
163     gp_tags;
164
165 /** memory regions related stuff */
166     struct
167       {
168         const char *xstack_name;
169         const char *istack_name;
170         const char *code_name;
171         const char *data_name;
172         const char *idata_name;
173         const char *pdata_name;
174         const char *xdata_name;
175         const char *bit_name;
176         const char *reg_name;
177         const char *static_name;
178         const char *overlay_name;
179         const char *post_static_name;
180         const char *home_name;
181         const char *xidata_name; // initialized xdata
182         const char *xinit_name; // a code copy of xidata
183         const char *const_name; // const data (code or not)
184         const char *cabs_name; // const absolute data (code or not)
185         const char *xabs_name; // absolute xdata/pdata
186         const char *iabs_name; // absolute idata/data
187         struct memmap *default_local_map; // default location for auto vars
188         struct memmap *default_globl_map; // default location for globl vars
189         int code_ro;            /* code space read-only 1=yes */
190       }
191     mem;
192
193     struct
194       {
195           void (*genExtraAreaDeclaration)(FILE *, bool);
196           void (*genExtraAreaLinkOptions)(FILE *);
197       }
198     extraAreas;
199
200     /* stack related information */
201     struct
202       {
203 /** -1 for grows down (z80), +1 for grows up (mcs51) */
204         int direction;
205 /** Extra overhead when calling between banks */
206         int bank_overhead;
207 /** Extra overhead when the function is an ISR */
208         int isr_overhead;
209 /** Standard overhead for a function call */
210         int call_overhead;
211 /** Re-enterant space */
212         int reent_overhead;
213         /** 'banked' call overhead.
214             Mild overlap with bank_overhead */
215         int banked_overhead;
216       }
217     stack;
218
219     struct
220       {
221         /** One more than the smallest
222             mul/div operation the processor can do natively
223             Eg if the processor has an 8 bit mul, native below is 2 */
224         unsigned muldiv;
225         unsigned shift;
226       }
227     support;
228
229     struct
230       {
231         void (*emitDebuggerSymbol) (char *);
232         struct
233           {
234             int (*regNum) (struct regs *);
235             bitVect * cfiSame;
236             bitVect * cfiUndef;
237             int addressSize;
238             int regNumRet;
239             int regNumSP;
240             int regNumBP;
241             int offsetSP;
242           }
243         dwarf;
244       }
245     debugger;
246
247     struct
248       {
249         int maxCount;
250         int sizeofElement;
251         int sizeofMatchJump[3];
252         int sizeofRangeCompare[3];
253         int sizeofSubtract;
254         int sizeofDispatch;
255       }
256     jumptableCost;
257
258 /** Prefix to add to a C function (eg "_") */
259     const char *fun_prefix;
260
261     /** Called once the processor target has been selected.
262         First chance to initalise and set any port specific variables.
263         'port' is set before calling this.  May be NULL.
264     */
265     void (*init) (void);
266 /** Parses one option + its arguments */
267       bool (*parseOption) (int *pargc, char **argv, int *i);
268 /** Optional list of automatically parsed options.  Should be
269     implemented to at least show the help text correctly. */
270     OPTION *poptions;
271 /** Initialise port spectific paths */
272     void (*initPaths)(void);
273 /** Called after all the options have been parsed. */
274     void (*finaliseOptions) (void);
275     /** Called after the port has been selected but before any
276         options are parsed. */
277     void (*setDefaultOptions) (void);
278 /** Does the dirty work. */
279     void (*assignRegisters) (struct ebbIndex *);
280
281     /** Returns the register name of a symbol.
282         Used so that 'regs' can be an incomplete type. */
283     const char *(*getRegName) (struct regs * reg);
284
285     /* list of keywords that are used by this
286        target (used by lexer) */
287     char **keywords;
288
289     /* Write any port specific assembler output. */
290     void (*genAssemblerPreamble) (FILE * of);
291       /* invoked at end assembler file */
292     void (*genAssemblerEnd) (FILE * of);
293
294     /* Write the port specific IVT. If genIVT is NULL or if
295      * it returns zero, default (8051) IVT generation code
296      * will be used.
297      */
298     int (*genIVT) (FILE * of, symbol ** intTable, int intCount);
299
300     void (*genXINIT) (FILE * of);
301
302     /* Write port specific startup code */
303     void (*genInitStartup) (FILE * of);
304
305     /* parameter passing in register related functions */
306     void (*reset_regparms) (void);      /* reset the register count */
307     int (*reg_parm) (struct sym_link *, bool reentrant);        /* will return 1 if can be passed in register */
308
309     /** Process the pragma string 'sz'.  Returns 0 if recognised and
310         processed, 1 otherwise.  May be NULL.
311     */
312     int (*process_pragma) (const char *sz);
313
314     /** Mangles a support function name to reflect the calling model.
315      */
316     char *(*getMangledFunctionName) (char *szOrginial);
317
318     /** Returns true if the port can multiply the two types nativly
319         without using support functions.
320     */
321     bool (*hasNativeMulFor) (iCode *ic, sym_link *left, sym_link *right);
322
323     /** Returns true if the port has implemented certain bit
324         manipulation iCodes (RRC, RLC, SWAP, GETHBIT, GETABIT, GETBYTE, GETWORD)
325     */
326     bool (*hasExtBitOp) (int op, int size);
327
328     /** Returns the relative expense of accessing a particular output
329         storage class. Larger values indicate higher expense.
330     */
331     int (*oclsExpense) (struct memmap *oclass);
332
333     /** If TRUE, then tprintf and !dw will be used for some initalisers
334      */
335     bool use_dw_for_init;
336
337     /** TRUE for targets with little endian byte ordering, FALSE for
338         targets with big endian byte ordering.
339      */
340     bool little_endian;
341
342     /* condition transformations */
343     bool lt_nge;                /* transform (a < b)  to !(a >= b)  */
344     bool gt_nle;                /* transform (a > b)  to !(a <= b)  */
345     bool le_ngt;                /* transform (a <= b) to !(a > b)   */
346     bool ge_nlt;                /* transform (a >= b) to !(a < b)   */
347     bool ne_neq;                /* transform a != b --> ! (a == b)  */
348     bool eq_nne;                /* transform a == b --> ! (a != b)  */
349
350     bool arrayInitializerSuppported;
351     bool (*cseOk) (iCode *ic, iCode *pdic);
352     builtins *builtintable;     /* table of builtin functions */
353     int unqualified_pointer;    /* unqualified pointers type is  */
354     int reset_labelKey  ;       /* reset Label no 1 at the start of a function */
355     int globals_allowed ;       /* global & static locals not allowed ?  0 ONLY TININative*/
356 #define PORT_MAGIC 0xAC32
357 /** Used at runtime to detect if this structure has been completly filled in. */
358     int magic;
359   }
360 PORT;
361
362 extern PORT *port;
363
364 #if !OPT_DISABLE_MCS51
365 extern PORT mcs51_port;
366 #endif
367 #if !OPT_DISABLE_GBZ80
368 extern PORT gbz80_port;
369 #endif
370 #if !OPT_DISABLE_Z80
371 extern PORT z80_port;
372 #endif
373 #if !OPT_DISABLE_AVR
374 extern PORT avr_port;
375 #endif
376 #if !OPT_DISABLE_DS390
377 extern PORT ds390_port;
378 #endif
379 #if !OPT_DISABLE_PIC
380 extern PORT pic_port;
381 #endif
382 #if !OPT_DISABLE_PIC16
383 extern PORT pic16_port;
384 #endif
385 #if !OPT_DISABLE_TININative
386 extern PORT tininative_port;
387 #endif
388 #if !OPT_DISABLE_XA51
389 extern PORT xa51_port;
390 #endif
391 #if !OPT_DISABLE_DS400
392 extern PORT ds400_port;
393 #endif
394 #if !OPT_DISABLE_HC08
395 extern PORT hc08_port;
396 #endif
397
398 #endif /* PORT_INCLUDE*/