comparison lwasm/unicorns.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 3864d96ee8c7
children 042c7b74faf0
comparison
equal deleted inserted replaced
225:823560a8c251 226:7c2c2239ec9c
44 fputc(*string, stream); 44 fputc(*string, stream);
45 } 45 }
46 } 46 }
47 } 47 }
48 48
49 static void show_unicorn_error(FILE *fp, line_t *l, lwasm_error_t *ee, const char *tag)
50 {
51 fprintf(fp, "%s: lineno=%d,filename=", tag, l -> lineno);
52 print_urlencoding(fp, l -> linespec);
53 fputs(",message=", fp);
54 print_urlencoding(fp, ee -> mess);
55 if (ee -> charpos > 0)
56 fprintf(fp, ",col=%d", ee -> charpos);
57 fputc('\n', fp);
58 }
59
49 void lwasm_do_unicorns(asmstate_t *as) 60 void lwasm_do_unicorns(asmstate_t *as)
50 { 61 {
51 struct ifl *ifl; 62 struct ifl *ifl;
52 macrotab_t *me; 63 macrotab_t *me;
53 structtab_t *se; 64 structtab_t *se;
54 int i; 65 int i;
66 line_t *l;
67 lwasm_error_t *ee;
55 68
56 /* output file list */ 69 /* output file list */
57 for (ifl = ifl_head; ifl; ifl = ifl -> next) 70 for (ifl = ifl_head; ifl; ifl = ifl -> next)
58 { 71 {
59 fputs("RESOURCE: type=file,filename=", stdout); 72 fputs("RESOURCE: type=file,filename=", stdout);
84 { 97 {
85 fprintf(stdout, "RESOURCE: type=struct,name=%s,lineno=%d,filename=", se -> name, se -> definedat -> lineno); 98 fprintf(stdout, "RESOURCE: type=struct,name=%s,lineno=%d,filename=", se -> name, se -> definedat -> lineno);
86 print_urlencoding(stdout, se -> definedat -> linespec); 99 print_urlencoding(stdout, se -> definedat -> linespec);
87 fputc('\n', stdout); 100 fputc('\n', stdout);
88 } 101 }
89 102
103 /* output error and warning lists */
104 for (l = as -> line_head; l; l = l -> next)
105 {
106 if (l -> err)
107 {
108 for (ee = l -> err; ee; ee = ee -> next)
109 {
110 show_unicorn_error(stdout, l, ee, "ERROR");
111 }
112 }
113
114 if (l -> warn)
115 {
116 for (ee = l -> warn; ee; ee = ee -> next)
117 {
118 show_unicorn_error(stdout, l, ee, "WARNING");
119 }
120 }
121 }
90 } 122 }