Added code to detect assembler directives and did some minor code clean up.

This commit is contained in:
2022-02-01 22:07:00 -06:00
parent ebc1d30c1c
commit 7a88d6e34d
5 changed files with 17 additions and 127 deletions
+2 -114
View File
@@ -20,118 +20,6 @@ int main(int argc, char* args[]) {
printf("Input files required.\n");
return -1;
}
// char* test = "user_id";
// printf("Key for '%s' is %d for size %d\n", test, GetKeyIndex(test, HASHTABLEDEFAULTSIZE), HASHTABLEDEFAULTSIZE);
GenerateTokensFromFile(args[1]);
// for (int i = 1; i < argc; i++) {
// input_files[i - 1] = args[i];
// print_file(args[i]);
// }
//print_file(args[1]);
// struct test {
// int SomeValue;
// char* SomeText;
// };
// struct test* thing = malloc(sizeof(struct test));
// thing->SomeText = calloc(1, 16);
// List *list = CreateList();
// for (int i = 0; i < 64; i++) {
// sprintf(thing->SomeText, "%d", i);
// thing->SomeValue = i;
// AddListItem(thing, sizeof(struct test), list);
// if (i % 4 == 0) printf("Size: %d; Capacity: %d\n", list->size, list->capacity);
// printf("Some Value: %d Some Text: '%s'\n", ((struct test*) list->content[list->size - 1])->SomeValue, ((struct test*) list->content[list->size - 1])->SomeText);
// }
// //PrintList(list);
// free(thing->SomeText);
// free(thing);
//free(list);
}
// void print_file(char* file_path) {
// FILE *file;
// char* line = NULL;
// size_t len = 0;
// ssize_t bytes_read;
// file = fopen(file_path, "r");
// if (!file) {
// printf("Failed to open '%s' for reading.\n", file_path);
// return;
// }
// while((bytes_read = getline(&line, &len, file)) != -1) {
// List* list = get_strings(line);
// if (!list) continue;
// if (list->size == 0) continue;
// // Instruction *inst = malloc(sizeof(Instruction));
// // inst->parameters = malloc(sizeof(char*) * 2);
// // if (strcmp(list->root[0], "mov") == 0) {
// // inst->opcode = "mov";
// // inst->count = 2;
// // inst->parameters[0] = list->root[1];
// // inst->parameters[1] = list->root[2];
// // printf("Instruction '%s' with %d params ('%s', '%s')\n", inst->opcode, inst->count, inst->parameters[0], inst->parameters[1]);
// // }
// // free(inst->parameters);
// // free(inst);
// //PrintList(list);
// DestroyList(list);
// }
// fclose(file);
// if (line) free(line);
// }
// List* get_strings(const char* line) {
// if (strlen(line) == 0 ) return NULL;
// if (line[0] == ';') return NULL; //If the line starts with a semi-colon its just a comment, so ignore it.
// List *list = CreateList();
// unsigned long lineLength = strlen(line);
// char* currentWord = malloc(lineLength + 1);
// int index = 0;
// for (int i = 0; i < lineLength; i++) {
// if (line[i] == ' ' || line[i] == ',') {
// if (index > 0) {
// currentWord[index] = '\0';
// PushListItem(currentWord, strlen(currentWord) + 1, list);
// }
// index = 0;
// continue;
// }
// if (line[i] == ';' || i + 1 == lineLength) {
// if (index > 0) {
// if (line[i] != ';') {
// currentWord[index] = line[i];
// index++;
// }
// currentWord[index] = '\0';
// PushListItem(currentWord, strlen(currentWord) + 1, list);
// }
// break;
// }
// currentWord[index] = line[i];
// index++;
// }
// return list;
// }
GenerateTokensFromFile(args[1]);
}