~rabbits/lin6

3fd0b16f7f7aac1653a7bf398e011b460fe5810b — Devine Lu Linvega 4 years ago 379fabd
Fixed issue with directives
2 files changed, 15 insertions(+), 20 deletions(-)

M lin6.c
M source.asm
M lin6.c => lin6.c +14 -19
@@ 30,7 30,7 @@
#include <string.h>

#define VERSION "1.1"
#define BUFLEN 256
#define BUFLEN 512

char *OPCODES[] = {"ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI",
                   "BNE", "BPL", "BRK", "BVC", "BVS", "CLC", "CLD", "CLI",


@@ 202,6 202,9 @@ bool is_upper(char *str) {
bool is_label(char *line) {
  int i, len = strlen(line);
  for (i = 0; i < len; i++) {
    if (line[i] == ' ' || line[i] == ';') {
      return false;
    }
    if (line[i] == ':') {
      return true;
    }


@@ 275,10 278,8 @@ void lint(char *filepath, char *output, bool do_debug) {
      set_line_key(trimed, key);
      set_line_comment(trimed, comment);
      if (!is_capital(key)) {
        printf("Error: Label %s is not capitalized, at %s:%d.\n", key, filepath,
        printf("Lin6: Label %s not capitalized, at %s:%d.\n", key, filepath,
               id);
        fclose(fr);
        exit(0);
      }
      if (key[0] != '@' && !skipped_last) {
        strcat(output, "\n");


@@ 325,7 326,6 @@ void lint(char *filepath, char *output, bool do_debug) {
      strcat(output, key);
      strcat(output, " ");
      if (has_comment(line)) {
        fillstr(value, 22, ' ');
        strcat(output, value);
        strcat(output, " ");
        strcat(output, comment);


@@ 354,10 354,8 @@ void lint(char *filepath, char *output, bool do_debug) {
      set_line_comment(trimed, comment);
      fillstr(key, 24, ' ');
      if (!is_lower(key)) {
        printf("Error: Variable %s is not lowercase, at %s:%d.\n", key,
               filepath, id);
        fclose(fr);
        exit(0);
        printf("Lin6: Variable %s not lowercase, at %s:%d.\n", key, filepath,
               id);
      }
      strcat(output, key);
      strcat(output, value);


@@ 374,10 372,8 @@ void lint(char *filepath, char *output, bool do_debug) {
      set_line_comment(trimed, comment);
      fillstr(key, 20, ' ');
      if (!is_upper(key)) {
        printf("Error: Constant %s is not uppercase, at %s:%d.\n", key,
               filepath, id);
        fclose(fr);
        exit(0);
        printf("Lin6: Constant %s not uppercase, at %s:%d.\n", key, filepath,
               id);
      }
      strcat(output, key);
      strcat(output, value);


@@ 386,15 382,14 @@ void lint(char *filepath, char *output, bool do_debug) {
      skipped_last = false;
      constants++;
    } else {
      printf("Error: Unknown line-type, at %s:%d.\n", filepath, id);
      fclose(fr);
      exit(0);
      printf("Lin6: Unknown line-type, at %s:%d.\n", filepath, id);
      strcat(output, line);
    }
    strcat(output, "\n");
    count++;
  }
  if (do_debug) {
    printf("Linted %d lines: \n", count);
    printf("Lin6 debug: %d lines: \n", count);
    printf("\t%d labels\n", labels);
    printf("\t%d opcodes\n", opcodes);
    printf("\t%d directives\n", directives);


@@ 442,9 437,9 @@ int main(int argc, char *argv[]) {
    }
    /* do files */
    else {
      char linted[32768];
      char linted[51200];
      if (!file_exists(argv[i])) {
        printf("Error! File %s not found\n", argv[i]);
        printf("Lin6: File %s not found\n", argv[i]);
        exit(0);
      }
      lint(argv[i], linted, do_debug);

M source.asm => source.asm +1 -1
@@ 1,7 1,7 @@

;; Variables

	.enum $0000                  ; Directive comment
	.enum $0000 ; Directive comment
pos_x                   .dsb 1 ; Variable comment
pos_y                   .dsb 1 
	.ende