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
|
||||
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)
|
||||
@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 "stdlib.h"
|
||||
#include <string.h>
|
||||
|
||||
int labelCounter = 0;
|
||||
static int labelCounter = 0;
|
||||
|
||||
/*At the start of the execution : the whole array is empty*/
|
||||
static char** table;
|
||||
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(){
|
||||
table = malloc(sizeof(Symbol) * START_TABLE_SIZE);
|
||||
asmTable = malloc(sizeof(char) * LINE_MAX_LENGTH * START_TABLE_SIZE);
|
||||
}
|
||||
|
||||
/*resets the symbol table*/
|
||||
void resetASMTable(){
|
||||
currentIndex = 0;
|
||||
maxIndex = START_TABLE_SIZE;
|
||||
|
||||
// stack pointers
|
||||
esp = 0;
|
||||
ebp = 0;
|
||||
|
||||
currentDepth = 0;
|
||||
/*Checks for the length of the array and reallocates if necessary*/
|
||||
void checkArraySanity(){
|
||||
if (lineCounter == maxIndex){
|
||||
reallocateArray(maxIndex * 2);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
* Initializes the array of Symbols*/
|
||||
void initSymbolTable();
|
||||
void initASMTable();
|
||||
|
||||
/*resets the symbol table*/
|
||||
void resetSymboltable();
|
||||
|
||||
#endif //PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H
|
||||
|
|
2
table.h
2
table.h
|
@ -39,6 +39,8 @@ void initSymbolTable();
|
|||
/*resets the symbol table*/
|
||||
void resetSymboltable();
|
||||
|
||||
void addLine(char* s);
|
||||
|
||||
|
||||
/*============================
|
||||
Element Management
|
||||
|
|
Loading…
Reference in a new issue