comparison lwasm/output.c @ 387:a741d2e4869f

Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
author lost@l-w.ca
date Wed, 14 Jul 2010 20:15:23 -0600
parents 55ed7d06b136
children c94436adce83
comparison
equal deleted inserted replaced
386:af5f2c51db76 387:a741d2e4869f
241 241
242 switch (tt) 242 switch (tt)
243 { 243 {
244 case lw_expr_type_oper: 244 case lw_expr_type_oper:
245 buf[0] = 0x04; 245 buf[0] = 0x04;
246 switch (lw_expr_intval(e)) 246 switch (lw_expr_whichop(e))
247 { 247 {
248 case lw_expr_oper_plus: 248 case lw_expr_oper_plus:
249 buf[1] = 0x01; 249 buf[1] = 0x01;
250 break; 250 break;
251 251
299 299
300 default: 300 default:
301 buf[1] = 0xff; 301 buf[1] = 0xff;
302 } 302 }
303 writebytes(buf, 2, 1, of); 303 writebytes(buf, 2, 1, of);
304 break; 304 return 0;
305 305
306 case lw_expr_type_int: 306 case lw_expr_type_int:
307 v = lw_expr_intval(e); 307 v = lw_expr_intval(e);
308 buf[0] = 0x01; 308 buf[0] = 0x01;
309 buf[1] = (v >> 8) & 0xff; 309 buf[1] = (v >> 8) & 0xff;
310 buf[2] = v & 0xff; 310 buf[2] = v & 0xff;
311 writebytes(buf, 3, 1, of); 311 writebytes(buf, 3, 1, of);
312 break; 312 return 0;
313 313
314 case lw_expr_type_special: 314 case lw_expr_type_special:
315 v = lw_expr_specint(e); 315 v = lw_expr_specint(e);
316 switch (v) 316 switch (v)
317 { 317 {
319 { 319 {
320 // replaced with a synthetic symbol 320 // replaced with a synthetic symbol
321 sectiontab_t *se; 321 sectiontab_t *se;
322 se = lw_expr_specptr(e); 322 se = lw_expr_specptr(e);
323 323
324 writebytes("\x03\x02", 1, 1, of); 324 writebytes("\x03\x02", 2, 1, of);
325 writebytes(se -> name, strlen(se -> name) + 1, 1, of); 325 writebytes(se -> name, strlen(se -> name) + 1, 1, of);
326 break; 326 return 0;
327 } 327 }
328 case lwasm_expr_import: 328 case lwasm_expr_import:
329 { 329 {
330 importlist_t *ie; 330 importlist_t *ie;
331 ie = lw_expr_specptr(e); 331 ie = lw_expr_specptr(e);
332 buf[0] = 0x02; 332 buf[0] = 0x02;
333 writebytes(buf, 1, 1, of); 333 writebytes(buf, 1, 1, of);
334 writebytes(ie -> symbol, strlen(ie -> symbol) + 1, 1, of); 334 writebytes(ie -> symbol, strlen(ie -> symbol) + 1, 1, of);
335 break; 335 return 0;
336 } 336 }
337 case lwasm_expr_syment: 337 case lwasm_expr_syment:
338 { 338 {
339 struct symtabe *se; 339 struct symtabe *se;
340 se = lw_expr_specptr(e); 340 se = lw_expr_specptr(e);
345 { 345 {
346 sprintf(buf, "\x01%d", se -> context); 346 sprintf(buf, "\x01%d", se -> context);
347 writebytes(buf, strlen(buf), 1, of); 347 writebytes(buf, strlen(buf), 1, of);
348 } 348 }
349 writebytes("", 1, 1, of); 349 writebytes("", 1, 1, of);
350 break; 350 return 0;
351 } 351 }
352 break;
353 } 352 }
354 353
355 default: 354 default:
356 // unrecognized term type - replace with integer 0 355 // unrecognized term type - replace with integer 0
356 // fprintf(stderr, "Unrecognized term type: %s\n", lw_expr_print(e));
357 buf[0] = 0x01; 357 buf[0] = 0x01;
358 buf[1] = 0x00; 358 buf[1] = 0x00;
359 buf[2] = 0x00; 359 buf[2] = 0x00;
360 writebytes(buf, 3, 1, of); 360 writebytes(buf, 3, 1, of);
361 break; 361 break;
406 { 406 {
407 // we're in a section - need to output some bytes 407 // we're in a section - need to output some bytes
408 if (l -> outputl > 0) 408 if (l -> outputl > 0)
409 for (i = 0; i < l -> outputl; i++) 409 for (i = 0; i < l -> outputl; i++)
410 write_code_obj_sbadd(l -> csect, l -> output[i]); 410 write_code_obj_sbadd(l -> csect, l -> output[i]);
411 else if (l -> outputl == 0) 411 else if (l -> outputl == 0 || l -> outputl == -1)
412 for (i = 0; i < l -> len; i++) 412 for (i = 0; i < l -> len; i++)
413 write_code_obj_sbadd(l -> csect, 0); 413 write_code_obj_sbadd(l -> csect, 0);
414 } 414 }
415 } 415 }
416 416
430 // now the local symbols 430 // now the local symbols
431 431
432 // a symbol for section base address 432 // a symbol for section base address
433 writebytes("\x02", 1, 1, of); 433 writebytes("\x02", 1, 1, of);
434 writebytes(s -> name, strlen(s -> name) + 1, 1, of); 434 writebytes(s -> name, strlen(s -> name) + 1, 1, of);
435 // address 0; "\0" is not an error
436 writebytes("\0", 2, 1, of);
435 for (se = as -> symtab.head; se; se = se -> next) 437 for (se = as -> symtab.head; se; se = se -> next)
436 { 438 {
437 // ignore symbols not in this section 439 // ignore symbols not in this section
438 if (se -> section != s) 440 if (se -> section != s)
439 continue; 441 continue;
523 buf[0] = 0xFF; 525 buf[0] = 0xFF;
524 buf[1] = 0x01; 526 buf[1] = 0x01;
525 writebytes(buf, 2, 1, of); 527 writebytes(buf, 2, 1, of);
526 } 528 }
527 529
528 te = lw_expr_copy(ex -> se -> value); 530 te = lw_expr_copy(re -> offset);
529 lwasm_reduce_expr(as, te); 531 lwasm_reduce_expr(as, te);
530 if (!lw_expr_istype(te, lw_expr_type_int)) 532 if (!lw_expr_istype(te, lw_expr_type_int))
531 { 533 {
532 lw_expr_destroy(te); 534 lw_expr_destroy(te);
533 continue; 535 continue;