Added post increment optimization for msc51 &
[fw/sdcc] / src / z80 / gbz80.c
1 /** @file z80/gbz80.c
2     Extra bits ontop of the z80 port to target the Gameboy's Z80 like
3     processor.
4
5     Michael Hope <michaelh@earthling.net> 2000
6 */
7
8 #include "z80.h"
9
10 static char _defaultRules[] =
11 {
12 #include "peeph.rul"
13 #include "peeph-gbz80.rul"
14 };
15
16 static char *_gbz80_keywords[] =
17 {NULL};
18
19 static bool
20 _gbz80_parseOptions (int *pargc, char **argv, int *i)
21 {
22   return FALSE;
23 }
24
25 static void
26 _gbz80_init (void)
27 {
28   z80_opts.sub = SUB_GBZ80;
29 }
30
31 static void
32 _gbz80_finaliseOptions (void)
33 {
34   port->mem.default_local_map = data;
35   port->mem.default_globl_map = data;
36 }
37
38 static void
39 _gbz80_setDefaultOptions (void)
40 {
41   options.genericPtr = 1;       /* default on */
42   options.nopeep = 0;
43   options.stackAuto = 1;
44   options.mainreturn = 1;
45   /* first the options part */
46   options.intlong_rent = 1;
47
48   optimize.global_cse = 1;
49   optimize.label1 = 1;
50   optimize.label2 = 1;
51   optimize.label3 = 1;
52   optimize.label4 = 1;
53   optimize.loopInvariant = 1;
54   optimize.loopInduction = 0;
55 }
56
57 static const char *
58 _gbz80_getRegName (struct regs *reg)
59 {
60   if (reg)
61     return reg->name;
62   assert (0);
63   return "err";
64 }
65
66 /** $1 is always the basename.
67     $2 is always the output file.
68     $3 varies
69     $l is the list of extra options that should be there somewhere...
70     MUST be terminated with a NULL.
71 */
72 static const char *_linkCmd[] =
73 {
74   "link-gbz80", "-nf", "$1", NULL
75 };
76
77 static const char *_asmCmd[] =
78 {
79   "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
80 };
81
82 /* Globals */
83 PORT gbz80_port =
84 {
85   "gbz80",
86   "Gameboy Z80-like",           /* Target name */
87   {
88     FALSE,
89   },
90   {
91     _asmCmd,
92     "-plosgff",                 /* Options with debug */
93     "-plosgff",                 /* Options without debug */
94     0,
95     ".asm"
96   },
97   {
98     _linkCmd
99   },
100   {
101     _defaultRules
102   },
103   {
104         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
105     1, 1, 2, 4, 2, 2, 2, 1, 4, 4
106   },
107   {
108     "_XSEG",
109     "_STACK",
110     "_CODE",
111     "_DATA",
112     "_ISEG",
113     "_XSEG",
114     "_BSEG",
115     "_RSEG",
116     "_GSINIT",
117     "_OVERLAY",
118     "_GSFINAL",
119     NULL,
120     NULL
121   },
122   {
123     -1, 0, 0, 4, 0
124   },
125     /* Z80 has no native mul/div commands */
126   {
127     0
128   },
129   _gbz80_init,
130   _gbz80_parseOptions,
131   _gbz80_finaliseOptions,
132   _gbz80_setDefaultOptions,
133   z80_assignRegisters,
134   _gbz80_getRegName,
135   _gbz80_keywords,
136   0,                            /* no assembler preamble */
137   0,                            /* no local IVT generation code */
138 };