projet_systeme/table_symboles.h

95 lines
2.3 KiB
C
Raw Normal View History

2021-03-31 21:08:45 +02:00
#ifndef TABLE_SYMBOLES_H
#define TABLE_SYMBOLES_H
2021-05-09 19:55:27 +02:00
#define TABLE_SIZE 256
#define VARIABLE_SIZE 30
2021-03-31 21:08:45 +02:00
2021-04-30 17:08:29 +02:00
enum Symbole_Type {TYPE_INT , TYPE_CONST_INT, TYPE_INT_PTR};
2021-03-31 21:08:45 +02:00
enum Initialised_Variable{INITIALISED , NOT_INITIALISED};
typedef struct Symboles {
char Variable_Name[VARIABLE_SIZE];
2021-03-31 21:08:45 +02:00
int addr ;
enum Symbole_Type type;
enum Initialised_Variable init;
int symbole_depth;
2021-03-31 21:08:45 +02:00
} Symbole;
typedef struct Table_Symboles {
Symbole array[TABLE_SIZE];
int indexAvailableTop;
int indexAvailableBottom;
int depth;
2021-03-31 21:08:45 +02:00
} Table_Symboles;
/**
* Initialises indexAvailableTop at 0 and indexAvailableBottom at TABLE_SIZE - 1
* @param table
*/
void initialise_table(Table_Symboles * table);
/**
* Adds a symbole at the top (regular varaibles)
* @param table
* @param varName
* @param type
* @param init
* @return if symbole added successfully, -1 if the table is full and -2 if the varaible already exists in the table
*/
int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type , enum Initialised_Variable init, int depth);
2021-03-31 21:08:45 +02:00
/**
* Adds a symbole at the bottom (temp variables)
* @param table
* @return 0 if symbole added successfully, -1 if the table is full and -2 if the varaible already exists in the table
*/
2021-04-06 18:22:31 +02:00
int add_symbole_bottom(Table_Symboles * table);
2021-03-31 21:08:45 +02:00
/**
* Verifies if a varaible name is already present in the table to avoid duplicates
* @param table
* @param varName
* @return -1 if the varaible name exists, 0 if it doesn't
*/
int variable_exists(Table_Symboles * table, char * varName);
/**
* Removes symbole from table having certain depth
* @param table
* @return -1 if the symbole isn't in the table, 0 otherwise
*/
2021-04-30 17:08:29 +02:00
int remove_symboles(Table_Symboles * table);
2021-04-06 18:22:31 +02:00
void free_temp(Table_Symboles * table);
2021-04-30 17:08:29 +02:00
int prepare_function_call(Table_Symboles * table);
int prepare_argument_push(Table_Symboles * table);
/**
* Initialises an already exisiting symbole
* @param table
* @param varName
* @return -1 if the symbole isn't in the table, 0 otherwise
*/
int initialise_symbole(Table_Symboles * table, char * varName);
2021-03-31 21:08:45 +02:00
/**
* Prints a symbole with this format
* varName | Type | Address | Initialised/Not_Initialised
* @param symbole
*/
void print_symbole(Symbole * symbole);
/**
* Prints the table
* @param table
*/
void print_table(Table_Symboles * table);
#endif