Added post increment optimization for msc51 &
[fw/sdcc] / src / mcs51 / main.c
1 /** @file main.c
2     mcs51 specific general functions.
3
4     Note that mlh prepended _mcs51_ on the static functions.  Makes
5     it easier to set a breakpoint using the debugger.
6 */
7 #include "common.h"
8 #include "main.h"
9 #include "ralloc.h"
10 #include "gen.h"
11
12 static char _defaultRules[] =
13 {
14 #include "peeph.rul"
15 };
16
17 /* list of key words used by msc51 */
18 static char *_mcs51_keywords[] =
19 {
20   "at",
21   "bit",
22   "code",
23   "critical",
24   "data",
25   "far",
26   "idata",
27   "interrupt",
28   "near",
29   "pdata",
30   "reentrant",
31   "sfr",
32   "sbit",
33   "using",
34   "xdata",
35   "_data",
36   "_code",
37   "_generic",
38   "_near",
39   "_xdata",
40   "_pdata",
41   "_idata",
42   NULL
43 };
44
45
46 void mcs51_assignRegisters (eBBlock ** ebbs, int count);
47
48 static int regParmFlg = 0;      /* determine if we can register a parameter */
49
50 static void
51 _mcs51_init (void)
52 {
53   asm_addTree (&asm_asxxxx_mapping);
54 }
55
56 static void
57 _mcs51_reset_regparm ()
58 {
59   regParmFlg = 0;
60 }
61
62 static int
63 _mcs51_regparm (sym_link * l)
64 {
65   /* for this processor it is simple
66      can pass only the first parameter in a register */
67   if (regParmFlg)
68     return 0;
69
70   regParmFlg = 1;
71   return 1;
72 }
73
74 static bool
75 _mcs51_parseOptions (int *pargc, char **argv, int *i)
76 {
77   /* TODO: allow port-specific command line options to specify
78    * segment names here.
79    */
80   return FALSE;
81 }
82
83 static void
84 _mcs51_finaliseOptions (void)
85 {
86   if (options.model == MODEL_LARGE) {
87       port->mem.default_local_map = xdata;
88       port->mem.default_globl_map = xdata;
89     }
90   else
91     {
92       port->mem.default_local_map = data;
93       port->mem.default_globl_map = data;
94     }
95 }
96
97 static void
98 _mcs51_setDefaultOptions (void)
99 {
100 }
101
102 static const char *
103 _mcs51_getRegName (struct regs *reg)
104 {
105   if (reg)
106     return reg->name;
107   return "err";
108 }
109
110 static void
111 _mcs51_genAssemblerPreamble (FILE * of)
112 {
113 }
114
115 /* Generate interrupt vector table. */
116 static int
117 _mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
118 {
119   return FALSE;
120 }
121
122 /** $1 is always the basename.
123     $2 is always the output file.
124     $3 varies
125     $l is the list of extra options that should be there somewhere...
126     MUST be terminated with a NULL.
127 */
128 static const char *_linkCmd[] =
129 {
130   "aslink", "-nf", "$1", NULL
131 };
132
133 static const char *_asmCmd[] =
134 {
135   "asx8051", "$l", "-plosgffc", "$1.asm", NULL
136 };
137
138 /* Globals */
139 PORT mcs51_port =
140 {
141   TARGET_ID_MCS51,
142   "mcs51",
143   "MCU 8051",                   /* Target name */
144   {
145     TRUE,                       /* Emit glue around main */
146     MODEL_SMALL | MODEL_LARGE,
147     MODEL_SMALL
148   },
149   {
150     _asmCmd,
151     "-plosgffc",                /* Options with debug */
152     "-plosgff",                 /* Options without debug */
153     0,
154     ".asm"
155   },
156   {
157     _linkCmd,
158     NULL,
159     ".rel"
160   },
161   {
162     _defaultRules
163   },
164   {
165         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
166     1, 1, 2, 4, 1, 2, 3, 1, 4, 4
167   },
168   {
169     "XSEG    (XDATA)",
170     "STACK   (DATA)",
171     "CSEG    (CODE)",
172     "DSEG    (DATA)",
173     "ISEG    (DATA)",
174     "XSEG    (XDATA)",
175     "BSEG    (BIT)",
176     "RSEG    (DATA)",
177     "GSINIT  (CODE)",
178     "OSEG    (OVR,DATA)",
179     "GSFINAL (CODE)",
180     "HOME        (CODE)",
181     NULL,
182     NULL,
183     1
184   },
185   {
186     +1, 1, 4, 1, 1, 0
187   },
188     /* mcs51 has an 8 bit mul */
189   {
190     1, 0
191   },
192   "_",
193   _mcs51_init,
194   _mcs51_parseOptions,
195   _mcs51_finaliseOptions,
196   _mcs51_setDefaultOptions,
197   mcs51_assignRegisters,
198   _mcs51_getRegName,
199   _mcs51_keywords,
200   _mcs51_genAssemblerPreamble,
201   _mcs51_genIVT,
202   _mcs51_reset_regparm,
203   _mcs51_regparm,
204   NULL,
205   FALSE,
206   0,                            /* leave lt */
207   0,                            /* leave gt */
208   1,                            /* transform <= to ! > */
209   1,                            /* transform >= to ! < */
210   1,                            /* transform != to !(a == b) */
211   0,                            /* leave == */
212   PORT_MAGIC
213 };