comparison lwasm/section.c @ 370:8764142b3192

Convert internal error/warning handling framework to a new unified system Replace the ad hoc error and warning handling with a new system that codifies the errors with specific codes. This makes it possible in the future for error numbers to be used for testing and other purposes. It also makes sure the error strings themselves are consistent. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 22 Jun 2015 18:49:38 -0600
parents 35f7ce3ef857
children 58cafa61ab40
comparison
equal deleted inserted replaced
369:682524a1f32f 370:8764142b3192
35 char *opts = NULL; 35 char *opts = NULL;
36 sectiontab_t *s; 36 sectiontab_t *s;
37 37
38 if (as -> output_format != OUTPUT_OBJ) 38 if (as -> output_format != OUTPUT_OBJ)
39 { 39 {
40 lwasm_register_error(as, l, "Cannot use sections unless using the object target"); 40 lwasm_register_error(as, l, E_SECTION_TARGET);
41 return; 41 return;
42 } 42 }
43 43
44 if (!**p) 44 if (!**p)
45 { 45 {
46 lwasm_register_error(as, l, "Need section name"); 46 lwasm_register_error(as, l, E_SECTION_NAME);
47 return; 47 return;
48 } 48 }
49 49
50 l -> len = 0; 50 l -> len = 0;
51 51
79 if (!strcmp(s -> name, sn)) 79 if (!strcmp(s -> name, sn))
80 break; 80 break;
81 } 81 }
82 if (s && opts) 82 if (s && opts)
83 { 83 {
84 lwasm_register_warning(as, l, "Section flags can only be specified the first time; ignoring duplicate definition"); 84 lwasm_register_error(as, l, W_DUPLICATE_SECTION);
85 } 85 }
86 if (!s) 86 if (!s)
87 { 87 {
88 // create section data structure 88 // create section data structure
89 s = lw_alloc(sizeof(sectiontab_t)); 89 s = lw_alloc(sizeof(sectiontab_t));
123 { 123 {
124 s -> flags |= section_flag_constant; 124 s -> flags |= section_flag_constant;
125 } 125 }
126 else 126 else
127 { 127 {
128 lwasm_register_error(as, l, "Unrecognized section flag"); 128 lwasm_register_error(as, l, E_SECTION_FLAG);
129 lw_free(sn); 129 lw_free(sn);
130 lw_free(opts); 130 lw_free(opts);
131 lw_free(s -> name); 131 lw_free(s -> name);
132 lw_expr_destroy(s -> offset); 132 lw_expr_destroy(s -> offset);
133 lw_free(s); 133 lw_free(s);
156 156
157 PARSEFUNC(pseudo_parse_endsection) 157 PARSEFUNC(pseudo_parse_endsection)
158 { 158 {
159 if (as -> output_format != OUTPUT_OBJ) 159 if (as -> output_format != OUTPUT_OBJ)
160 { 160 {
161 lwasm_register_error(as, l, "Cannot use sections unless using the object target"); 161 lwasm_register_error(as, l, E_SECTION_TARGET);
162 return; 162 return;
163 } 163 }
164 164
165 l -> len = 0; 165 l -> len = 0;
166 166
167 if (!(as -> csect)) 167 if (!(as -> csect))
168 { 168 {
169 lwasm_register_error(as, l, "ENDSECTION without SECTION"); 169 lwasm_register_error(as, l, E_SECTION_END);
170 return; 170 return;
171 } 171 }
172 172
173 // save offset in case another instance of the section appears 173 // save offset in case another instance of the section appears
174 lw_expr_destroy(as -> csect -> offset); 174 lw_expr_destroy(as -> csect -> offset);
190 char *sym = NULL; 190 char *sym = NULL;
191 exportlist_t *e; 191 exportlist_t *e;
192 192
193 if (as -> output_format != OUTPUT_OBJ) 193 if (as -> output_format != OUTPUT_OBJ)
194 { 194 {
195 lwasm_register_error(as, l, "EXPORT only supported for object target"); 195 lwasm_register_error2(as, l, E_OBJTARGET_ONLY, "(%s)", "EXPORT");
196 return; 196 return;
197 } 197 }
198 198
199 l -> len = 0; 199 l -> len = 0;
200 200
221 sym = lw_strndup(*p, p2 - *p); 221 sym = lw_strndup(*p, p2 - *p);
222 *p = p2; 222 *p = p2;
223 } 223 }
224 if (!sym) 224 if (!sym)
225 { 225 {
226 lwasm_register_error(as, l, "No symbol for EXPORT"); 226 lwasm_register_error2(as, l, E_SYMBOL_MISSING, "for %s", "EXPORT");
227 return; 227 return;
228 } 228 }
229 229
230 // add the symbol to the "export" list (which will be resolved 230 // add the symbol to the "export" list (which will be resolved
231 // after the parse pass is complete 231 // after the parse pass is complete
252 char *sym = NULL; 252 char *sym = NULL;
253 importlist_t *e; 253 importlist_t *e;
254 254
255 if (as -> output_format != OUTPUT_OBJ) 255 if (as -> output_format != OUTPUT_OBJ)
256 { 256 {
257 lwasm_register_error(as, l, "IMPORT only supported for object target"); 257 lwasm_register_error2(as, l, E_OBJTARGET_ONLY, "(%s)", "IMPORT");
258 return; 258 return;
259 } 259 }
260 260
261 l -> len = 0; 261 l -> len = 0;
262 262
283 sym = lw_strndup(*p, p2 - *p); 283 sym = lw_strndup(*p, p2 - *p);
284 *p = p2; 284 *p = p2;
285 } 285 }
286 if (!sym) 286 if (!sym)
287 { 287 {
288 lwasm_register_error(as, l, "No symbol for IMPORT"); 288 lwasm_register_error2(as, l, E_SYMBOL_MISSING, "for %s", "IMPORT");
289 return; 289 return;
290 } 290 }
291 291
292 // add the symbol to the "export" list (which will be resolved 292 // add the symbol to the "export" list (which will be resolved
293 // after the parse pass is complete 293 // after the parse pass is complete
312 char *sym = NULL; 312 char *sym = NULL;
313 // importlist_t *e; 313 // importlist_t *e;
314 314
315 if (as -> output_format != OUTPUT_OBJ) 315 if (as -> output_format != OUTPUT_OBJ)
316 { 316 {
317 lwasm_register_error(as, l, "EXTDEP only supported for object target"); 317 lwasm_register_error2(as, l, E_OBJTARGET_ONLY, "(%s)", "EXTDEP");
318 return; 318 return;
319 } 319 }
320 320
321 if (!as -> csect) 321 if (!as -> csect)
322 { 322 {
323 lwasm_register_error(as, l, "EXTDEP must be within a section"); 323 lwasm_register_error(as, l, E_SECTION_EXTDEP);
324 return; 324 return;
325 } 325 }
326 326
327 l -> len = 0; 327 l -> len = 0;
328 328
345 345
346 sym = lw_strndup(*p, p2 - *p); 346 sym = lw_strndup(*p, p2 - *p);
347 } 347 }
348 if (!sym) 348 if (!sym)
349 { 349 {
350 lwasm_register_error(as, l, "No symbol for EXTDEP"); 350 lwasm_register_error2(as, l, E_SYMBOL_MISSING, "for %s", "EXTDEP");
351 return; 351 return;
352 } 352 }
353 353
354 // create a zero-width dependency 354 // create a zero-width dependency
355 { 355 {