fix some grossness in the logic operations (genAnd, genOr, genXor)
[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
10 #define TARGET_ID_MCS51    1
11 #define TARGET_ID_GBZ80    2
12 #define TARGET_ID_Z80      3
13 #define TARGET_ID_AVR      4
14 #define TARGET_ID_DS390    5
15 #define TARGET_ID_PIC      6
16 #define TARGET_ID_I186     7
17 #define TARGET_ID_TLCS900H 8
18 #define TARGET_ID_XA51     9
19
20 /* Macro to test the target we are compiling for.
21    Can only be used after SDCCmain has defined the port
22 */
23 #define TARGET_IS_MCS51 (port->id==TARGET_ID_MCS51)
24 #define TARGET_IS_GBZ80 (port->id==TARGET_ID_GBZ80)
25 #define TARGET_IS_Z80 (port->id==TARGET_ID_Z80)
26 #define TARGET_IS_AVR (port->id==TARGET_ID_AVR)
27 #define TARGET_IS_DS390 (port->id==TARGET_ID_DS390)
28 #define TARGET_IS_PIC   (port->id==TARGET_ID_PIC)
29 #define TARGET_IS_I186 (port->id==TARGET_ID_I186)
30 #define TARGET_IS_TCLS900H (port->id==TARGET_ID_TCLS900H)
31
32 /* Processor specific names */
33 typedef struct
34   {
35 /** Unique id for this target */
36     const int id;
37 /** Target name used for -m */
38     const char *target;
39
40 /** Target name string, used for --help */
41     const char *target_name;
42
43     struct
44       {
45         /** TRUE if all types of glue functions should be inserted into
46             the file that also defines main.
47             We dont want this in cases like the z80 where the startup
48             code is provided by a seperate module.
49         */
50         bool glue_up_main;
51         /* OR of MODEL_* */
52         int supported_models;
53         int default_model;
54       }
55     general;
56
57     /* assembler related information */
58     struct
59       {
60         /** Command to run and arguments (eg as-z80) */
61         const char **cmd;
62         /** Alternate macro based form. */
63         const char *mcmd;
64         /** Arguments for debug mode. */
65         const char *debug_opts;
66         /** Arguments for normal assembly mode. */
67         const char *plain_opts;
68         /* print externs as global */
69         int externGlobal;
70         /* assembler file extension */
71         const char *file_ext;
72       }
73     assembler;
74
75     /* linker related info */
76     struct
77       {
78         /** Command to run (eg link-z80) */
79         const char **cmd;
80         /** Alternate macro based form. */
81         const char *mcmd;
82         /** If non-null will be used to execute the link. */
83         void (*do_link) (void);
84         /** Extention for object files (.rel, .obj, ...) */
85         const char *rel_ext;
86       }
87     linker;
88
89     struct
90       {
91 /** Default peephole rules */
92         char *default_rules;
93       }
94     peep;
95
96 /** Basic type sizes */
97     struct
98       {
99         int char_size;
100         int short_size;
101         int int_size;
102         int long_size;
103         int ptr_size;
104         int fptr_size;
105         int gptr_size;
106         int bit_size;
107         int float_size;
108         int max_base_size;
109       }
110     s;
111
112 /** memory regions related stuff */
113     struct
114       {
115         const char *xstack_name;
116         const char *istack_name;
117         const char *code_name;
118         const char *data_name;
119         const char *idata_name;
120         const char *xdata_name;
121         const char *bit_name;
122         const char *reg_name;
123         const char *static_name;
124         const char *overlay_name;
125         const char *post_static_name;
126         const char *home_name;
127         struct memmap *default_local_map;       /* default location for auto vars */
128         struct memmap *default_globl_map;       /* default location for globl vars */
129         int code_ro;            /* code space read-only 1=yes */
130       }
131     mem;
132
133     /* stack related information */
134     struct
135       {
136 /** -1 for grows down (z80), +1 for grows up (mcs51) */
137         int direction;
138 /** Extra overhead when calling between banks */
139         int bank_overhead;
140 /** Extra overhead when the function is an ISR */
141         int isr_overhead;
142 /** Standard overhead for a function call */
143         int call_overhead;
144 /** Re-enterant space */
145         int reent_overhead;
146         /** 'banked' call overhead.
147             Mild overlap with bank_overhead */
148         int banked_overhead;
149       }
150     stack;
151
152     struct
153       {
154         /** One more than the smallest 
155             mul/div operation the processor can do nativley 
156             Eg if the processor has an 8 bit mul, nativebelow is 2 */
157         unsigned muldiv;
158         unsigned shift;
159       }
160     support;
161
162 /** Prefix to add to a C function (eg "_") */
163     const char *fun_prefix;
164
165     /** Called once the processor target has been selected.
166         First chance to initalise and set any port specific variables.
167         'port' is set before calling this.  May be NULL.
168     */
169     void (*init) (void);
170 /** Parses one option + its arguments */
171       bool (*parseOption) (int *pargc, char **argv, int *i);
172 /** Called after all the options have been parsed. */
173     void (*finaliseOptions) (void);
174     /** Called after the port has been selected but before any
175         options are parsed. */
176     void (*setDefaultOptions) (void);
177 /** Does the dirty work. */
178     void (*assignRegisters) (struct eBBlock **, int);
179
180     /** Returns the register name of a symbol.
181         Used so that 'regs' can be an incomplete type. */
182     const char *(*getRegName) (struct regs * reg);
183
184     /* list of keywords that are used by this
185        target (used by lexer) */
186     char **keywords;
187
188     /* Write any port specific assembler output. */
189     void (*genAssemblerPreamble) (FILE * of);
190
191     /* Write the port specific IVT. If genIVT is NULL or if
192      * it returns zero, default (8051) IVT generation code
193      * will be used. 
194      */
195     int (*genIVT) (FILE * of, symbol ** intTable, int intCount);
196
197
198     /* parameter passing in register related functions */
199     void (*reset_regparms) ();  /* reset the register count */
200     int (*reg_parm) (struct sym_link *);        /* will return 1 if can be passed in register */
201
202     /** Process the pragma string 'sz'.  Returns 0 if recognised and
203         processed, 1 otherwise.  May be NULL.
204     */
205     int (*process_pragma) (const char *sz);
206
207     /** Mangles a support function name to reflect the calling model. 
208      */
209     char *(*getMangledFunctionName) (char *szOrginial);
210
211     /** Returns true if the port can multiply the two types nativly
212         without using support functions.
213     */
214     bool (*hasNativeMulFor) (iCode *ic, sym_link *left, sym_link *right);
215
216     /** If TRUE, then tprintf and !dw will be used for some initalisers
217      */
218     bool use_dw_for_init;
219
220     /* condition transformations */
221     bool lt_nge;                /* transform (a < b)  to !(a >= b)  */
222     bool gt_nle;                /* transform (a > b)  to !(a <= b)  */
223     bool le_ngt;                /* transform (a <= b) to !(a > b)   */
224     bool ge_nlt;                /* transform (a >= b) to !(a < b)   */
225     bool ne_neq;                /* transform a != b --> ! (a == b)  */
226     bool eq_nne;                /* transform a == b --> ! (a != b)  */
227
228     bool arrayInitializerSuppported;  
229       
230 #define PORT_MAGIC 0xAC32
231 /** Used at runtime to detect if this structure has been completly filled in. */
232     int magic;
233   }
234 PORT;
235
236 extern PORT *port;
237
238 #if !OPT_DISABLE_MCS51
239 extern PORT mcs51_port;
240 #endif
241 #if !OPT_DISABLE_GBZ80
242 extern PORT gbz80_port;
243 #endif
244 #if !OPT_DISABLE_Z80
245 extern PORT z80_port;
246 #endif
247 #if !OPT_DISABLE_AVR
248 extern PORT avr_port;
249 #endif
250 #if !OPT_DISABLE_DS390
251 extern PORT ds390_port;
252 #endif
253 #if !OPT_DISABLE_PIC
254 extern PORT pic_port;
255 #endif
256 #if !OPT_DISABLE_I186
257 extern PORT i186_port;
258 #endif
259 #if !OPT_DISABLE_TLCS900H
260 extern PORT tlcs900h_port;
261 #endif
262
263 #endif /* PORT_INCLUDE*/