comparison lwasm/lwasm.c @ 226:7c2c2239ec9c

Make unicorns grok errors and warnings. Added unicorn formatted error and warning output and also a framework to handle errors which know which character position in the line they occurred in.
author William Astle <lost@l-w.ca>
date Sun, 15 Jul 2012 21:19:43 -0600
parents 398773d7e504
children 41d64951eb32
comparison
equal deleted inserted replaced
225:823560a8c251 226:7c2c2239ec9c
197 } 197 }
198 } 198 }
199 return NULL; 199 return NULL;
200 } 200 }
201 201
202 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...) 202 void lwasm_register_error_real(asmstate_t *as, line_t *l, char *iptr, const char *msg, va_list args)
203 { 203 {
204 lwasm_error_t *e; 204 lwasm_error_t *e;
205 va_list args;
206 char errbuff[1024]; 205 char errbuff[1024];
207 206
208 if (!l) 207 if (!l)
209 return; 208 return;
210 209
211 va_start(args, msg);
212
213 e = lw_alloc(sizeof(lwasm_error_t)); 210 e = lw_alloc(sizeof(lwasm_error_t));
214 211
215 e -> next = l -> err; 212 e -> next = l -> err;
216 l -> err = e; 213 l -> err = e;
214 e -> charpos = -1;
215
216 if (iptr)
217 e -> charpos = iptr - l -> ltext + 1;
217 218
218 as -> errorcount++; 219 as -> errorcount++;
219 220
220 (void)vsnprintf(errbuff, 1024, msg, args); 221 (void)vsnprintf(errbuff, 1024, msg, args);
221 e -> mess = lw_strdup(errbuff); 222 e -> mess = lw_strdup(errbuff);
223 }
224
225 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...)
226 {
227 va_list args;
228
229 va_start(args, msg);
230
231 lwasm_register_error_real(as, l, NULL, msg, args);
222 232
223 va_end(args); 233 va_end(args);
224 } 234 }
225 235
226 void lwasm_register_warning(asmstate_t *as, line_t *l, const char *msg, ...) 236 void lwasm_register_error_n(asmstate_t *as, line_t *l, char *iptr, const char *msg, ...)
237 {
238 va_list args;
239
240 va_start(args, msg);
241
242 lwasm_register_error_real(as, l, iptr, msg, args);
243
244 va_end(args);
245 }
246
247 void lwasm_register_warning_real(asmstate_t *as, line_t *l, char *iptr, const char *msg, va_list args)
227 { 248 {
228 lwasm_error_t *e; 249 lwasm_error_t *e;
229 va_list args;
230 char errbuff[1024]; 250 char errbuff[1024];
231 251
232 if (!l) 252 if (!l)
233 return; 253 return;
234 254
235 va_start(args, msg);
236
237 e = lw_alloc(sizeof(lwasm_error_t)); 255 e = lw_alloc(sizeof(lwasm_error_t));
238 256
239 e -> next = l -> warn; 257 e -> next = l -> warn;
240 l -> warn = e; 258 l -> warn = e;
241 259
260 e -> charpos = -1;
261 if (iptr)
262 e -> charpos = iptr - l -> ltext + 1;
263
242 as -> warningcount++; 264 as -> warningcount++;
243 265
244 (void)vsnprintf(errbuff, 1024, msg, args); 266 (void)vsnprintf(errbuff, 1024, msg, args);
245 e -> mess = lw_strdup(errbuff); 267 e -> mess = lw_strdup(errbuff);
268 }
269
270 void lwasm_register_warning(asmstate_t *as, line_t *l, const char *msg, ...)
271 {
272 va_list args;
273
274 va_start(args, msg);
275
276 lwasm_register_warning_real(as, l, NULL, msg, args);
277
278 va_end(args);
279 }
280
281 void lwasm_register_warning_n(asmstate_t *as, line_t *l, char *iptr, const char *msg, ...)
282 {
283 va_list args;
284
285 va_start(args, msg);
286
287 lwasm_register_warning_real(as, l, iptr, msg, args);
246 288
247 va_end(args); 289 va_end(args);
248 } 290 }
249 291
250 int lwasm_next_context(asmstate_t *as) 292 int lwasm_next_context(asmstate_t *as)