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