77 lines
No EOL
1.8 KiB
C
77 lines
No EOL
1.8 KiB
C
|
|
#include <stdio.h>
|
|
#include "asmTable.h"
|
|
#include "stdlib.h"
|
|
#include <string.h>
|
|
|
|
/*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"
|
|
#include "table.h"
|
|
|
|
/* /!\ 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 checkASMArraySanity(){
|
|
if (lineCounter == maxIndex){
|
|
reallocateASMArray(maxIndex * 2);
|
|
}
|
|
}
|
|
|
|
/*reallocates the array with the specified size*/
|
|
void reallocateASMArray(int size){
|
|
ASMLine *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 = -1;
|
|
lineCounter++;
|
|
checkASMArraySanity();
|
|
displayASMTable();
|
|
}
|
|
|
|
/*inserts the address in case of jumps*/
|
|
void setJumpLine(int index, int addr) {
|
|
asmTable[index].jumpLine = addr;
|
|
printf("\n%d aaaaa %d\n",index,addr);
|
|
displayASMTable();
|
|
}
|
|
|
|
/*returns the current line (i.e. next one to insert)*/
|
|
int getCurrentLineNumber() {
|
|
return lineCounter;
|
|
}
|
|
|
|
/*displays the entire table at this moment*/
|
|
void displayASMTable(){
|
|
printf("\n");
|
|
doubleLine();
|
|
for (int i = 0; i < lineCounter; ++i) {
|
|
ASMLine a = asmTable[i];
|
|
if(a.jumpLine == -1) {
|
|
printf("%d | %s", i, a.name);
|
|
} else {
|
|
printf("%d | %s %d\n", i, a.name,a.jumpLine);
|
|
}
|
|
if (i != lineCounter -1) {
|
|
line();
|
|
}
|
|
}
|
|
doubleLine();
|
|
} |