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