added conditional transformation
[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 /* Processor specific names */
9 typedef struct {
10     /** Target name used for -m */
11     const char *target;
12
13     /** Target name string, used for --help */
14     const char *target_name;
15
16     struct {
17         /** TRUE if all types of glue functions should be inseted into
18             the file that also defines main.
19             We dont want this in cases like the z80 where the startup
20             code is provided by a seperate module.
21         */
22         bool glue_up_main;
23         /* OR of MODEL_* */
24         int supported_models;
25         int default_model;
26     } general;
27
28     /* assembler related information */
29     struct {
30         /** Command to run and arguments (eg as-z80) */
31         const char **cmd;
32         /** Arguments for debug mode.  PENDING: ignored */
33         const char *debug_opts;
34         /** Arguments for normal assembly mode.  PENDING: ignored */
35         const char *plain_opts;
36         /* print externs as global */
37         int externGlobal;
38     } assembler;
39
40     /* linker related info */
41     struct {
42         /** Command to run (eg link-z80) */
43         const char **cmd;
44         /** If non-null will be used to execute the link. */
45         void (*do_link)(void);
46         /** Extention for object files (.rel, .obj, ...) */
47         const char *rel_ext;
48     } linker;
49
50     struct {
51         /** Default peephole rules */
52         char *default_rules;
53     } peep;
54
55     /** Basic type sizes */
56     struct {
57         int char_size;
58         int short_size;
59         int int_size;
60         int long_size;
61         int ptr_size;
62         int fptr_size;
63         int gptr_size;
64         int bit_size;
65         int float_size;
66         int max_base_size;
67     } s;
68
69     /** memory regions related stuff */
70     struct {
71         const char *xstack_name;
72         const char *istack_name;
73         const char *code_name;
74         const char *data_name;
75         const char *idata_name;
76         const char *xdata_name;
77         const char *bit_name;
78         const char *reg_name;
79         const char *static_name;
80         const char *overlay_name;
81         const char *post_static_name;
82         const char *home_name;
83         struct memmap *default_local_map ; /* default location for auto vars */
84         struct memmap *default_globl_map ; /* default location for globl vars*/
85         int         code_ro;               /* code space read-only 1=yes */
86     } mem;
87     
88     /* stack related information */
89     struct {
90         /** -1 for grows down (z80), +1 for grows up (mcs51) */
91         int direction;
92         /** Extra overhead when calling between banks */
93         int bank_overhead;
94         /** Extra overhead when the function is an ISR */
95         int isr_overhead;
96         /** Standard overhead for a function call */
97         int call_overhead;
98         /** Re-enterant space */
99         int reent_overhead;
100         /** 'banked' call overhead.
101             Mild overlap with bank_overhead */
102         int banked_overhead;
103     } stack;
104
105     struct {
106         /** One more than the smallest 
107             mul/div operation the processor can do nativley 
108             Eg if the processor has an 8 bit mul, nativebelow is 2 */
109         int native_below;
110         /** The mul/div/mod functions will be made to use regparams
111             for sizeof(param) < log2(force_reg)
112             i.e. Use 2 for WORD and BYTE, 0 for none. */
113         int force_reg_param_below;
114     } muldiv;
115
116     /** Prefix to add to a C function (eg "_") */
117     const char *fun_prefix;
118
119     /** Called once the processor target has been selected.
120         First chance to initalise and set any port specific varibles.
121         'port' is set before calling this.  May be NULL.
122     */
123     void (*init)(void);
124     /** Parses one option + its arguments */
125     bool (*parseOption)(int *pargc, char **argv, int *i);
126     /** Called after all the options have been parsed. */
127     void (*finaliseOptions)(void);
128     /** Called after the port has been selected but before any
129         options are parsed. */
130     void (*setDefaultOptions)(void);
131     /** Does the dirty work. */
132     void (*assignRegisters)(struct eBBlock **, int);
133     
134     /** Returns the register name of a symbol.
135         Used so that 'regs' can be an incomplete type. */
136     const char *(*getRegName)(struct regs *reg);
137
138     /* list of keywords that are used by this
139        target (used by lexer) */
140     char **keywords; 
141     
142     /* Write any port specific assembler output. */
143     void (*genAssemblerPreamble)(FILE *of);
144     
145     /* Write the port specific IVT. If genIVT is NULL or if
146      * it returns zero, default (8051) IVT generation code
147      * will be used. 
148      */
149     int (*genIVT)(FILE *of, symbol **intTable, int intCount); 
150
151
152     /* parameter passing in register related functions */
153     void (*reset_regparms)();          /* reset the register count */
154     int  (*reg_parm)(struct link *);   /* will return 1 if can be passed in register */
155
156     /** Process the pragma string 'sz'.  Returns 0 if recognised and
157         processed, 1 otherwise.  May be NULL.
158     */
159     int (*process_pragma)(const char *sz);
160
161     /** If TRUE, then tprintf and !dw will be used for some initalisers
162      */
163     bool use_dw_for_init;
164
165     /* condition transformations */
166     bool lt_nge ;     /* transform (a < b)  to !(a >= b)  */
167     bool gt_nle ;     /* transform (a > b)  to !(a <= b)  */
168     bool le_ngt ;     /* transform (a <= b) to !(a > b)   */
169     bool ge_nlt ;     /* transform (a >= b) to !(a < b)   */
170     bool ne_neq ;     /* transform a != b --> ! (a == b)  */
171     bool eq_nne ;     /* transform a == b --> ! (a != b)  */
172 } PORT;
173
174 extern PORT *port;
175
176 #if !OPT_DISABLE_MCS51
177 extern PORT mcs51_port;
178 #endif
179 #if !OPT_DISABLE_GBZ80
180 extern PORT gbz80_port;
181 #endif
182 #if !OPT_DISABLE_Z80
183 extern PORT z80_port;
184 #endif
185 #if !OPT_DISABLE_AVR
186 extern PORT avr_port;
187 #endif
188 #if !OPT_DISABLE_DS390
189 extern PORT ds390_port;
190 #endif
191
192 /* Test to see if we are current compiling in DS390 mode. */
193 #define IS_MCS51_PORT (port == &mcs51_port)
194 #define IS_GBZ80_PORT (port == &gbz80_port)
195 #define IS_Z80_PORT (port == &z80_port)
196 #define IS_AVR_PORT (port == &avr_port)
197 #define IS_DS390_PORT (port == &ds390_port)
198
199 #endif