#include #include "asmTable.h" #include "stdlib.h" #include static int labelCounter = 0; /*At the start of the execution : the whole array is empty*/ static ASMLine* 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(ASMLine) * 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 = (ASMLine*) realloc(asmTable, (sizeof(ASMLine) * size)); if (temp != NULL){ asmTable = temp; } else { error("Cannot allocate more memory.\n"); } } /*inserts an asm code line at the current index*/ void addLine(char* s) { strcpy(asmTable[lineCounter].name,s); asmTable[lineCounter].jumpLine; lineCounter++; } /*returns the current line (i.e. next one to insert)*/ int getCurrentLineNumber() { return lineCounter; }