comparison src/lwasm.c @ 13:05d4115b4860

Started work on new expression evaluator system and major code re-work for next release
author lost
date Wed, 22 Oct 2008 04:51:16 +0000
parents 34568fab6058
children d2e86babd958
comparison
equal deleted inserted replaced
5:287a6905a63c 13:05d4115b4860
421 { 421 {
422 resolve_insn(as, cl); 422 resolve_insn(as, cl);
423 } 423 }
424 } 424 }
425 425
426 void lwasm_read_file(asmstate_t *as, char *fname)
427 {
428 FILE *f;
429 int cline = 0;
430 sourceline_t *cl;
431 size_t bufflen;
432 char *buff = NULL;
433 int retval;
434
435 as -> passnum = 1;
436
437 f = fopen(fname, "r");
438 if (!f)
439 {
440 fprintf(stderr, "Cannot open input file %s: %s\n", fname, strerror(errno));
441 return;
442 }
443
444 while (!feof(f))
445 {
446 retval = getline(&buff, &bufflen, f);
447 debug(" read line (%s:%d): %s\n", fname, cline, buff);
448 if (retval < 0)
449 {
450 if (feof(f))
451 break;
452 fprintf(stderr, "Error reading '%s': %s\n", fname, strerror(errno));
453 exit(1);
454 }
455 if (strchr(buff, '\n'))
456 *strchr(buff, '\n') = '\0';
457 if (strchr(buff, '\r'))
458 *strchr(buff, '\r') = '\0';
459 cl = calloc(sizeof(sourceline_t), 1);
460 if (!cl)
461 {
462 perror("Malloc");
463 exit(1);
464 }
465
466 cl -> lineno = cline++;
467 cl -> sourcefile = fname;
468 cl -> opcode = -1;
469 cl -> addrmode = -1;
470 cl -> addr = as -> addr;
471 cl -> dpval = as -> dpval;
472 cl -> prev = as -> source_tail;
473 if (as -> source_tail)
474 as -> source_tail -> next = cl;
475 as -> source_tail = cl;
476 if (as -> source_head == NULL)
477 as -> source_head = cl;
478 cl -> line = strdup(buff);
479
480 resolve_insn(as, cl);
481
482 if (cl -> opcode >= 0 && instab[cl -> opcode].instype == INSTYPE_PSEUDO && instab[cl -> opcode].specialnum == SPECIAL_END)
483 break;
484
485 *buff = '\0';
486
487 }
488 if (buff)
489 free(buff);
490
491 fclose(f);
492
493 return;
494 }
495 426
496 /* 427 /*
497 below this point is the expression evaluation package 428 below this point is the expression evaluation package
498 429
499 Supported binary operators: + - / * % 430 Supported binary operators: + - / * %