From 271309e831b3acb27ffef14878179bc27cbfe1f3 Mon Sep 17 00:00:00 2001 From: Nahom Date: Fri, 14 May 2021 16:35:26 +0200 Subject: [PATCH] =?UTF-8?q?r=C3=A9organisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 8196 -> 10244 bytes .idea/projet_systeme.iml | 2 +- analyse_lexicale.lex | 106 ------- analyse_syntaxique.y | 230 -------------- cross_assembleur/.DS_Store | Bin 0 -> 6148 bytes cross_assembleur/STD_LOGIC_VECTOR_output | 1 + cross_assembleur/cross_input.txt | 3 + cross_assembleur/cross_output.txt | 10 + cross_assembleur/main.py | 36 +++ cross_assembleur/makefile | 17 ++ cross_assembleur/src/.DS_Store | Bin 0 -> 6148 bytes cross_assembleur/src/cross.l | 32 ++ cross_assembleur/src/cross.y | 88 ++++++ cross_assembleur/src/cross_instructions.c | 23 ++ cross_assembleur/src/cross_instructions.h | 33 ++ gen_assembleur.c | 357 ---------------------- gen_assembleur.h | 121 -------- instructions.txt | 26 -- interpreter/.DS_Store | Bin 6148 -> 6148 bytes interpreter/interpreter | Bin 37080 -> 0 bytes interpreter/makefile | 2 +- script.sh | 22 -- table_fonctions.c | 59 ---- table_fonctions.h | 35 --- table_symboles.c | 152 --------- table_symboles.h | 95 ------ test_file | 16 - xilinx/.DS_Store | Bin 6148 -> 6148 bytes 28 files changed, 245 insertions(+), 1221 deletions(-) delete mode 100644 analyse_lexicale.lex delete mode 100644 analyse_syntaxique.y create mode 100644 cross_assembleur/.DS_Store create mode 100644 cross_assembleur/STD_LOGIC_VECTOR_output create mode 100644 cross_assembleur/cross_input.txt create mode 100644 cross_assembleur/cross_output.txt create mode 100644 cross_assembleur/main.py create mode 100755 cross_assembleur/makefile create mode 100644 cross_assembleur/src/.DS_Store create mode 100755 cross_assembleur/src/cross.l create mode 100755 cross_assembleur/src/cross.y create mode 100755 cross_assembleur/src/cross_instructions.c create mode 100644 cross_assembleur/src/cross_instructions.h delete mode 100644 gen_assembleur.c delete mode 100644 gen_assembleur.h delete mode 100644 instructions.txt delete mode 100755 interpreter/interpreter delete mode 100755 script.sh delete mode 100644 table_fonctions.c delete mode 100644 table_fonctions.h delete mode 100644 table_symboles.c delete mode 100644 table_symboles.h delete mode 100644 test_file diff --git a/.DS_Store b/.DS_Store index 6bd4d1ebbbca52042536a31e79d1925a50fec639..db29eb603c7a43f3be1a03062cbe62cb4bf6a52b 100644 GIT binary patch literal 10244 zcmeHM-EI;=6h32XU8trQoAlDXG4_Hqv^8xSV?vQ$^uojxqZeu@3s{KDF0vr4NW+cq zP#?j!F!9DW@CkeZA3(n|JCgmYv>I(wXUNPMcITV3`^`CLI0F%hLa(+=WD=2q$})2m zO+w-OTw~>ux^fdz08ey49@VK#Hd}|^LUuip)O|O*E8T{r`j1@K9``HO<7T~I&dlF;oo=P+)H@Q~tkp5(*^{PIbNdCi=hQqoPszVw z7^zgMoLLwQ)>g9SYA!d-nuGQAT-Lm^x;7l9jD=gv_qKOi2X6*%hlfX!Z4xRJ(wzT& z+`dOI#>?wc$FW^!5BC_C0dF0!?BP?!`mn51i!8}vFUDhZtta9yD6bRW+umC)Rozy5 zyc#Fqy5$y&$_9;(^!3Kh?N6I0S)-O)`z>6%ar$SB+0P#A#Ywgu_;}QBVL!qM_;`kX zjcFv+#EZUf)A>Dbow({azRqi%@eC+*>CD?u~0UeA>zRoU3 z8EEc6%6=HdPa2Af$Dq!ef2?NBm5q%*jyuP^ZNz#EdVrYo5)7)93v)==5kl6IijJql z2qJ1<23E+$8e7m|b4&}57w;mgl%gHlqD?A7(^ir-$aM``!*#5FMa4_DK(?c>MJ4&b ze!vGN&yeH=!5K24XW-qIBe*MLINNmO3HYr;yiUSL^?!@tXXL(aORtLlI*9M;{2M@x zy`a_~;v-`7fek@-H3OOf&46Y=GjN6sO!>M^KL6iBnsUtl|7ZAwTD4|CGw`<=5Yxp{ zu>dVU50s(``K;YU-9_cX<3_%e5H#{Q9#S61;|m|hFQW3;97`_f=an4!5?4_E`JVwg P|BszJ>iqxz%Kv`=Aa6th delta 666 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8E20o2aKKED4ea@);OPJah7slXCKtHWp4} zpV+{^nVo}$gC8W%%8voiUMYgl9M9@)Vaap30GUb(N#(@_AP)lNPbL-QWEPhg z7+hy$VrF4wW9Q)D;+U)>n8DA%880AFU2SY^s-s|RVlnxbkSycO$p-}G8D~w-5|xrE z3ogpb$oIXOW@Y_gUp@8m`?`N<~Yf|DPMsW8r%%ptC8 z4s<%h3?!#>G88i;GZZmo0z<9@sJoZ}&F^4$b4;!g*PWa${+A6Da6li~Nk~xcjWEf- sg3Lho0D%NIkZ=X1hmD2bnJ4qB1abg<1xh6hljC`&P3{$!p@H?k0B)nE!2kdN diff --git a/.idea/projet_systeme.iml b/.idea/projet_systeme.iml index 94d8d6f..771e54c 100644 --- a/.idea/projet_systeme.iml +++ b/.idea/projet_systeme.iml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/analyse_lexicale.lex b/analyse_lexicale.lex deleted file mode 100644 index b8d5686..0000000 --- a/analyse_lexicale.lex +++ /dev/null @@ -1,106 +0,0 @@ -%{ -#include "analyse_syntaxique.tab.h" -int yywrap(void){ - return 1; -} - -%} - - - - -ADD "+" -SUB "-" -MUL "*" -DIV "/" -tPO "(" -tPF ")" -tAO "{" -tAF "}" -EOL "\n" -EOI ";" -SPACE " " -TAB "\t" -VIRGULE "," -AFFECTATION "=" -EQUAL "==" -LT "<" -GT ">" -LTE "<=" -GTE ">=" -tINT "int" -tMAIN "main" -tPRINT "printf" -tRETURN "return" -tIF "if" -tELSE "else" -tWHILE "while" -tNOT "!" -tAND "&&" -tOR "||" -tDIFF "!=" -tAPPERSAND "&" -DIGIT [0-9] -VARIABLE [A-Za-z0-9_]+ -CONST "const" -DECIMAL {DIGIT}+ -EXPONENTIEL {DIGIT}+"e"{DIGIT}+ -ENTIER {DECIMAL} -ENTIEREXP {EXPONENTIEL} -OPERATION {ADD}|{SUB}|{MUL}|{DIV} -COMPARATEUR {EGAL}|{LT}|{GT} -SEPARATOR {SPACE}|{TAB} - -%% - -{ADD} {return tADD ;} -{SUB} {return tSUB ;} -{MUL} {return tMUL ;} -{DIV} {return tDIV ;} - -{tPO} {return tPO ;} -{tPF} {return tPF ;} -{tAO} {return tAO ;} -{tAF} {return tAF ;} - -{EOI} {return tPV ;} -{SEPARATOR} {} -{EOL} {} -{VIRGULE} {return tVIRGULE ;} - -{AFFECTATION} {return tAFFECTATION ;} - -{EQUAL} {return tEGAL ;} -{tDIFF} {return tDIFF ;} -{LT} {return tLT ;} -{GT} {return tGT ;} -{LTE} {return tLTE ;} -{GTE} {return tGTE ;} -{tNOT} {return tNOT ;} - - -{tMAIN} {return tMAIN ;} -{tINT} {return tINT ;} -{tPRINT} {return tPRINT ;} -{tRETURN} {return tRETURN ;} - -{tOR} {return tOR ;} -{tAND} {return tAND ;} - -{tIF} {return tIF ;} -{tELSE} {return tELSE ;} -{tWHILE} {return tWHILE ;} - -{tAPPERSAND} {return tAPPERSAND;} -{CONST} {return tCONST ;} -{ENTIER} {yylval.nombre = atoi(yytext); return tENTIER ;} -{ENTIEREXP} {yylval.nombre = -1; return tENTIEREXP;} -{VARIABLE} {strcpy(yylval.id, yytext); return tVAR ;} - -%% - -//int main(void){ -// yylex(); -//} - - diff --git a/analyse_syntaxique.y b/analyse_syntaxique.y deleted file mode 100644 index 4660fcb..0000000 --- a/analyse_syntaxique.y +++ /dev/null @@ -1,230 +0,0 @@ -%union { -int nombre; -char id[30]; -} - -%{ -#include -#include "table_symboles.h" -#include "table_fonctions.h" -#include "gen_assembleur.h" - -enum Initialised_Variable init; -enum Symbole_Type type; -enum Return_Type return_type; -Table_Symboles table; -Table_Fonctions table_fonctions; -instructions_array array; -int whileCondition; -int return_value; -%} - - -%token tENTIER -%token tENTIEREXP - -%type E -%type Return Instructions -%type Cond -%type While Else Invocation - - -%token tADD -%token tSUB -%token tMUL -%token tDIV - -%token tPO -%token tPF -%token tAO -%token tAF - -%token tERROR - -%token tAPPERSAND -%token tPV -%token tVIRGULE -%token tAFFECTATION -%token tEGAL -%token tDIFF -%token tLT -%token tGT -%token tGTE -%token tLTE -%token tMAIN -%token tINT -%token tPRINT -%token tRETURN -%token tOR -%token tAND -%token tIF -%token tELSE -%token tWHILE -%token tCONST -%token tVAR -%token tNOT - -%left tADD -%left tSUB -%left tMUL -%left tDIV -%right tEGAL - - -%% - -/*C : Fonctions Main ; - -Fonctions : ; -Fonctions : Fonction Fonctions ; - -Fonction : tINT tVAR tPO Params tPF Body;*/ - -C : {generate_instruction_1(&array, JMP, -1);} Fonctions; - -Fonctions: Main; -Fonctions: Fonction Fonctions; - - -Main : tINT tMAIN {update_jmp(&array, 0, array.index); add_function(&table_fonctions, "Main", RET_INT, array.index); table.depth++;} tPO Params tPF Body {print_table(&table);remove_symboles(&table); table.depth--;}; -Fonction : Function_type tVAR {{add_function(&table_fonctions, $2, return_type, array.index); table.depth++;}} tPO Params tPF Body {print_table(&table);remove_symboles(&table); table.depth--;}; - -Function_type: tINT {type = TYPE_INT;} ; -Function_type: tINT tMUL {type = TYPE_INT_PTR;}; - -Params : {} ; -Params : Param SuiteParams ; - -Param : Param_type tVAR {add_symbole_top(&table, $2, type, INITIALISED, table.depth);} ; - -Param_type: tINT {type = TYPE_INT;} ; -Param_type: tINT tMUL {type = TYPE_INT_PTR;}; - -SuiteParams : tVIRGULE Param SuiteParams ; -SuiteParams : ; - - -Body : tAO Instructions Return tAF {} ; - -Instructions : Instruction Instructions {$$ = array.index;}; -Instructions : {$$ = array.index;}; - -Instruction : Aff ; -Instruction : If ; -Instruction : While ; -Instruction : Print ; -Instruction : Decl ; -Instruction : Invocation tPV ; - -Decl : Type Valeur SuiteDecl tPV ; - -SuiteDecl: tVIRGULE Valeur SuiteDecl ; -SuiteDecl: ; - -Type : tINT {type = TYPE_INT;} ; -Type : tCONST tINT {type = TYPE_CONST_INT;} ; -Type : tINT tMUL {type = TYPE_INT_PTR;}; - -Valeur : tVAR {add_symbole_top(&table, $1, type, INITIALISED, table.depth);} tAFFECTATION E {int varAddr = variable_exists(&table, $1); generate_instruction_2(&array, COP, varAddr, $4); free_temp(&table);}; -Valeur : tVAR {add_symbole_top(&table, $1, type, NOT_INITIALISED, table.depth);}; - - -Aff : tVAR tAFFECTATION E tPV {int varAddr = variable_exists(&table, $1); generate_instruction_2(&array, COP, varAddr, $3); free_temp(&table); }; -Aff : tMUL tVAR tAFFECTATION E tPV {int varAddr = variable_exists(&table, $2); generate_instruction_2(&array, COP_STR, varAddr, $4); free_temp(&table); }; - - -E : tENTIER {int vt = new_temp(&table); generate_instruction_2(&array, AFC, vt, $1); $$ = vt;}; -E : tVAR {int vt = new_temp(&table); int varAddr = variable_exists(&table, $1); generate_instruction_2(&array, COP, vt, varAddr); $$ = vt;}; -E : E tADD E {generate_instruction_3(&array, ADD, $1, $1, $3); free_temp(&table); $$ = $1;} ; -E : E tMUL E {generate_instruction_3(&array, MUL, $1, $1, $3); free_temp(&table); $$ = $1;} ; -E : E tSUB E {generate_instruction_3(&array, SOU, $1, $1, $3); free_temp(&table); $$ = $1;} ; -E : E tDIV E {generate_instruction_3(&array, DIV, $1, $1, $3); free_temp(&table); $$ = $1;} ; -E : tSUB E {printf("Variable negative\n");} ; -E : Invocation { - //int vt = new_temp(&table); - //generate_instruction_2(&array, COP, vt, $1); - remove_symboles(&table); - table.depth--; - $$ = $1;}; -E : tPO E tPF {printf("Parenthèse\n"); $$ = $2; } ; -E : tAPPERSAND tVAR {int vt = new_temp(&table); int varAddr = variable_exists(&table, $2); generate_instruction_2(&array, LEA, vt, varAddr); $$ = vt;}; -E : tMUL tVAR {int vt = new_temp(&table); int varAddr = variable_exists(&table, $2); generate_instruction_2(&array, COP, vt, varAddr); generate_instruction_2(&array, COP_LD, vt, vt); $$ = vt;}; - - -If : tIF tPO Cond tPF { - //gen_jmpf(&table, &array, $3, -1); - generate_instruction_2(&array, JMF, $3, -1); - free_temp(&table); - $1 = array.index; -} -tAO {table.depth++;} Instructions {generate_instruction_1(&array, JMP, -1);} tAF {remove_symboles(&table); table.depth--;} -{ - int adr_jmp = array.index; - update_jmf(&array, $1, adr_jmp); -} -Else {printf("updating jump\n"); update_jmp(&array, $8, $13);}; - -Else : tELSE tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {$$ = array.index;} ; -Else : {$$ = array.index;}; -Else : tELSE If {$$ = array.index;} ; - -While : tWHILE tPO { - $2 = array.index ; -} Cond tPF { - //gen_jmpf(&table, &array, $4, -1); - generate_instruction_2(&array, JMF, $4, -1); - free_temp(&table); - $1 = array.index; -} -tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} { - int adr_jmp = array.index; - update_jmf(&array, $1, adr_jmp); - //gen_jmpf(&table, &array, $1, $2); - generate_instruction_1(&array, JMP, $2); -}; - -Cond : E tEGAL E {generate_instruction_3(&array, EQ, $1, $1, $3); free_temp(&table); $$ = $3;}; -Cond : E tDIFF E {generate_instruction_3(&array, NEQ, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : E tLT E {generate_instruction_3(&array, LT, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : E tGT E {generate_instruction_3(&array, GT, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : E tLTE E {generate_instruction_3(&array, LTE, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : E tGTE E {generate_instruction_3(&array, GTE, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : E tAND E {generate_instruction_3(&array, AND, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : E tOR E {generate_instruction_3(&array, OR, $1, $1, $3); free_temp(&table); $$ = $3;} ; -Cond : tNOT Cond {generate_instruction_2(&array, NOT, $2, $2); $$ = $2;} ; -Cond : E {$$ = $1; }; - -Invocation : tVAR tPO {table.depth++; prepare_function_call(&table); return_value = (table.indexAvailableBottom);} Args tPF - {int function_index = function_exists(&table_fonctions, $1); - int jmp_addr = (table_fonctions.array[function_index]).start_addr; - generate_instruction_2(&array, CALL, jmp_addr, table.indexAvailableTop); - $$ = return_value; - }; - -Args : Arg SuiteArgs ; -Args : -Arg : E {int arg_addr = prepare_argument_push(&table); generate_instruction_2(&array, COP, arg_addr, $1); free_temp(&table);}; -SuiteArgs : tVIRGULE Arg SuiteArgs ; -SuiteArgs : ; - -Print : tPRINT tPO E tPF tPV {generate_instruction_1(&array, PRI, $3); free_temp(&table);}; - -Return : tRETURN E tPV {$$ = generate_instruction_1(&array, RET, $2); free_temp(&table);}; - -%% -#include -void main(void){ - //TODO: rajouter gestion des erreurs - initialise_table(&table); - initialise_function_table(&table_fonctions); - initialise_asm(&array); - yyparse(); - print_table(&table); - printf("\n"); - print_fonction_table(&table_fonctions); - - //remove_symboles(&table, 0); - //print_table(&table); - exportInstructions(&array); -} - diff --git a/cross_assembleur/.DS_Store b/cross_assembleur/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..eafa3708eee834c1c6eec9504320462b3e63a4df GIT binary patch literal 6148 zcmeHKL5|Zf6#bqSCJjQ<1=7qi8zdIhs6!bB2_Z#gSj-M72o``kNn4nRG_I1AGL)ih zxC3wlj=~8z2nT>?`xi(G>_80iufE@p{huAb%63ddqCXq$5w(fPfh%mfD1Kt9UHO`A zaE)pdx{sU&6jF}gcrDvjSOu&C|C$17?QYSKGLm}TeqX;6iYUQ4&W;i}j1n0kQ*9F; z;8(tALsVzSl+u)DRM0N`1r=4ccvEAyD`QK|{2hP0#^0m~b{sY8F2+5rjz%|Y*^bVB zhFLuU2eYf@i_f+E1~kcNSk2PCzWqS~&Wh&wly&+TO_Mk;y4_D=qtQHfe$#PW*S+XI z4o>7eD8gcv_rvU=db%4HClSZ@q)fiWVRSzp&j;;Gw`E#{aXQX4IUbFX^5{XFj^w;A zXXz-{{RF1Laayg`puMwL^!E2VUhnFSWyf0_9CSP0wchpRvgK@F-n(^lJUM;2c(r`} z4ikn6Y~R|p7+3Hf0Z;FFkfn)CpQ2`!y~?t9CKcen(YbIY-`>8oRlq9nClyfpg9lgW zGnNMR)`3D_0f0?ZYeTF)5){W{^chQoXn_es1sba0D~2$1)O(!gGnNJoodjP#1dlBE zh9dOn=-<=nBz%LmvFWh$>Us3|D;IM#tWig)1J(B`QC=rfiEQ3JCd0$K)JSOxy70$%~)B&1yc literal 0 HcmV?d00001 diff --git a/cross_assembleur/STD_LOGIC_VECTOR_output b/cross_assembleur/STD_LOGIC_VECTOR_output new file mode 100644 index 0000000..638e5bc --- /dev/null +++ b/cross_assembleur/STD_LOGIC_VECTOR_output @@ -0,0 +1 @@ +(0=>"00000111000000010000001000000000", 1=>"00000111000000100000001100000000", 2=>"00000001000000110000000100000010", 3=>"00001000000000010000001100000000", 4=>"00000111000000010000001000000000", 5=>"00000111000000100000001100000000", 6=>"00000011000000110000000100000010", 7=>"00001000000000010000001100000000", 8=>"00000111000000010000001000000000", 9=>"00001000000000010000000100000000", others => "00000000000000000000000000000000") \ No newline at end of file diff --git a/cross_assembleur/cross_input.txt b/cross_assembleur/cross_input.txt new file mode 100644 index 0000000..22198ad --- /dev/null +++ b/cross_assembleur/cross_input.txt @@ -0,0 +1,3 @@ +ADD 1 2 3 +SOU 1 2 3 +COP 1 2 \ No newline at end of file diff --git a/cross_assembleur/cross_output.txt b/cross_assembleur/cross_output.txt new file mode 100644 index 0000000..b2c24da --- /dev/null +++ b/cross_assembleur/cross_output.txt @@ -0,0 +1,10 @@ +7 1 2 0 +7 2 3 0 +1 3 1 2 +8 1 3 0 +7 1 2 0 +7 2 3 0 +3 3 1 2 +8 1 3 0 +7 1 2 0 +8 1 1 0 diff --git a/cross_assembleur/main.py b/cross_assembleur/main.py new file mode 100644 index 0000000..0ff673c --- /dev/null +++ b/cross_assembleur/main.py @@ -0,0 +1,36 @@ +import sys + +def output_instructions_binary(instructions): + file = open("STD_LOGIC_VECTOR_output", "w") + file.write("(") + for index, instruction in enumerate(instructions): + string_instruction = str(index) + "=>" + string_instruction+= "\"" + op = f'{int(instruction[0]):08b}' + arg1 = f'{int(instruction[1]):08b}' + arg2 = f'{int(instruction[2]):08b}' + arg3 = f'{int(instruction[3]):08b}' + string_instruction += op + arg1 + arg2 + arg3 + string_instruction += "\", " + file.write(string_instruction) + file.write("others => \"00000000000000000000000000000000\")") + file.close() + + +if __name__ == '__main__': + if len(sys.argv) != 2: + print("Please only input one file name") + exit(0) + + filename = sys.argv[1] + f = open(filename, "r") + lines = f.readlines() + lines = [line.strip() for line in lines] + instructions = [line.split(" ") for line in lines] + + output_instructions_binary(instructions) + f.close() + + + + diff --git a/cross_assembleur/makefile b/cross_assembleur/makefile new file mode 100755 index 0000000..b43dd79 --- /dev/null +++ b/cross_assembleur/makefile @@ -0,0 +1,17 @@ +SRCC:= ./src/*.c + +all: cross_assembler + +cross_assembler: src/cross.y src/cross.l src/cross_instructions.c + yacc -d ./src/cross.y + lex ./src/cross.l + gcc lex.yy.c y.tab.c ./src/cross_instructions.c -Isrc -o cross_assembler + +run: cross_assembler + ./cross_assembler < cross_input.txt + +export_binary: run + python3 main.py cross_output.txt + +clean: + rm -f lex.yy.c cross_assembler y.tab.h y.tab.c *.o diff --git a/cross_assembleur/src/.DS_Store b/cross_assembleur/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6d4f57b2160bcdb4823b775c10d4f2a2adef36d7 GIT binary patch literal 6148 zcmeHKJx>EM47F(`DzS7xf-xggC1#eWDg!e=0Mugu>C}^GJ9Nv!kKtFs^9Lt#+{Azo z*j4-z$967HY7!F>FZU0ZL~|mVp$W2dMnue`Q%CMR1+wPY(t_HXwrkeyNTT0pl5anz zhMuXTEq?v?cWcam7Cr-Bys790YVU*Xw)cJ+c%OdCeMe8U!5TZPwugO(ai^9AHFX}k z`evTTL7vw^9^FEyU?3O>27-Zq%>eFfk=co1=wKii2nKovd^tEB>+&K z(JJUmEg><%V>Q0;uLk9!F zK+V9!hI6_9ukn`|E%NJ-7zG2tz#n6Pr>oo55}We7^~?6;u1#q7Xd>cQqys^}dIVq~ g=g7HE+I*5e{IX*)lq_P`a9}(Hl#o!tzz;C+4j?H@3IG5A literal 0 HcmV?d00001 diff --git a/cross_assembleur/src/cross.l b/cross_assembleur/src/cross.l new file mode 100755 index 0000000..37edbf2 --- /dev/null +++ b/cross_assembleur/src/cross.l @@ -0,0 +1,32 @@ +%{ + #include "y.tab.h" +%} + +vSEP [ \t\r\n] + +%% + +ADD {return tADD;} +MUL {return tMUL;} +SOU {return tSOU;} +DIV {return tDIV;} +COP {return tCOP;} +AFC {return tAFC;} + +-?[0-9]+ { + yylval.nb = atoi(yytext); + return tNB; + } + + +{vSEP} {} + +. { + fprintf(stderr, "ERROR lex : Unknown pattern %s", yytext); + exit(1); + } + +%% + +int yywrap(void) { return 1; } +//int main(int argc, char *argv[]) { while (yylex()!=0) ; return 0; } diff --git a/cross_assembleur/src/cross.y b/cross_assembleur/src/cross.y new file mode 100755 index 0000000..cc0cac5 --- /dev/null +++ b/cross_assembleur/src/cross.y @@ -0,0 +1,88 @@ +%{ + #include + #include "cross_instructions.h" + int yylex(); + void yyerror(char*); + int yydebug = 1; + extern int yylineno; + + reg_instructions reg_array; +%} + +/* Union for yylval */ +%union { + int nb; +} + +%token tADD tMUL tSOU tDIV tCOP tAFC +%token tNB + +%% + +%start File; + +File: + Instructions; + +Instructions: + /* epsilon */ + | Instructions Instruction + ; + +Instruction: + tADD tNB tNB tNB + { + add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0); + add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0); + add_reg_oriented_instructions(®_array,ADD, 3, 1, 2); + add_reg_oriented_instructions(®_array,STORE, $2, 3, 0); + } + | tMUL tNB tNB tNB + { + add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0); + add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0); + add_reg_oriented_instructions(®_array,MUL, 3, 1, 2); + add_reg_oriented_instructions(®_array,STORE, $2, 3, 0); + } + | tSOU tNB tNB tNB + { + add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0); + add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0); + add_reg_oriented_instructions(®_array,SOU, 3, 1, 2); + add_reg_oriented_instructions(®_array,STORE, $2, 3, 0); + } + | tDIV tNB tNB tNB + { + add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0); + add_reg_oriented_instructions(®_array,LOAD, 2, $4, 0); + add_reg_oriented_instructions(®_array,DIV, 3, 1, 2); + add_reg_oriented_instructions(®_array,STORE, $2, 3, 0); + } + | tCOP tNB tNB + { + add_reg_oriented_instructions(®_array,LOAD, 1, $3, 0); + add_reg_oriented_instructions(®_array,STORE, $2, 1, 0); + } + | tAFC tNB tNB + { + add_reg_oriented_instructions(®_array,AFC, 1, $3, 0); + add_reg_oriented_instructions(®_array,STORE, $2, 1, 0); + } +; + + +%% + +void yyerror(char* str) { + extern int yylineno; + fprintf(stderr, "ERROR yyparse : Line %d: %s\n", yylineno, str); +} + +int main(int argc, char *argv[]) { + init_reg_oriented_instructions(®_array); + yyparse(); + printf("INFO yyparse : Parsing End\n"); + output_reg_oriented_instructions(®_array); + return 0; +} + diff --git a/cross_assembleur/src/cross_instructions.c b/cross_assembleur/src/cross_instructions.c new file mode 100755 index 0000000..e66046d --- /dev/null +++ b/cross_assembleur/src/cross_instructions.c @@ -0,0 +1,23 @@ +#include +#include "cross_instructions.h" + +void init_reg_oriented_instructions(reg_instructions * instructions_array){ + instructions_array->index = 0; +} + +void add_reg_oriented_instructions(reg_instructions * instructions_array, int operation, int arg1, int arg2, int arg3) { + struct reg_instruction ins = {operation, arg1, arg2, arg3}; + instructions_array->reg_instructions[instructions_array->index] = ins; + instructions_array->index++; +} + +void output_reg_oriented_instructions(reg_instructions * instructions_array){ + FILE *file; + file = fopen("cross_output.txt", "w"); + struct reg_instruction instru; + for (int i = 0; i < instructions_array->index; i++){ + instru = instructions_array->reg_instructions[i]; + fprintf(file, "%d %d %d %d\n", instru.ins, instru.arg1, instru.arg2, instru.arg3); + } + +} diff --git a/cross_assembleur/src/cross_instructions.h b/cross_assembleur/src/cross_instructions.h new file mode 100644 index 0000000..c67adcd --- /dev/null +++ b/cross_assembleur/src/cross_instructions.h @@ -0,0 +1,33 @@ +#ifndef __INSTRUCTIONS_H__ +#define __INSTRUCTIONS_H__ + +#define ADD 1 +#define MUL 2 +#define SOU 3 +#define DIV 4 +#define COP 5 +#define AFC 6 +#define LOAD 7 +#define STORE 8 + +#define MAX_SIZE 256 + +struct reg_instruction { + char ins; + int arg1; + int arg2; + int arg3; +}; + +typedef struct reg_instructions{ + struct reg_instruction reg_instructions[MAX_SIZE]; + int index; +} reg_instructions; + +void init_reg_oriented_instructions(reg_instructions * instructions_array); + +void add_reg_oriented_instructions(reg_instructions * instructions_array, int operation, int arg1, int arg2, int arg3); + +void output_reg_oriented_instructions(reg_instructions * instructions_array); + +#endif // #ifndef __INSTRUCTIONS_H__ diff --git a/gen_assembleur.c b/gen_assembleur.c deleted file mode 100644 index c2c7bfa..0000000 --- a/gen_assembleur.c +++ /dev/null @@ -1,357 +0,0 @@ -#include "gen_assembleur.h" -#include -#include - -char * operationName(enum operation op){ - switch(op){ - case EQ: - return "EQ"; - case NEQ: - return "NEQ"; - case LT: - return "LT"; - case GT: - return "GT"; - case LTE: - return "LTE"; - case GTE: - return "GTE"; - case ADD: - return "ADD"; - case SOU: - return "SOU"; - case DIV: - return "DIV"; - case MUL: - return "MUL"; - case COP: - return "COP"; - case AFC: - return "AFC"; - case RET: - return "RET"; - case JMF: - return "JPF"; - case JMP: - return "JMP"; - case AND: - return "AND"; - case OR: - return "OR"; - case NOT: - return "NOT"; - case PRI: - return "PRI"; - case LEA: - return "LEA"; - case COP_LD: - return "COP_LD"; - case COP_STR: - return "COP_STR"; - case RET_FUN: - return "RET_FUN"; - case CALL: - return "CALL"; - default: - break; - } - return ""; -} - -void initialise_asm(instructions_array * array){ - array->index = 0; -} - -int add_instruction(instructions_array * array, instruction * instru){ - if (array->index >= INSTRUCTION_TABLE_SIZE){ - return 1; - } - array->array[array->index] = *instru; - array->index++; - - return 0; -} - -int new_temp(Table_Symboles * table){ - int ret_addr ; - if(add_symbole_bottom(table) == -1) { - return -1; - } - ret_addr = table->indexAvailableBottom + 1; - return ret_addr; -} - -int generate_instruction_0(instructions_array * array, enum operation op){ - instruction instru; - char * opName = operationName(op); - - instru.operation = op; - - printf("%d\t %s\n", array->index, opName); - - if (add_instruction(array, &instru) != 0){ - //TODO: Error handling - exit(1); - } - - return 0; -} - -int generate_instruction_1(instructions_array * array, enum operation op, int arg1){ - instruction instru; - char * opName = operationName(op); - - instru.operation = op; - instru.reg1 = arg1; - - printf("%d\t %s %d\n", array->index, opName, instru.reg1); - - if (add_instruction(array, &instru) != 0){ - //TODO: Error handling - exit(1); - } - - return 0; -} - -int generate_instruction_2(instructions_array * array, enum operation op, int arg1, int arg2){ - instruction instru; - char * opName = operationName(op); - - instru.operation = op; - instru.reg1 = arg1; - instru.reg2 = arg2; - - printf("%d\t %s %d %d\n", array->index, opName, instru.reg1, instru.reg2); - - if (add_instruction(array, &instru) != 0){ - //TODO: Error handling - exit(1); - } - - return 0; -} - -int generate_instruction_3(instructions_array * array, enum operation op, int arg1, int arg2, int arg3){ - instruction instru; - char * opName = operationName(op); - - instru.operation = op; - instru.reg1 = arg1; - instru.reg2 = arg2; - instru.reg3 = arg3; - - printf("%d\t %s %d %d %d\n", array->index, opName, instru.reg1, instru.reg2, instru.reg3); - - if (add_instruction(array, &instru) != 0){ - //TODO: Error handling - exit(1); - } - - return 0; -} - -void update_jmf(instructions_array * array, int instru_index, int adr_jmp){ - array->array[instru_index - 1].reg2 = adr_jmp; - printf("%d\t JMP %d %d\n", (instru_index - 1), array->array[instru_index].reg1, array->array[instru_index].reg2); -} - -void update_jmp(instructions_array * array, int instru_index, int adr_jmp){ - array->array[instru_index].reg1 = adr_jmp; - printf("%d\t JMP %d\n", (instru_index - 1), array->array[instru_index].reg1); -} - -void exportInstructions(instructions_array * array){ - FILE *file; - file = fopen("instructions.txt", "w"); - instruction instru; - enum operation op; - - for (int i = 0; i < array->index; i++){ - instru = array->array[i]; - op = instru.operation; - switch (op) { - //0 parameters - case RET_FUN: - fprintf(file, "%s\n", operationName(op)); - break; - //1 parameter - case JMP: - case PRI: - case RET: - fprintf(file, "%s %d\n", operationName(op), instru.reg1); - break; - //2 parameters - case JMF: - case NOT: - case AFC: - case COP: - case LEA: - case CALL: - fprintf(file, "%s %d %d\n", operationName(op), instru.reg1, instru.reg2); - break; - case COP_LD: - fprintf(file, "%s %d [%d]\n", operationName(op), instru.reg1, instru.reg2); - break; - case COP_STR: - fprintf(file, "%s [%d] %d\n", operationName(op), instru.reg1, instru.reg2); - break; - //3 parameters - case ADD: - case SOU: - case DIV: - case MUL: - case AND: - case OR: - case EQ: - case NEQ: - case LT: - case LTE: - case GT: - case GTE: - fprintf(file, "%s %d %d %d\n", operationName(op), instru.reg1, instru.reg2, instru.reg3); - break; - default: - break; - } - } - - fclose(file); -} - -/*int gen_print(Table_Symboles * table, instructions_array * array, int arg1){ - instruction instru; - instru.operation = PRI; - instru.reg1 = arg1; - - printf("%d\t PRI %d\n", array->index, instru.reg1); - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - - free_temp(table); -}*/ - -/*void gen_arithmetique(instructions_array * array, enum operation op, int arg1, int arg2){ - instruction instru; - instru.reg1 = arg1; - instru.reg2 = arg1; - instru.reg3 = arg2; - - char * opName = operationName(op); - printf("%d\t %s %d %d %d\n", array->index, opName, arg1, arg1, arg2); - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - -} - -int gen_var(Table_Symboles * table, instructions_array * array, char * varName){ - int vt = new_temp(table); - int varAddr = variable_exists(table, varName); - - //vérifier que non null - instruction instru; - instru.operation = COP; - instru.reg1 = vt; - instru.reg2 = varAddr; - - printf("%d\t COP %d %d\n", array->index, vt, varAddr); - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - - return vt; - -} - -int gen_entier(Table_Symboles * table, instructions_array * array, int entier){ - int vt = new_temp(table); - - //vérifier que non null - instruction instru; - instru.operation = AFC; - instru.reg1 = vt; - instru.reg2 = entier; - - printf("%d\t AFC %d %d\n", array->index, vt, entier); - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - - return vt; -} - -int gen_condition(Table_Symboles * table, instructions_array * array, enum operation op, int arg1, int arg2){ - - char * opName = operationName(op); - - instruction instru; - instru.operation = op; - instru.reg1 = arg1; - instru.reg2 = arg1; - if (op != NOT){ - instru.reg3 = arg2; - printf("%d\t %s %d %d %d\n", array->index, opName, instru.reg1, instru.reg2, instru.reg3); - free_temp(table); - } else { - printf("%d\t %s %d %d \n", array->index, opName, instru.reg1, instru.reg2); - } - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - - return instru.reg1; -} - -int gen_return(Table_Symboles * table, instructions_array * array, int adr){ - - //vérifier que non null - instruction instru; - instru.operation = RET; - instru.reg1 = adr; - - printf("%d\t RET %d\n", array->index, adr); - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - - //free_temp(table); - - return adr; -} - -int gen_jmpf(Table_Symboles * table, instructions_array * array, int cond, int dest){ - //vérifier que non null - instruction instru; - instru.operation = JMF; - instru.reg1 = cond; - instru.reg2 = dest; - - printf("%d\t JMPF %d %d\n", array->index, instru.reg1 , instru.reg2); - - if (array->index < INSTRUCTION_TABLE_SIZE){ - array->array[array->index] = instru; - array->index++; - } - - //free_temp(table); - - return cond; -} - - */ - - diff --git a/gen_assembleur.h b/gen_assembleur.h deleted file mode 100644 index 8028c89..0000000 --- a/gen_assembleur.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef GEN_ASSEMBLEUR_H -#define GEN_ASSEMBLEUR_H - -#define INSTRUCTION_TABLE_SIZE 1000 - -#include "table_symboles.h" - -enum operation{ADD, SOU, MUL, DIV, COP, AFC, RET, JMF, JMP, EQ, NEQ, LT, GT, LTE, - GTE, AND, OR, NOT, PRI, LEA, COP_LD, COP_STR, CALL, RET_FUN}; - -typedef struct instruction{ - enum operation operation; - int reg1; - int reg2; - int reg3; -}instruction; - -//table des instructions -typedef struct instructions_array{ - instruction array[INSTRUCTION_TABLE_SIZE]; - int index; -} instructions_array; - -/** - * - * @param op operation - * @return returns the string that corresponds to the enum operation op - */ -char * operationName(enum operation op); - -/** - * Initialises the instructions array - * @param array - */ -void initialise_asm(instructions_array * array); - -//renvoie l'index (ou valeur?) de la premiere @ dispo -/** - * Fetch address of a temporary variable - * @param table - * @return first available temp address - */ -int new_temp(Table_Symboles * table); - -/** - * Adds intruction to instruction array - * @param array - * @param intru - * @return 0 if instruction was added successfully, -1 if not - */ -int add_instruction(instructions_array * array, instruction * intru); - -/** - * Generates intruction with no parameter - * @param array - * @param op - * @return - */ -int generate_instruction_0(instructions_array * array, enum operation op); - -/** - * Generates intruction with one parameter - * @param array - * @param op - * @param arg1 - * @return - */ -int generate_instruction_1(instructions_array * array, enum operation op, int arg1); - -/** - * Generates intruction with two parameters - * @param array - * @param op - * @param arg1 - * @param arg2 - * @return - */ -int generate_instruction_2(instructions_array * array, enum operation op, int arg1, int arg2); - -/** - * Generates intruction with three parameters - * @param array - * @param op - * @param arg1 - * @param arg2 - * @param arg3 - * @return - */ -int generate_instruction_3(instructions_array * array, enum operation op, int arg1, int arg2, int arg3); - -/** - * Updates the JMF instruction with the correct jump destination address - * @param array - * @param instru_index - * @param adr_jmp - */ -void update_jmf(instructions_array * array, int instru_index, int adr_jmp); - -void update_jmp(instructions_array * array, int instru_index, int adr_jmp); - - - - -void exportInstructions(instructions_array * array); - -/* -void gen_arithmetique(instructions_array * array, enum operation op, int arg1, int arg2); - -int gen_var(Table_Symboles * table, instructions_array * array, char * varName); - -int gen_entier(Table_Symboles * table, instructions_array * array, int entier); - -int gen_return(Table_Symboles * table, instructions_array * array, int adr); - -int gen_jmpf(Table_Symboles * table, instructions_array * array, int cond, int dest); - -int gen_condition(Table_Symboles * table, instructions_array * array, enum operation op, int arg1, int arg2); - -int gen_print(Table_Symboles * table, instructions_array * array, int arg1); - */ -#endif \ No newline at end of file diff --git a/instructions.txt b/instructions.txt deleted file mode 100644 index 8a5ed67..0000000 --- a/instructions.txt +++ /dev/null @@ -1,26 +0,0 @@ -JMP 8 -COP 255 0 -COP_LD 255 [255] -COP 1 255 -COP 255 1 -PRI 255 -AFC 255 1 -RET 255 -AFC 255 21 -COP 0 255 -LEA 255 0 -COP 1 255 -COP 255 1 -COP 5 255 -CALL 1 6 -COP 2 255 -COP 255 2 -PRI 255 -LEA 255 2 -COP 1 255 -AFC 255 2 -COP_STR [1] 255 -COP 255 2 -PRI 255 -AFC 255 0 -RET 255 diff --git a/interpreter/.DS_Store b/interpreter/.DS_Store index af774dac104ff16e3c10927e1da75b71c30abbb9..83973b245976ee21e01dcc9a2c7cd8ea0cb253a1 100644 GIT binary patch delta 32 ocmZoMXfc@J&&atkU^g=(=Vl(3XN;Rw*d8-ZY%to)&heKY0INz0mjD0& delta 51 zcmZoMXfc@J&&ahgU^g=(*Jd7;XN=sO3?&Sy48=e)e)0wuF(yXw$%1UMo7k>0Zf58B G%MSo$hYgef diff --git a/interpreter/interpreter b/interpreter/interpreter deleted file mode 100755 index daaf2bdc8d4e4726deae4ac294ba97f186396c3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 37080 zcmeHw33!y%`R|z|AA}{DundGn84-|0!j6Q^1Q?hoO9TScibF^y5KS_1G6RW0X{&9$TK`sY!?2Vf)fOx+RcoU~J7Zj;P)r4#`+Lvw%{SjnsP}*G^W6K~ z>zC)td(OL^_q^wv_nh->bF*vl!Ze$WsUw}uWt7|1OJE8lVP{w-01DU))&u{~V?$Xt z!(khP*py@s;m5pj(37)J+1^Il^?F@0)KNC`0KjB zKh_0)R2TUF)&-uzS1LPi>jFQ#i~8;Y|8ShvqYQ{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oCtpdJ6lY{9{ -#include - -void initialise_function_table(Table_Fonctions * table){ - table->depth = 1; -} - -void add_function(Table_Fonctions * table, char * function_name, enum Return_Type return_type, int start_addr){ - Fonction fonction; - strcpy(fonction.function_name,function_name); - fonction.start_addr = start_addr; - fonction.type = return_type; - fonction.function_depth = table->depth; - table->array[table->depth] = fonction; - table->depth++; -} - -void print_function(Fonction * fonction){ - char * function_name = fonction->function_name; - int start_addr = fonction->start_addr; - int depth = fonction->function_depth; - int return_type = fonction->type; - char typeStr[20]; - if (return_type == RET_INT){ - strcpy(typeStr, "INT"); - } else if (return_type == RET_INT_PTR){ - strcpy(typeStr, "INT_PTR"); - } - printf("%-20s\t\t %-12s\t\t %-12d\t %-12d\n", function_name, typeStr, start_addr, depth); -} - -void print_fonction_table(Table_Fonctions * table) { - printf("%-20s\t\t %-12s\t\t %-12s\t %-20s\n", "Function Name", "Return Type", "Start Address", "Depth"); - Fonction fonction; - for (int i = 1; i < table->depth; i++) { - fonction = table->array[i]; - print_function(&fonction); - } -} - -int function_exists(Table_Fonctions * table, char * func_name){ - for (int i = 0; i < table->depth; i++){ - if (strcmp(table->array[i].function_name, func_name) == 0){ - return i; - } - } - return -1; -} - -/* -int main(){ - Table_Fonctions table; - initialise_function_table(&table); - add_function(&table, "Fonction1", 0, 7); - add_function(&table, "Fonction2", 1, 23); - print_fonction_table(&table); - return 1; -}*/ diff --git a/table_fonctions.h b/table_fonctions.h deleted file mode 100644 index 2c77e2c..0000000 --- a/table_fonctions.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by Nahom Belay on 29/04/2021. -// - -#ifndef PROJET_SYSTEME_TABLE_FONCTIONS_H -#define PROJET_SYSTEME_TABLE_FONCTIONS_H - -#define FUNCTION_TABLE_SIZE 50 -#define FUNCTION_NAME_SIZE 30 - -enum Return_Type {RET_INT , RET_INT_PTR}; - -typedef struct Fonction { - char function_name[FUNCTION_NAME_SIZE]; - int start_addr ; - enum Return_Type type; - int function_depth; -} Fonction; - -typedef struct Table_Fonctions { - Fonction array[FUNCTION_TABLE_SIZE]; - int depth; -} Table_Fonctions; - -void initialise_function_table(Table_Fonctions * table); - -void add_function(Table_Fonctions * table, char * function_name, enum Return_Type return_type, int start_addr); - -void print_fonction_table(Table_Fonctions * table); - -int function_exists(Table_Fonctions * table, char * func_name); - - - -#endif //PROJET_SYSTEME_TABLE_FONCTIONS_H diff --git a/table_symboles.c b/table_symboles.c deleted file mode 100644 index 31f4899..0000000 --- a/table_symboles.c +++ /dev/null @@ -1,152 +0,0 @@ -#include "table_symboles.h" -#include -#include - - -void initialise_table(Table_Symboles * table){ - table->indexAvailableBottom = TABLE_SIZE - 1; - table->indexAvailableTop = 0; - table->depth = 0; -} - -int variable_exists(Table_Symboles * table, char * varName){ - for (int i = 0; i < table->indexAvailableTop; i++){ - if (strcmp(varName, table->array[i].Variable_Name) == 0){ - return i; - } - } - - for (int i = (table->indexAvailableBottom + 1); i < TABLE_SIZE; i++){ - if (strcmp(varName, table->array[i].Variable_Name) == 0){ - return i; - } - } - return 0; -} -int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type, enum Initialised_Variable init, int depth){ - Symbole symbole; - strcpy(symbole.Variable_Name, varName); - symbole.addr = table->indexAvailableTop; - symbole.init = init; - symbole.type = type; - symbole.symbole_depth = table->depth; - if (table->indexAvailableTop >= table->indexAvailableBottom){ - return -1; - } else if (variable_exists(table, varName) != 0){ - return -2; - } else { - table->array[table->indexAvailableTop] = symbole; - table->indexAvailableTop++; - } - return 0; -} - -int add_symbole_bottom(Table_Symboles * table){ - Symbole symbole; - symbole.addr = table->indexAvailableBottom; - //symbole.symbole_depth = -1; - if (table->indexAvailableTop >= table->indexAvailableBottom){ - return -1; - } else { - table->array[table->indexAvailableBottom] = symbole; - table->indexAvailableBottom--; - } - return 0; -} - -int remove_symboles(Table_Symboles * table){ - if (table->indexAvailableTop > 0){ - while(table->indexAvailableTop > 0){ - if (table->array[table->indexAvailableTop-1].symbole_depth == table->depth){ - table->indexAvailableTop--; - } else { - break; - } - - } - } - - - //TODO: vérifier qu'il n'y a pas de varaibles temporarires au moment de changement de profondeur - return 0; -} - -void free_temp(Table_Symboles * table){ - table->indexAvailableBottom++; - if (table->indexAvailableBottom >= TABLE_SIZE){ - printf("Huge error\n"); - table->indexAvailableBottom--; - } -} - -int prepare_function_call(Table_Symboles * table){ - prepare_argument_push(table); - prepare_argument_push(table); -} - -int prepare_argument_push(Table_Symboles * table){ - Symbole symbole; - symbole.addr = table->indexAvailableTop; - symbole.symbole_depth = table->depth; - if (table->indexAvailableTop < table->indexAvailableBottom){ - table->array[table->indexAvailableTop] = symbole; - table->indexAvailableTop++; - return (table->indexAvailableTop) - 1 ; - } - -} - -int initialise_symbole(Table_Symboles * table, char * varName){ - int index = variable_exists(table, varName); - if (index == -1){ - return -1; - } else { - table->array[index].init = INITIALISED; - } -} - -void print_symbole(Symbole * symbole){ - char * var = symbole->Variable_Name; - int addr = symbole->addr; - enum Symbole_Type type = symbole->type; - char typeStr[20]; - if (type == TYPE_INT){ - strcpy(typeStr, "INT"); - } else if (type == TYPE_CONST_INT){ - strcpy(typeStr, "CONST_INT"); - } else if (type == TYPE_INT_PTR) { - strcpy(typeStr, "INT_PTR"); - } else { - strcpy(typeStr, "Error type"); - } - enum Initialised_Variable init = symbole->init; - char initStr[20]; - if (init == INITIALISED){ - strcpy(initStr,"INITIALISED"); - } else{ - strcpy(initStr,"NOT_INITIALISED"); - } - int depth = symbole->symbole_depth; - printf("%-20s\t\t %-12s\t\t %-12d\t %-20s\t %-12d\n", var, typeStr, addr, initStr, depth); -} - -void print_table(Table_Symboles * table){ - printf("%-20s\t\t %-12s\t\t %-12s\t %-20s\t %-12s\n", "Variable Name", "Type", "Address", "Initialised", "Depth"); - int indexTop = table->indexAvailableTop; - int indexBottom = table->indexAvailableBottom; - Symbole symbole; - for (int i = 0; i < indexTop; i++){ - symbole = table->array[i]; - print_symbole(&symbole); - } - if (table->indexAvailableBottom != TABLE_SIZE - 1){ - printf("%-20s\t\t %-12s\t\t %-12s\t %-20s\t %-12s\n", "...", "...", "...", "...", "..."); - for (int i = (indexBottom + 1); i < TABLE_SIZE; i++){ - symbole = table->array[i]; - print_symbole(&symbole); - } - } - - - -} diff --git a/table_symboles.h b/table_symboles.h deleted file mode 100644 index 0eac03f..0000000 --- a/table_symboles.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef TABLE_SYMBOLES_H -#define TABLE_SYMBOLES_H - -#define TABLE_SIZE 256 -#define VARIABLE_SIZE 30 - -enum Symbole_Type {TYPE_INT , TYPE_CONST_INT, TYPE_INT_PTR}; -enum Initialised_Variable{INITIALISED , NOT_INITIALISED}; - -typedef struct Symboles { - char Variable_Name[VARIABLE_SIZE]; - int addr ; - enum Symbole_Type type; - enum Initialised_Variable init; - int symbole_depth; -} Symbole; - -typedef struct Table_Symboles { - Symbole array[TABLE_SIZE]; - int indexAvailableTop; - int indexAvailableBottom; - int depth; -} 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); - -/** - * 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 - */ -int add_symbole_bottom(Table_Symboles * table); - - - -/** - * 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 - */ -int remove_symboles(Table_Symboles * table); - - -void free_temp(Table_Symboles * table); - -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); - - -/** - * 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 \ No newline at end of file diff --git a/test_file b/test_file deleted file mode 100644 index f0dfdca..0000000 --- a/test_file +++ /dev/null @@ -1,16 +0,0 @@ -int fonction1(int * a){ - int b = *a; - printf(b); - return 1; - } - -int main(){ - int l = 21; - int * p = &l; - int c = fonction1(p); - printf(c); - p = &c; - *p = 2; - printf(c); - - return 0; \ No newline at end of file diff --git a/xilinx/.DS_Store b/xilinx/.DS_Store index 15f11d24cc626205b1223eef6ac354aa4353d98a..cfdbb75f0b1712ca3d5bb42401973bee0fde05bf 100644 GIT binary patch delta 184 zcmZoMXffCj&BDkvIff;JkCQWAK%%C6;ndF;Q^|QAsH&naM${MY8b% z{Kd&d`8hcO`Nf$fnfZB<(dk8*DgJ3`#i=EeAF}#NgH&YXmwP7X=LHm{mSv`vM`Qxo z!I@R5lReoqY?2xnK!8JlF(fZPFO`#1*&zTd0u*D=W^iQiWe8))W~gGA$S{{-J;QE> b6AX75-ZT7UWM`C|yp~OzF?#b+HhVz;-J>%h delta 184 zcmZoMXffCj&BDkrIff;JkApK_K%%AF}#NM`R}F=LKh0rGlh0^2Cg zvdq--$)0Q)HVqLBAiyEO7?PKtm&&Q^5C9fn;AG%n&}MLC@MQ>N$Y!Wwn8+}fVI{+E ch7$~T8QwGeWMpR)n7o!voH2RxQ8s%)0O7bZ3;+NC