* Added z80 blurb.
[fw/sdcc] / src / z80 / main.c
1 #include "z80.h"
2
3 static char _z80_defaultRules[] =
4 {
5 #include "peeph.rul"
6 #include "peeph-z80.rul"
7 };
8
9 static char _gbz80_defaultRules[] =
10 {
11 #include "peeph.rul"
12 #include "peeph-gbz80.rul"
13 };
14
15 Z80_OPTS z80_opts;
16
17 static char *_keywords[] = { NULL };
18
19 static void _z80_init(void)
20 {
21     z80_opts.sub = SUB_Z80;
22 }
23
24 static void _gbz80_init(void)
25 {
26     z80_opts.sub = SUB_GBZ80;
27 }
28
29 static int regParmFlg = 0; /* determine if we can register a parameter */
30
31 static void _reset_regparm()
32 {
33     regParmFlg = 0;
34 }
35
36 static int _reg_parm(link *l)
37 {
38         /* for this processor it is simple
39        can pass only the first parameter in a register */
40     if (regParmFlg)
41         return 0;
42
43     regParmFlg = 1;
44     return 1;
45
46 }
47
48 static int _process_pragma(const char *sz)
49 {
50     printf("Got pragma \"%s\"\n", sz);
51     return 1;
52 }
53
54 static bool _parseOptions(int *pargc, char **argv, int *i)
55 {
56     return FALSE;
57 }
58
59 static void _finaliseOptions(void)
60 {
61     port->mem.default_local_map = data;
62     port->mem.default_globl_map = data;
63 }
64
65 static void _setDefaultOptions(void)
66 {    
67     options.genericPtr = 1;   /* default on */
68     options.nopeep    = 0;
69     options.stackAuto = 1;
70     options.mainreturn = 1;
71     options.noregparms = 1;
72     /* first the options part */
73     options.intlong_rent = 1;
74
75     optimize.global_cse = 1;    
76     optimize.label1 = 1;
77     optimize.label2 = 1;
78     optimize.label3 = 1;
79     optimize.label4 = 1;    
80     optimize.loopInvariant = 1;
81     optimize.loopInduction = 0;
82 }
83
84 static const char *_getRegName(struct regs *reg)
85 {
86     if (reg)
87         return reg->name;
88     assert(0);
89     return "err";
90 }
91
92 /** $1 is always the basename.
93     $2 is always the output file.
94     $3 varies
95     $l is the list of extra options that should be there somewhere...
96     MUST be terminated with a NULL.
97 */
98 static const char *_z80_linkCmd[] = {
99     "link-z80", "-nf", "$1", NULL
100 };
101
102 static const char *_z80_asmCmd[] = {
103     "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
104 };
105
106 /** $1 is always the basename.
107     $2 is always the output file.
108     $3 varies
109     $l is the list of extra options that should be there somewhere...
110     MUST be terminated with a NULL.
111 */
112 static const char *_gbz80_linkCmd[] = {
113     "link-gbz80", "-nf", "$1", NULL
114 };
115
116 static const char *_gbz80_asmCmd[] = {
117     "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
118 };
119
120 /* Globals */
121 PORT z80_port = {
122     "z80",
123     "Zilog Z80",                /* Target name */
124     {
125         FALSE,
126     },
127     {   
128         _z80_asmCmd,
129         "-plosgff",             /* Options with debug */
130         "-plosgff",             /* Options without debug */
131     },
132     {
133         _z80_linkCmd
134     },
135     {
136         _z80_defaultRules
137     },
138     {
139         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
140         1, 1, 2, 4, 2, 2, 2, 1, 4, 4
141     },
142     {
143         "_XSEG",
144         "_STACK",
145         "_CODE",
146         "_DATA",
147         "_ISEG",
148         "_XSEG",
149         "_BSEG",
150         "_RSEG",
151         "_GSINIT",
152         "_OVERLAY",
153         "_GSFINAL",
154         NULL,
155         NULL,
156         1
157     },
158     { 
159         -1, 0, 0, 8, 0
160     },
161     /* Z80 has no native mul/div commands */
162     {  
163         0
164     },
165     _z80_init,
166     _parseOptions,
167     _finaliseOptions,
168     _setDefaultOptions,
169     z80_assignRegisters,
170     _getRegName,
171     _keywords,
172     0,  /* no assembler preamble */
173     0,  /* no local IVT generation code */
174     _reset_regparm,
175     _reg_parm
176 };
177
178 /* Globals */
179 PORT gbz80_port = {
180     "gbz80",
181     "Gameboy Z80-like",         /* Target name */
182     {
183         FALSE,
184     },
185     {   
186         _gbz80_asmCmd,
187         "-plosgff",             /* Options with debug */
188         "-plosgff",             /* Options without debug */
189     },
190     {
191         _gbz80_linkCmd
192     },
193     {
194         _gbz80_defaultRules
195     },
196     {
197         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
198         1, 1, 2, 4, 2, 2, 2, 1, 4, 4
199     },
200     {
201         "_XSEG",
202         "_STACK",
203         "_CODE",
204         "_DATA",
205         "_ISEG",
206         "_XSEG",
207         "_BSEG",
208         "_RSEG",
209         "_GSINIT",
210         "_OVERLAY",
211         "_GSFINAL",
212         NULL,
213         NULL,
214         1
215     },
216     { 
217         -1, 0, 0, 4, 0
218     },
219     /* gbZ80 has no native mul/div commands */
220     {  
221         0
222     },
223     _gbz80_init,
224     _parseOptions,
225     _finaliseOptions,
226     _setDefaultOptions,
227     z80_assignRegisters,
228     _getRegName,
229     _keywords,
230     0,  /* no assembler preamble */
231     0,  /* no local IVT generation code */
232     _reset_regparm,
233     _reg_parm,
234     _process_pragma
235 };