Made debugging optional.
[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     options.nodebug = 1;
73     /* first the options part */
74     options.intlong_rent = 1;
75
76     optimize.global_cse = 1;    
77     optimize.label1 = 1;
78     optimize.label2 = 1;
79     optimize.label3 = 1;
80     optimize.label4 = 1;    
81     optimize.loopInvariant = 1;
82     optimize.loopInduction = 0;
83 }
84
85 static const char *_getRegName(struct regs *reg)
86 {
87     if (reg)
88         return reg->name;
89     assert(0);
90     return "err";
91 }
92
93 /** $1 is always the basename.
94     $2 is always the output file.
95     $3 varies
96     $l is the list of extra options that should be there somewhere...
97     MUST be terminated with a NULL.
98 */
99 static const char *_z80_linkCmd[] = {
100     "link-z80", "-nf", "$1", NULL
101 };
102
103 static const char *_z80_asmCmd[] = {
104     "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
105 };
106
107 /** $1 is always the basename.
108     $2 is always the output file.
109     $3 varies
110     $l is the list of extra options that should be there somewhere...
111     MUST be terminated with a NULL.
112 */
113 static const char *_gbz80_linkCmd[] = {
114     "link-gbz80", "-nf", "$1", NULL
115 };
116
117 static const char *_gbz80_asmCmd[] = {
118     "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
119 };
120
121 /* Globals */
122 PORT z80_port = {
123     "z80",
124     "Zilog Z80",                /* Target name */
125     {
126         FALSE,
127     },
128     {   
129         _z80_asmCmd,
130         "-plosgff",             /* Options with debug */
131         "-plosgff",             /* Options without debug */
132     },
133     {
134         _z80_linkCmd
135     },
136     {
137         _z80_defaultRules
138     },
139     {
140         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
141         1, 1, 2, 4, 2, 2, 2, 1, 4, 4
142     },
143     {
144         "_XSEG",
145         "_STACK",
146         "_CODE",
147         "_DATA",
148         "_ISEG",
149         "_XSEG",
150         "_BSEG",
151         "_RSEG",
152         "_GSINIT",
153         "_OVERLAY",
154         "_GSFINAL",
155         NULL,
156         NULL,
157         1
158     },
159     { 
160         -1, 0, 0, 8, 0
161     },
162     /* Z80 has no native mul/div commands */
163     {  
164         0
165     },
166     _z80_init,
167     _parseOptions,
168     _finaliseOptions,
169     _setDefaultOptions,
170     z80_assignRegisters,
171     _getRegName,
172     _keywords,
173     0,  /* no assembler preamble */
174     0,  /* no local IVT generation code */
175     _reset_regparm,
176     _reg_parm
177 };
178
179 /* Globals */
180 PORT gbz80_port = {
181     "gbz80",
182     "Gameboy Z80-like",         /* Target name */
183     {
184         FALSE,
185     },
186     {   
187         _gbz80_asmCmd,
188         "-plosgff",             /* Options with debug */
189         "-plosgff",             /* Options without debug */
190     },
191     {
192         _gbz80_linkCmd
193     },
194     {
195         _gbz80_defaultRules
196     },
197     {
198         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
199         1, 1, 2, 4, 2, 2, 2, 1, 4, 4
200     },
201     {
202         "_XSEG",
203         "_STACK",
204         "_CODE",
205         "_DATA",
206         "_ISEG",
207         "_XSEG",
208         "_BSEG",
209         "_RSEG",
210         "_GSINIT",
211         "_OVERLAY",
212         "_GSFINAL",
213         NULL,
214         NULL,
215         1
216     },
217     { 
218         -1, 0, 0, 4, 0
219     },
220     /* gbZ80 has no native mul/div commands */
221     {  
222         0
223     },
224     _gbz80_init,
225     _parseOptions,
226     _finaliseOptions,
227     _setDefaultOptions,
228     z80_assignRegisters,
229     _getRegName,
230     _keywords,
231     0,  /* no assembler preamble */
232     0,  /* no local IVT generation code */
233     _reset_regparm,
234     _reg_parm,
235     _process_pragma
236 };