Pristine Ack-5.5
[Ack-5.5.git] / mach / 6805 / as / mach4.c
1 #define RCSID4 "$Id: mach4.c,v 0.3 1994/06/24 12:55:53 ceriel Exp $"
2
3 /*
4  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
5  * See the copyright notice in the ACK home directory, in the file "Copyright".
6  *
7  */
8
9 /*
10  * Motorola 6805 parsing rules
11  */
12
13 expr8
14         :
15                 expr
16                         {
17                                 fit(fitb($1.val));
18                         }
19         ;
20 bitexp
21         :
22                 absexp
23                         {
24                                 fit((unsigned) $1 <= 7);
25                                 $$ = $1 & 07;
26                         }
27         ;
28 operation
29         :
30                 NOARG
31                         {       emit1($1);}
32         |
33                 BRANCH expr
34                         {       branch($1,$2);}
35         |
36                 BBRANCH bitexp ',' expr8 ',' expr
37                         {
38                                 branch($1+($2 << 1), $6, $4);
39                         }
40         |
41                 BIT bitexp ',' expr8
42                         {
43                                 emit1($1+($2 << 1));
44 #ifdef RELOCATION
45                                 newrelo($4.typ, RELO1);
46 #endif
47                                 emit1($4.val);
48                         }
49         |
50                 RMR '<' expr8
51         |
52                 RMR expr8
53                         {
54                                 emit1($1);
55 #ifdef RELOCATION
56                                 newrelo($2.typ, RELO1);
57 #endif
58                                 emit1($2.val);
59                         }
60         |
61                 RMR expr8 ',' X
62                         {
63                                 if(small($2.val == 0 &&
64                                          ($2.typ & ~S_DOT) == DOTTYP &&
65                                          pass == PASS_2, 1))
66                                         emit1($1+0x40);
67                                 else
68                                 {
69                                         emit1($1+0x30);
70 #ifdef RELOCATION
71                                         newrelo($2.typ, RELO1);
72 #endif
73                                         emit1($2.val);
74                                 }
75                         }
76         |
77                 RMR ',' X
78                         {       emit1($1+0x40); }
79         |
80                 RM '#' expr8
81                         {
82                                 switch($1) {
83                                         case 0xa7:
84                                         case 0xac:
85                                         case 0xad:
86                                         case 0xaf:
87                                                 serror("mode error");
88                                         default:
89                                                 emit1($1);
90                                 }
91 #ifdef RELOCATION
92                                 newrelo($3.typ, RELO1);
93 #endif
94                                 emit1($3.val);
95                         }
96         |
97                 RM '<' expr8
98                         {
99                                 emit1($1+0x10);
100 #ifdef RELOCATION
101                                 newrelo($3.typ, RELO1);
102 #endif
103                                 emit1($3.val);
104                         }
105         |
106                 RM expr
107                         {
108                                 if(small(pass == PASS_2 &&
109                                          ($2.typ & ~S_DOT) == DOTTYP &&
110                                          fitb($2.val),1)) {
111                                         emit1($1+0x10);
112 #ifdef RELOCATION
113                                         newrelo($2.typ, RELO1);
114 #endif
115                                         emit1($2.val);
116                                 } else {
117                                         emit1($1+0x20);
118 #ifdef RELOCATION
119                                         newrelo($2.typ, RELO2|RELBR);
120 #endif
121                                         emit2($2.val);
122                                 }
123                         }
124         |
125                 RM '>' expr
126                         {
127                                 emit1($1+0x20);
128 #ifdef RELOCATION
129                                 newrelo($3.typ, RELO2|RELBR);
130 #endif
131                                 emit2($3.val);
132                         }
133         |
134                 RM '>' expr ',' X
135                         {
136                                 emit1($1+0x30);
137 #ifdef RELOCATION
138                                 newrelo($3.typ, RELO2|RELBR);
139 #endif
140                                 emit2($3.val);
141                         }
142         |
143                 RM expr ',' X
144                         {
145                                 if(small(pass == PASS_2 &&
146                                          ($2.typ & ~S_DOT) == DOTTYP &&
147                                          fitb($2.val),1)) {
148                                         if(small(pass == PASS_2 && 
149                                                  ($2.typ & ~S_DOT) == DOTTYP &&
150                                                  $2.val == 0,1))
151                                                 emit1($1+0x50);
152                                         else {
153                                                 emit1($1+0x40);
154 #ifdef RELOCATION
155                                                 newrelo($2.typ, RELO1);
156 #endif
157                                                 emit1($2.val);
158                                         }
159                                 } else {
160                                         small(0,1);  /* dummy */
161                                         emit1($1+0x30);
162 #ifdef RELOCATION
163                                         newrelo($2.typ, RELO2|RELBR);
164 #endif
165                                         emit2($2.val);
166                                 }
167                         }
168         |
169                 RM '<' expr8 ',' X
170                         {
171                                 emit1($1+0x40);
172 #ifdef RELOCATION
173                                 newrelo($3.typ, RELO1);
174 #endif
175                                 emit1($3.val);
176                         }
177         |
178                 RM ',' X
179                         {       emit1($1+0x50); }
180         |
181                 CMOS
182                         {
183                                 switch($1) {
184                                         case 0:
185                                                 opt_cmos = 1;
186                                                 break;
187                                         case 0x8e:
188                                         case 0x8f:
189                                                 if(! opt_cmos)
190                                                 serror("bad opcode");
191                                                 emit1($1);
192                                 }
193                         }
194         ;