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