Files
assm-test/src/main.c
T

52 lines
1.3 KiB
C

#include <bits/types/FILE.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sysexits.h>
#include "../includes/list.h"
#include "../includes/parser.h"
#include "../includes/futil.h"
#include "../includes/scanner.h"
#include "../includes/disass.h"
int main(int argc, char* args[]) {
if (argc == 1) {
printf("Usage: assm <file1.asm>\n");
return EX_USAGE;
}
char* source_code;
size_t bytes_read;
if (!ReadAllString(args[1], &source_code, &bytes_read)) return EX_IOERR;
List* list = GenerateTokenList(source_code);
// for(int i = 0; i < list->size; i++) {
// Token* t = (Token*) list->content[i];
// if (t->type == LineEnd) {
// if (i - 1 >= 0 && ((Token*) list->content[i - 1])->type != LineEnd)
// printf("\n");
// continue;
// }
// printf("[T: %i][C: %i] '%s' ", t->type, t->token_class, t->lexeme);
// if (t->type == LABEL) printf("* ");
// }
IRState* image = ParseTokens(list);
//Disassemble(image);
for(int i = 0; i < image->Opcodes->size; i++) {
printf("%d\n", ((IROpcode*) image->Opcodes->content[i])->Mnemonic);
}
//FILE* program = fopen("program.bin", "w+b");
//fwrite(image, 1, image[2] + image[3], program);
//fclose(program);
free(source_code);
}