Projet-Systemes-Informatiques/asmTable.c
2023-04-18 16:27:50 +02:00

50 lines
1.1 KiB
C

#include <stdio.h>
#include "asmTable.h"
#include "stdlib.h"
#include <string.h>
static int labelCounter = 0;
/*At the start of the execution : the whole array is empty*/
static char** asmTable;
static int lineCounter = 0;
static int maxIndex = START_TABLE_SIZE;
#include "asmTable.h"
/* Error display */
void error(char* mess){
printf("ERROR : %s\n", mess);
exit(-1);
}
/* /!\ To be called at the beginning
* Initializes the array of Symbols*/
void initASMTable(){
asmTable = malloc(sizeof(char) * LINE_MAX_LENGTH * START_TABLE_SIZE);
}
/*Checks for the length of the array and reallocates if necessary*/
void checkArraySanity(){
if (lineCounter == maxIndex){
reallocateArray(maxIndex * 2);
}
}
/*reallocates the array with the specified size*/
void reallocateArray(int size){
char **temp = (char **)realloc(asmTable, (sizeof(char) * LINE_MAX_LENGTH * size));
if (temp != NULL){
asmTable = temp;
}
else {
error("Cannot allocate more memory.\n");
}
}
void addLine(char* s) {
strcpy(asmTable[lineCounter],s);
lineCounter++;
}