comparison lwasm/list.c @ 457:7d6eacd87370

Make warnings still show when listings are not enabled.
author William Astle <lost@l-w.ca>
date Fri, 16 Feb 2018 23:40:53 -0700
parents 83a124428f44
children 74d0c394666e
comparison
equal deleted inserted replaced
456:83a124428f44 457:7d6eacd87370
42 int obytelen = 0; 42 int obytelen = 0;
43 43
44 char *tc; 44 char *tc;
45 45
46 if (!(as -> flags & FLAG_LIST)) 46 if (!(as -> flags & FLAG_LIST))
47 return;
48
49 if (as -> list_file)
50 { 47 {
51 if (strcmp(as -> list_file, "-") == 0) 48 of = NULL;
52 {
53 of = stdout;
54 }
55 else
56 of = fopen(as -> list_file, "w");
57 } 49 }
58 else 50 else
59 of = stdout; 51 {
60 if (!of) 52 if (as -> list_file)
61 { 53 {
62 fprintf(stderr, "Cannot open list file; list not generated\n"); 54 if (strcmp(as -> list_file, "-") == 0)
63 return; 55 {
56 of = stdout;
57 }
58 else
59 of = fopen(as -> list_file, "w");
60 }
61 else
62 of = stdout;
63
64 if (!of)
65 {
66 fprintf(stderr, "Cannot open list file; list not generated\n");
67 return;
68 }
64 } 69 }
65 70
66 for (cl = as -> line_head; cl; cl = nl) 71 for (cl = as -> line_head; cl; cl = nl)
67 { 72 {
68 char *linespec; 73 char *linespec;
69 74
70 nl = cl -> next; 75 nl = cl -> next;
89 if (nl -> warn) 94 if (nl -> warn)
90 { 95 {
91 lwasm_error_t *e; 96 lwasm_error_t *e;
92 for (e = nl -> warn; e; e = e -> next) 97 for (e = nl -> warn; e; e = e -> next)
93 { 98 {
94 if (of != stdout) printf("Warning: %s\n", e -> mess); 99 if (of != stdout) printf("Warning (%s:%d): %s\n", cl -> linespec, cl -> lineno, e -> mess);
95 fprintf(of, "Warning: %s\n", e -> mess); 100 if (of) fprintf(of, "Warning: %s\n", e -> mess);
96 } 101 }
97 } 102 }
98 if (nc == 0) 103 if (nc == 0)
99 break; 104 break;
100 } 105 }
118 if (cl -> warn) 123 if (cl -> warn)
119 { 124 {
120 lwasm_error_t *e; 125 lwasm_error_t *e;
121 for (e = cl -> warn; e; e = e -> next) 126 for (e = cl -> warn; e; e = e -> next)
122 { 127 {
123 if (of != stdout) printf("Warning: %s\n", e -> mess); 128 if (of != stdout) printf("Warning (%s:%d): %s\n", cl -> linespec, cl -> lineno, e -> mess);
124 fprintf(of, "Warning: %s\n", e -> mess); 129 if (of) fprintf(of, "Warning: %s\n", e -> mess);
125 } 130 }
126 } 131 }
127 obytelen = cl -> outputl; 132 obytelen = cl -> outputl;
128 if (obytelen > 0) 133 if (obytelen > 0)
129 { 134 {
133 } 138 }
134 if ((cl -> len < 1 && cl -> dlen < 1) && obytelen < 1 && (cl -> symset == 1 || cl -> sym == NULL) ) 139 if ((cl -> len < 1 && cl -> dlen < 1) && obytelen < 1 && (cl -> symset == 1 || cl -> sym == NULL) )
135 { 140 {
136 if (cl -> soff >= 0) 141 if (cl -> soff >= 0)
137 { 142 {
138 fprintf(of, "%04Xs ", cl -> soff & 0xffff); 143 if (of) fprintf(of, "%04Xs ", cl -> soff & 0xffff);
139 } 144 }
140 else if (cl -> dshow >= 0) 145 else if (cl -> dshow >= 0)
141 { 146 {
142 if (cl -> dsize == 1) 147 if (cl -> dsize == 1)
143 { 148 {
144 fprintf(of, " %02X ", cl -> dshow & 0xff); 149 if (of) fprintf(of, " %02X ", cl -> dshow & 0xff);
145 } 150 }
146 else 151 else
147 { 152 {
148 fprintf(of, " %04X ", cl -> dshow & 0xff); 153 if (of) fprintf(of, " %04X ", cl -> dshow & 0xff);
149 } 154 }
150 } 155 }
151 else if (cl -> dptr) 156 else if (cl -> dptr)
152 { 157 {
153 lw_expr_t te; 158 lw_expr_t te;
156 as -> csect = cl -> csect; 161 as -> csect = cl -> csect;
157 lwasm_reduce_expr(as, te); 162 lwasm_reduce_expr(as, te);
158 as -> exportcheck = 0; 163 as -> exportcheck = 0;
159 if (lw_expr_istype(te, lw_expr_type_int)) 164 if (lw_expr_istype(te, lw_expr_type_int))
160 { 165 {
161 fprintf(of, " %04X ", lw_expr_intval(te) & 0xffff); 166 if (of) fprintf(of, " %04X ", lw_expr_intval(te) & 0xffff);
162 } 167 }
163 else 168 else
164 { 169 {
165 fprintf(of, " ???? "); 170 if (of) fprintf(of, " ???? ");
166 } 171 }
167 lw_expr_destroy(te); 172 lw_expr_destroy(te);
168 } 173 }
169 else 174 else
170 { 175 {
171 fprintf(of, " "); 176 if (of) fprintf(of, " ");
172 } 177 }
173 } 178 }
174 else 179 else
175 { 180 {
176 lw_expr_t te; 181 lw_expr_t te;
180 te = lw_expr_copy(cl -> addr); 185 te = lw_expr_copy(cl -> addr);
181 as -> exportcheck = 1; 186 as -> exportcheck = 1;
182 as -> csect = cl -> csect; 187 as -> csect = cl -> csect;
183 lwasm_reduce_expr(as, te); 188 lwasm_reduce_expr(as, te);
184 as -> exportcheck = 0; 189 as -> exportcheck = 0;
185 // fprintf(of, "%s\n", lw_expr_print(te)); 190 // if (of) fprintf(of, "%s\n", lw_expr_print(te));
186 fprintf(of, "%04X%c", lw_expr_intval(te) & 0xffff, ((cl -> inmod || (cl -> dlen != cl -> len)) && instab[cl -> insn].flags & lwasm_insn_setdata) ? '.' : ' '); 191 if (of) fprintf(of, "%04X%c", lw_expr_intval(te) & 0xffff, ((cl -> inmod || (cl -> dlen != cl -> len)) && instab[cl -> insn].flags & lwasm_insn_setdata) ? '.' : ' ');
187 lw_expr_destroy(te); 192 lw_expr_destroy(te);
188 for (i = 0; i < obytelen && i < 8; i++) 193 for (i = 0; i < obytelen && i < 8; i++)
189 { 194 {
190 fprintf(of, "%02X", obytes[i]); 195 if (of) fprintf(of, "%02X", obytes[i]);
191 } 196 }
192 for (; i < 8; i++) 197 for (; i < 8; i++)
193 { 198 {
194 fprintf(of, " "); 199 if (of) fprintf(of, " ");
195 } 200 }
196 fprintf(of, " "); 201 if (of) fprintf(of, " ");
197 } 202 }
198 203
199 /* the format specifier below is deliberately chosen so that the start of the line text is at 204 /* the format specifier below is deliberately chosen so that the start of the line text is at
200 a multiple of 8 from the start of the list line */ 205 a multiple of 8 from the start of the list line */
201 206
202 #define max_linespec_len 17 207 #define max_linespec_len 17
203 208
204 // trim "include:" if it appears 209 // trim "include:" if it appears
205 if (as -> listnofile) 210 if (as -> listnofile)
206 { 211 {
207 fprintf(of, "%05d ", cl->lineno); 212 if (of) fprintf(of, "%05d ", cl->lineno);
208 } 213 }
209 else 214 else
210 { 215 {
211 linespec = cl -> linespec; 216 linespec = cl -> linespec;
212 if ((strlen(linespec) > 8) && (linespec[7] == ':')) linespec += 8; 217 if ((strlen(linespec) > 8) && (linespec[7] == ':')) linespec += 8;
213 while (*linespec == ' ') linespec++; 218 while (*linespec == ' ') linespec++;
214 219
215 fprintf(of, "(%*.*s):%05d ", max_linespec_len, max_linespec_len, linespec, cl->lineno); 220 if (of) fprintf(of, "(%*.*s):%05d ", max_linespec_len, max_linespec_len, linespec, cl->lineno);
216 } 221 }
217 222
218 if (CURPRAGMA(cl, PRAGMA_CC)) 223 if (CURPRAGMA(cl, PRAGMA_CC))
219 { 224 {
220 as->cycle_total = 0; 225 as->cycle_total = 0;
247 if (CURPRAGMA(cl, PRAGMA_6809)) ch = ']'; 252 if (CURPRAGMA(cl, PRAGMA_6809)) ch = ']';
248 sprintf(s, "%s%c", s, ch); 253 sprintf(s, "%s%c", s, ch);
249 } 254 }
250 } 255 }
251 256
252 fprintf(of, "%-8s", s); 257 if (of) fprintf(of, "%-8s", s);
253 258
254 if (CURPRAGMA(cl, PRAGMA_CT)) 259 if (CURPRAGMA(cl, PRAGMA_CT))
255 { 260 {
256 if (cl->cycle_base != 0) 261 if (cl->cycle_base != 0)
257 { 262 {
258 fprintf(of, "%-8d", as->cycle_total); 263 if (of) fprintf(of, "%-8d", as->cycle_total);
259 } 264 }
260 else 265 else
261 { 266 {
262 fprintf(of, " "); 267 if (of) fprintf(of, " ");
263 } 268 }
264 } 269 }
265 270
266 if (as -> tabwidth == 0) 271 if (as -> tabwidth == 0)
267 { 272 {
274 { 279 {
275 if ((*tc) == '\t') 280 if ((*tc) == '\t')
276 { 281 {
277 if (i % as -> tabwidth == 0) 282 if (i % as -> tabwidth == 0)
278 { 283 {
279 fputc(' ', of); 284 if (of) fputc(' ', of);
280 i++; 285 i++;
281 } 286 }
282 while (i % as -> tabwidth) 287 while (i % as -> tabwidth)
283 { 288 {
284 fputc(' ', of); 289 if (of) fputc(' ', of);
285 i++; 290 i++;
286 } 291 }
287 } 292 }
288 else 293 else
289 { 294 {
290 fputc(*tc, of); 295 if (of) fputc(*tc, of);
291 i++; 296 i++;
292 } 297 }
293 } 298 }
294 } 299 }
295 fputc('\n', of); 300 if (of) fputc('\n', of);
296 301
297 if (obytelen > 8) 302 if (obytelen > 8)
298 { 303 {
299 for (i = 8; i < obytelen; i++) 304 for (i = 8; i < obytelen; i++)
300 { 305 {
301 if (i % 8 == 0) 306 if (i % 8 == 0)
302 { 307 {
303 if (i != 8) 308 if (i != 8)
304 fprintf(of, "\n "); 309 {
310 if (of) fprintf(of, "\n ");
311 }
305 else 312 else
306 fprintf(of, " "); 313 {
307 } 314 if (of) fprintf(of, " ");
308 fprintf(of, "%02X", obytes[i]); 315 }
316 }
317 if (of) fprintf(of, "%02X", obytes[i]);
309 } 318 }
310 if (i > 8) 319 if (i > 8)
311 fprintf(of, "\n"); 320 if (of) fprintf(of, "\n");
312 } 321 }
313 lw_free(obytes); 322 lw_free(obytes);
314 obytes = NULL; 323 obytes = NULL;
315 } 324 }
316 if ((as -> flags & FLAG_SYMBOLS)) 325 if ((as -> flags & FLAG_SYMBOLS))
317 list_symbols(as, of); 326 list_symbols(as, of);
327 if (of && of != stdout)
328 fclose(of);
318 } 329 }