added basic asmTable functionalities
This commit is contained in:
parent
c71e340389
commit
86af52f0ac
4 changed files with 36 additions and 18 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ BIN=out
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-Wall -g
|
CFLAGS=-Wall -g
|
||||||
|
|
||||||
OBJ=yacc.tab.o lex.yy.o table.o operations.o blocs.o
|
OBJ=yacc.tab.o lex.yy.o table.o operations.o blocs.o asmTable.o
|
||||||
|
|
||||||
all: $(BIN)
|
all: $(BIN)
|
||||||
@touch testFile # to prevent an error in case of deletion
|
@touch testFile # to prevent an error in case of deletion
|
||||||
|
|
46
asmTable.c
46
asmTable.c
|
@ -1,32 +1,50 @@
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include "asmTable.h"
|
#include "asmTable.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int labelCounter = 0;
|
static int labelCounter = 0;
|
||||||
|
|
||||||
/*At the start of the execution : the whole array is empty*/
|
/*At the start of the execution : the whole array is empty*/
|
||||||
static char** table;
|
static char** asmTable;
|
||||||
static int lineCounter = 0;
|
static int lineCounter = 0;
|
||||||
static int maxIndex = START_TABLE_SIZE;
|
static int maxIndex = START_TABLE_SIZE;
|
||||||
|
|
||||||
|
|
||||||
#include "asmTable.h"
|
#include "asmTable.h"
|
||||||
|
|
||||||
|
/* Error display */
|
||||||
|
void error(char* mess){
|
||||||
|
printf("ERROR : %s\n", mess);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
/* /!\ To be called at the beginning
|
/* /!\ To be called at the beginning
|
||||||
* Initializes the array of Symbols*/
|
* Initializes the array of Symbols*/
|
||||||
void initASMTable(){
|
void initASMTable(){
|
||||||
table = malloc(sizeof(Symbol) * START_TABLE_SIZE);
|
asmTable = malloc(sizeof(char) * LINE_MAX_LENGTH * START_TABLE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*resets the symbol table*/
|
/*Checks for the length of the array and reallocates if necessary*/
|
||||||
void resetASMTable(){
|
void checkArraySanity(){
|
||||||
currentIndex = 0;
|
if (lineCounter == maxIndex){
|
||||||
maxIndex = START_TABLE_SIZE;
|
reallocateArray(maxIndex * 2);
|
||||||
|
}
|
||||||
// stack pointers
|
|
||||||
esp = 0;
|
|
||||||
ebp = 0;
|
|
||||||
|
|
||||||
currentDepth = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo inserer parser détecter les labels
|
/*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++;
|
||||||
|
}
|
||||||
|
|
|
@ -20,9 +20,7 @@ void checkArraySanity();
|
||||||
|
|
||||||
/* /!\ To be called at the beginning
|
/* /!\ To be called at the beginning
|
||||||
* Initializes the array of Symbols*/
|
* Initializes the array of Symbols*/
|
||||||
void initSymbolTable();
|
void initASMTable();
|
||||||
|
|
||||||
/*resets the symbol table*/
|
|
||||||
void resetSymboltable();
|
|
||||||
|
|
||||||
#endif //PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H
|
#endif //PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H
|
||||||
|
|
2
table.h
2
table.h
|
@ -39,6 +39,8 @@ void initSymbolTable();
|
||||||
/*resets the symbol table*/
|
/*resets the symbol table*/
|
||||||
void resetSymboltable();
|
void resetSymboltable();
|
||||||
|
|
||||||
|
void addLine(char* s);
|
||||||
|
|
||||||
|
|
||||||
/*============================
|
/*============================
|
||||||
Element Management
|
Element Management
|
||||||
|
|
Loading…
Reference in a new issue