NOT REAL PUSH
This commit is contained in:
parent
5d7d2a82f9
commit
c71e340389
5 changed files with 137 additions and 9 deletions
32
asmTable.c
Normal file
32
asmTable.c
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
#include "asmTable.h"
|
||||||
|
|
||||||
|
int labelCounter = 0;
|
||||||
|
|
||||||
|
/*At the start of the execution : the whole array is empty*/
|
||||||
|
static char** table;
|
||||||
|
static int lineCounter = 0;
|
||||||
|
static int maxIndex = START_TABLE_SIZE;
|
||||||
|
|
||||||
|
|
||||||
|
#include "asmTable.h"
|
||||||
|
|
||||||
|
/* /!\ To be called at the beginning
|
||||||
|
* Initializes the array of Symbols*/
|
||||||
|
void initASMTable(){
|
||||||
|
table = malloc(sizeof(Symbol) * START_TABLE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*resets the symbol table*/
|
||||||
|
void resetASMTable(){
|
||||||
|
currentIndex = 0;
|
||||||
|
maxIndex = START_TABLE_SIZE;
|
||||||
|
|
||||||
|
// stack pointers
|
||||||
|
esp = 0;
|
||||||
|
ebp = 0;
|
||||||
|
|
||||||
|
currentDepth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo inserer parser détecter les labels
|
28
asmTable.h
Normal file
28
asmTable.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Created by chepycou on 4/18/23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H
|
||||||
|
#define PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H
|
||||||
|
|
||||||
|
#define START_TABLE_SIZE 128
|
||||||
|
#define LINE_MAX_LENGTH 50
|
||||||
|
|
||||||
|
/*============================
|
||||||
|
Array and Reallocation
|
||||||
|
============================*/
|
||||||
|
|
||||||
|
/*reallocates the array with the specified size*/
|
||||||
|
void reallocateArray(int size);
|
||||||
|
|
||||||
|
/*Checks for the length of the array and reallocates if necessary*/
|
||||||
|
void checkArraySanity();
|
||||||
|
|
||||||
|
/* /!\ To be called at the beginning
|
||||||
|
* Initializes the array of Symbols*/
|
||||||
|
void initSymbolTable();
|
||||||
|
|
||||||
|
/*resets the symbol table*/
|
||||||
|
void resetSymboltable();
|
||||||
|
|
||||||
|
#endif //PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H
|
47
blocs.c
47
blocs.c
|
@ -3,22 +3,57 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "blocs.h"
|
#include "blocs.h"
|
||||||
|
#include "operations.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*TODO on écrit tout dans un fichier asm extérieur puis on :
|
/*TODO on écrit tout dans un fichier asm extérieur puis on :
|
||||||
* - fait un parcours pour stocker dans une liste chaînée par exemple les valeur de ligne des labels
|
* - fait un parcours pour stocker dans une liste chaînée par exemple les valeur de ligne des labels
|
||||||
* - faire un parcours pour retirer les labels au début des lignes
|
* - faire un parcours pour retirer les labels au début des lignes
|
||||||
* - faire un parcours pour remplacer les labels par leur valeur
|
* - faire un parcours pour remplacer les labels par leur valeur
|
||||||
* */
|
* */
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
int labelCount = 0;
|
int labelCount = 0;
|
||||||
|
|
||||||
char* getNextLabel(){
|
int getNextLabel(){
|
||||||
char label[LABEL_MAX_LENGTH];
|
return(labelCount++);
|
||||||
sprintf(label, "%d_LABEL", labelCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printLabel(int labelWhile){
|
||||||
|
char label[LABEL_MAX_LENGTH];
|
||||||
|
sprintf(label,"%d_LABEL\n",labelWhile);
|
||||||
|
printf("%s",label);
|
||||||
|
FILE* fp;
|
||||||
|
fp = fopen("asm", "a");
|
||||||
|
fputs(label, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int printNewLabel(){
|
||||||
|
int l = getNextLabel();
|
||||||
|
printLabel(l);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printJumpToLabel(int labelWhile) {
|
||||||
|
char instr[ASM_TEXT_LEN];
|
||||||
|
sprintf(instr,"JMP %d_LABEL\n",labelWhile);
|
||||||
|
printf("%s",instr);
|
||||||
|
FILE* fp;
|
||||||
|
fp = fopen("asm", "a");
|
||||||
|
fputs(instr, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printJumpFToLabel(int labelWhile) {
|
||||||
|
char label[LABEL_MAX_LENGTH];
|
||||||
|
sprintf(label,"%d_LABEL\n",labelWhile);
|
||||||
|
printf("JMF %s",label);
|
||||||
|
FILE* fp;
|
||||||
|
fp = fopen("asm", "a");
|
||||||
|
fputs(label, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
16
blocs.h
16
blocs.h
|
@ -5,8 +5,22 @@
|
||||||
#ifndef PROJET_SYSTEMES_INFORMATIQUES_BLOCS_H
|
#ifndef PROJET_SYSTEMES_INFORMATIQUES_BLOCS_H
|
||||||
#define PROJET_SYSTEMES_INFORMATIQUES_BLOCS_H
|
#define PROJET_SYSTEMES_INFORMATIQUES_BLOCS_H
|
||||||
|
|
||||||
int labelCount;
|
|
||||||
#define LABEL_MAX_LENGTH 20
|
#define LABEL_MAX_LENGTH 20
|
||||||
|
|
||||||
|
/*======================
|
||||||
|
Label Management
|
||||||
|
======================*/
|
||||||
|
|
||||||
|
/*returns the next label*/
|
||||||
|
int getNextLabel();
|
||||||
|
|
||||||
|
// prints a new label and returns the index of it
|
||||||
|
int printNewLabel();
|
||||||
|
|
||||||
|
// prints a label and returns the index of it
|
||||||
|
void printLabel(int labelWhile);
|
||||||
|
|
||||||
|
// prints a jump to the label and returns the index of it
|
||||||
|
void printJumpToLabel(int labelWhile);
|
||||||
|
|
||||||
#endif //PROJET_SYSTEMES_INFORMATIQUES_BLOCS_H
|
#endif //PROJET_SYSTEMES_INFORMATIQUES_BLOCS_H
|
||||||
|
|
23
yacc.y
23
yacc.y
|
@ -8,6 +8,8 @@
|
||||||
#include "blocs.h"
|
#include "blocs.h"
|
||||||
|
|
||||||
int t;
|
int t;
|
||||||
|
int labelWhileStart;
|
||||||
|
int labelWhileEnd;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%code provides{
|
%code provides{
|
||||||
|
@ -95,10 +97,22 @@ NumericalOperator : tLE | tGE | tEQ | tNE | tLT | tGT;
|
||||||
Operation: tADD | tMUL | tSUB | tDIV;
|
Operation: tADD | tMUL | tSUB | tDIV;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
IfStatement : tIF Condition InnerBlock
|
IfStatement : tIF Condition {
|
||||||
|
printf(f, « JMPF ???\n ») ;
|
||||||
|
int ligne = get_nb_lignes_asm();
|
||||||
|
$1 = ligne ;
|
||||||
|
}
|
||||||
|
InnerBlock {
|
||||||
|
int current = get_nb_lignes_asm() ; // current == 4
|
||||||
|
patch($1, current + 2) ;
|
||||||
|
int ligne = insert(JMP) ; // ligne == L5
|
||||||
|
$1 = ligne ;
|
||||||
|
}
|
||||||
| tIF Condition InnerBlock tELSE InnerBlock
|
| tIF Condition InnerBlock tELSE InnerBlock
|
||||||
|
|
||||||
WhileStatement : tWHILE Condition InnerBlock;
|
WhileStatement : tWHILE {labelWhileStart = printNewLabel();}
|
||||||
|
Condition InnerBlock {printJumpToLabel(labelWhileStart);
|
||||||
|
labelWhileEnd = printNewLabel();};
|
||||||
|
|
||||||
Assignment : tID tASSIGN Expression tSEMI {
|
Assignment : tID tASSIGN Expression tSEMI {
|
||||||
setInit($1); operation_copy(getOffset($1),$3); suppressTempINTElement();
|
setInit($1); operation_copy(getOffset($1),$3); suppressTempINTElement();
|
||||||
|
@ -160,6 +174,11 @@ void yyerror(const char *msg) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void patch(int from, int to) {
|
||||||
|
/* Mémorisation pour patcher apres la compilation. */
|
||||||
|
labels[from] = to ;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
clearOp();
|
clearOp();
|
||||||
initSymbolTable();
|
initSymbolTable();
|
||||||
|
|
Loading…
Reference in a new issue