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