Browse Source

Avancée compilation maiis bug

Elies Tali 3 years ago
parent
commit
2be358e747

+ 4
- 0
Lex_Yacc/ProgC View File

@@ -0,0 +1,4 @@
1
+int main(int a, int b)
2
+{
3
+	int c;
4
+}

BIN
Lex_Yacc/a.exe View File


BIN
Lex_Yacc/a.out View File


+ 7
- 0
Lex_Yacc/al.lex View File

@@ -1,6 +1,13 @@
1 1
 %{
2 2
 #include "as.tab.h"
3 3
 int yywrap(void){return 1;}
4
+void
5
+yyerror (char const *s)
6
+{
7
+
8
+  fprintf (stderr, "%s\n", s);
9
+}
10
+
4 11
 %}
5 12
 
6 13
 %%

+ 543
- 466
Lex_Yacc/as.output
File diff suppressed because it is too large
View File


+ 503
- 364
Lex_Yacc/as.tab.c
File diff suppressed because it is too large
View File


+ 9
- 6
Lex_Yacc/as.tab.h View File

@@ -1,8 +1,9 @@
1
-/* A Bison parser, made by GNU Bison 3.0.4.  */
1
+/* A Bison parser, made by GNU Bison 3.5.1.  */
2 2
 
3 3
 /* Bison interface for Yacc-like parsers in C
4 4
 
5
-   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
5
+   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
6
+   Inc.
6 7
 
7 8
    This program is free software: you can redistribute it and/or modify
8 9
    it under the terms of the GNU General Public License as published by
@@ -30,6 +31,9 @@
30 31
    This special exception was added by the Free Software Foundation in
31 32
    version 2.2 of Bison.  */
32 33
 
34
+/* Undocumented macros, especially those whose name start with YY_,
35
+   are private implementation details.  Do not rely on them.  */
36
+
33 37
 #ifndef YY_YY_AS_TAB_H_INCLUDED
34 38
 # define YY_YY_AS_TAB_H_INCLUDED
35 39
 /* Debug traces.  */
@@ -78,17 +82,16 @@ extern int yydebug;
78 82
 
79 83
 /* Value type.  */
80 84
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
81
-
82 85
 union YYSTYPE
83 86
 {
84
-#line 1 "as.y" /* yacc.c:1909  */
87
+#line 1 "as.y"
85 88
 
86 89
 	int nombre;
87 90
     char id[30];
88 91
 
89
-#line 90 "as.tab.h" /* yacc.c:1909  */
90
-};
92
+#line 93 "as.tab.h"
91 93
 
94
+};
92 95
 typedef union YYSTYPE YYSTYPE;
93 96
 # define YYSTYPE_IS_TRIVIAL 1
94 97
 # define YYSTYPE_IS_DECLARED 1

+ 44
- 32
Lex_Yacc/as.y View File

@@ -7,13 +7,10 @@
7 7
 #include <stdio.h> 
8 8
 #include <string.h>
9 9
 #include <stdlib.h>
10
+#include "../Symboles/tab_instruc.h"
10 11
 #define TAILLE 1024
11 12
 
12
-int addr = 0;
13
-
14 13
 enum type_t type_courant;
15
-int * tab_instruc = malloc(sizeof(int)*TAILLE);
16
-int index_instruc = 0;
17 14
 
18 15
 %}
19 16
 
@@ -22,7 +19,7 @@ int index_instruc = 0;
22 19
 %token tOBRACE tCBRACE
23 20
 %token tINT
24 21
 %token tCONST
25
-%token tPV tCOMA#include <string.h>
22
+%token tPV tCOMA
26 23
 %token tMUL tDIV tADD tSUB tEQ
27 24
 %token<nombre> tNB tNBEXP
28 25
 %token<id> tID
@@ -39,6 +36,8 @@ int index_instruc = 0;
39 36
 %left tADD tSUB
40 37
 %left tMUL tDIV
41 38
 
39
+%type<nombre> E Invocation
40
+
42 41
 
43 42
 
44 43
 //%type<nombre> E
@@ -47,7 +46,7 @@ int index_instruc = 0;
47 46
 
48 47
 %%
49 48
 
50
-Main : tINT tMAIN tOBRACE Params tCBRACE Body { print(pile);  printf("addr = %d\n",addr);} ; 
49
+Main : tINT tMAIN tOBRACE Params tCBRACE Body { print(); create_asm();} ; 
51 50
 
52 51
 Params : { printf("Sans Params\n"); } ;
53 52
 Params : Param SuiteParams ;
@@ -55,16 +54,16 @@ Param : DeclType tID { printf("Prametre : %s\n", $2); };
55 54
 SuiteParams : tCOMA Param SuiteParams ;
56 55
 SuiteParams : ;
57 56
 
58
-Body : tOBRACKET Instructions tCBRACKET { struct symbole_t symbole = {"Salut", 0x77b58af, INT, 1}; push(symbole, pile); } ;
57
+Body : tOBRACKET Instructions tCBRACKET { } ;
59 58
 
60 59
 
61 60
 Instructions : Instruction Instructions ;
62 61
 Instructions : ;
63
-Instruction : Aff ;
64
-Instruction : Decl ;
65
-Instruction : Invocation tPV ;
66
-Instruction : If;
67
-Instruction : While;
62
+Instruction : Aff {reset_temp_vars();};
63
+Instruction : Decl {reset_temp_vars();};
64
+Instruction : Invocation tPV{reset_temp_vars();};
65
+Instruction : If {reset_temp_vars();};
66
+Instruction : While {reset_temp_vars();};
68 67
 
69 68
 
70 69
 If : tIF tOBRACE Cond tCBRACE Body Else { printf("If reconnu\n"); };
@@ -81,44 +80,57 @@ SuiteCond : tOR E SuiteCond;
81 80
 
82 81
 Aff : tID tEQ E tPV { printf("%s prend une valeur\n", $1);} ; //besoin de get_address
83 82
 
84
-E : tNB { printf("Nombre\n"); 
85
- struct symbole_t symbole = ("", addr, INT, 1};
86
- push(symbole, pile); 
87
-$$=addr;
88
-  addr++;
89
- printf("AFC %d %d",addr,$1); } ;
83
+E : tNB { int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
90 84
 
91
-E : tNBEXP { printf("Nombre exp\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("AFC %d %d",addr,$1); };
85
+E : tNBEXP { printf("Nombre exp\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
92 86
 E : tID { printf("Id\n"); /*Faire un get_address sur la pile*/};
93
-E : E tMUL E { printf("Mul\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("MUL %d %d %d",addr, $1,$2);};
94
-E : E tDIV E { printf("Div\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("DIV %d %d %d",addr, $1,$2);};
95
-E : E tSUB E { printf("Sub\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("SOU %d %d %d",addr, $1,$2);};
96
-E : E tADD E { printf("Add\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("ADD %d %d %d",addr, $1,$2);}};
97
-E : Invocation { printf("Invoc\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("AFC %d %d",addr, $1);};
98
-E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2};
99
-E : tSUB E { printf("Moins\n"); printf("SUB %d 0 %d",addr,$2);};
100
-E : E tEQCOND E { printf("==\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("EQU %d %d %d",addr, $1,$3);};
101
-E : E tGT E { printf(">\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("SUP %d %d %d",addr, $1,$3);};
102
-E : E tLT E { printf("<\n"); struct symbole_t symbole = {"", addr, INT, 1}; push(symbole, pile); $$=addr;  addr++; printf("SUP %d %d %d",addr, $1,$3);};
87
+E : E tMUL E { printf("Mul\n"); int addr = allocate_mem_temp_var(INT); add_operation(MUL, addr,$1,$2); $$ = addr;};
88
+E : E tDIV E { printf("Div\n"); int addr = allocate_mem_temp_var(INT); add_operation(DIV, addr,$1,$2); $$ = addr;};
89
+E : E tSUB E { printf("Sub\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, addr,$1,$2); $$ = addr;};
90
+E : E tADD E { printf("Add\n"); int addr = allocate_mem_temp_var(INT); add_operation(ADD, addr,$1,$2); $$ = addr;};
91
+E : Invocation { printf("Invoc\n"); int addr = allocate_mem_temp_var(INT); add_operation(AFC, addr,$1,0); $$ = addr;};
92
+E : tOBRACE E tCBRACE { printf("Parentheses\n"); $$=$2;};
93
+E : tSUB E { printf("Moins\n"); int addr = allocate_mem_temp_var(INT); add_operation(SOU, 0,addr,0); $$ = addr;};
94
+E : E tEQCOND E { printf("==\n"); int addr = allocate_mem_temp_var(INT); add_operation(EQU, addr,$1,$3); $$ = addr;};
95
+E : E tGT E { printf(">\n"); int addr = allocate_mem_temp_var(INT); add_operation(SUP, addr,$1,$3); $$ = addr;};
96
+E : E tLT E { printf("<\n"); int addr = allocate_mem_temp_var(INT); add_operation(INF, addr,$1,$3); $$ = addr;};
103 97
 E : tNOT E { printf("!\n"); };
104 98
 
105 99
 
106 100
 
107 101
 //Créer un champ isConst dans la table des symboles
102
+DeclType : tINT {type_courant = INT; printf("Type int\n");} ;
103
+
104
+Decl : DeclType SuiteDecl FinDecl ;
105
+Decl : tCONST DeclType SuiteDeclConst FinDeclConst;
106
+
107
+SuiteDecl : tID {push($1, 0, type_courant); printf("Suite Decl\n");};
108
+SuiteDecl : tID tEQ E {int addr = push($1,1, type_courant); add_operation(AFC, addr,$3,0);};
109
+FinDecl : tPV { printf("Fin Decl\n");};
110
+FinDecl : tCOMA SuiteDecl FinDecl ;
111
+
112
+SuiteDeclConst : tID tEQ E {int addr = push($1,1, type_courant); add_operation(AFC, addr,$3,0);};
113
+FinDeclConst : tPV;
114
+FinDeclConst : tCOMA SuiteDeclConst FinDeclConst;
115
+
116
+
117
+/* //Créer un champ isConst dans la table des symboles
118
+DeclType : tINT {type_courant = INT; printf("Type int\n");} ;
119
+
108 120
 Decl : tCONST DeclType SuiteDeclConst { } ;
109 121
 SuiteDeclConst : tCOMA tID SuiteDeclConst ;
110 122
 SuiteDeclConst : tEQ E tPV { };
111 123
 SuiteDeclConst : tPV { };
112 124
 
113 125
 
114
-DeclType : tINT {type_courant = INT;} ;
115 126
 Decl : DeclType Decl SuiteDecl { } ;
116 127
 Decl : tID {push($1, 0, type_courant);};
117
-Decl : tID tEQ E {push($1,1, type_courant);} ;
128
+Decl : tID tEQ E {int addr = push($1,1, type_courant); add_operation(AFC, addr,$3,0);} ;
118 129
 SuiteDecl : tCOMA Decl SuiteDecl { };
119 130
 SuiteDecl : tPV { };
131
+*/
120 132
 
121
-Invocation : tPRINTF tOBRACE  tID tCBRACE { printf("Appel de printf sur %s\n", $3); } ;
133
+Invocation : tPRINTF tOBRACE tID tCBRACE { printf("Appel de printf sur %s\n", $3); } ;
122 134
 
123 135
 /*S : E tPV
124 136
 						{ printf("RES: %d\n", $1); }

+ 2
- 3
Lex_Yacc/comp.sh View File

@@ -1,5 +1,4 @@
1 1
 bison -d -t as.y -v
2 2
 flex al.lex 
3
-gcc *.c ../Symboles/table_symboles.c -ly
4
-cat ../Fichiers_Tests/progC | ./a.out 
5
-
3
+gcc as.tab.c lex.yy.c ../Symboles/tab_instruc.c ../Symboles/table_symboles.c -ll -o a.exe
4
+cat ./ProgC | ./a.exe

+ 44
- 37
Lex_Yacc/lex.yy.c View File

@@ -483,8 +483,15 @@ char *yytext;
483 483
 #line 2 "al.lex"
484 484
 #include "as.tab.h"
485 485
 int yywrap(void){return 1;}
486
-#line 487 "lex.yy.c"
487
-#line 488 "lex.yy.c"
486
+void
487
+yyerror (char const *s)
488
+{
489
+
490
+  fprintf (stderr, "%s\n", s);
491
+}
492
+
493
+#line 494 "lex.yy.c"
494
+#line 495 "lex.yy.c"
488 495
 
489 496
 #define INITIAL 0
490 497
 
@@ -701,10 +708,10 @@ YY_DECL
701 708
 		}
702 709
 
703 710
 	{
704
-#line 6 "al.lex"
711
+#line 13 "al.lex"
705 712
 
706 713
 
707
-#line 708 "lex.yy.c"
714
+#line 715 "lex.yy.c"
708 715
 
709 716
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
710 717
 		{
@@ -763,161 +770,161 @@ do_action:	/* This label is used only to access EOF actions. */
763 770
 
764 771
 case 1:
765 772
 YY_RULE_SETUP
766
-#line 8 "al.lex"
773
+#line 15 "al.lex"
767 774
 { return tMAIN ;} 
768 775
 	YY_BREAK
769 776
 case 2:
770 777
 YY_RULE_SETUP
771
-#line 9 "al.lex"
778
+#line 16 "al.lex"
772 779
 { return tOBRACKET;}
773 780
 	YY_BREAK
774 781
 case 3:
775 782
 YY_RULE_SETUP
776
-#line 10 "al.lex"
783
+#line 17 "al.lex"
777 784
 { return tCBRACKET; }
778 785
 	YY_BREAK
779 786
 case 4:
780 787
 YY_RULE_SETUP
781
-#line 11 "al.lex"
788
+#line 18 "al.lex"
782 789
 { return tOBRACE; }
783 790
 	YY_BREAK
784 791
 case 5:
785 792
 YY_RULE_SETUP
786
-#line 12 "al.lex"
793
+#line 19 "al.lex"
787 794
 { return tCBRACE; }
788 795
 	YY_BREAK
789 796
 case 6:
790 797
 YY_RULE_SETUP
791
-#line 13 "al.lex"
798
+#line 20 "al.lex"
792 799
 { return tCONST; }
793 800
 	YY_BREAK
794 801
 case 7:
795 802
 YY_RULE_SETUP
796
-#line 14 "al.lex"
803
+#line 21 "al.lex"
797 804
 { return tINT; }
798 805
 	YY_BREAK
799 806
 case 8:
800 807
 YY_RULE_SETUP
801
-#line 15 "al.lex"
808
+#line 22 "al.lex"
802 809
 { return tPRINTF; } //Degeu mais à degager
803 810
 	YY_BREAK
804 811
 case 9:
805 812
 YY_RULE_SETUP
806
-#line 16 "al.lex"
813
+#line 23 "al.lex"
807 814
 { return tIF; }
808 815
 	YY_BREAK
809 816
 case 10:
810 817
 YY_RULE_SETUP
811
-#line 17 "al.lex"
818
+#line 24 "al.lex"
812 819
 { return tWHILE; }
813 820
 	YY_BREAK
814 821
 case 11:
815 822
 YY_RULE_SETUP
816
-#line 18 "al.lex"
823
+#line 25 "al.lex"
817 824
 { return tLT; }
818 825
 	YY_BREAK
819 826
 case 12:
820 827
 YY_RULE_SETUP
821
-#line 19 "al.lex"
828
+#line 26 "al.lex"
822 829
 { return tGT; }
823 830
 	YY_BREAK
824 831
 case 13:
825 832
 YY_RULE_SETUP
826
-#line 20 "al.lex"
833
+#line 27 "al.lex"
827 834
 { return tEQCOND; }
828 835
 	YY_BREAK
829 836
 case 14:
830 837
 YY_RULE_SETUP
831
-#line 21 "al.lex"
838
+#line 28 "al.lex"
832 839
 { return tAND; }
833 840
 	YY_BREAK
834 841
 case 15:
835 842
 YY_RULE_SETUP
836
-#line 22 "al.lex"
843
+#line 29 "al.lex"
837 844
 { return tOR; }
838 845
 	YY_BREAK
839 846
 case 16:
840 847
 YY_RULE_SETUP
841
-#line 23 "al.lex"
848
+#line 30 "al.lex"
842 849
 { return tELSE;}
843 850
 	YY_BREAK
844 851
 case 17:
845 852
 YY_RULE_SETUP
846
-#line 26 "al.lex"
853
+#line 33 "al.lex"
847 854
 { yylval.nombre = atoi(yytext); return tNB; }
848 855
 	YY_BREAK
849 856
 case 18:
850 857
 YY_RULE_SETUP
851
-#line 27 "al.lex"
858
+#line 34 "al.lex"
852 859
 { yylval.nombre = -1; return tNBEXP; } //Renvoyer le token tNB et pas tNBEXP
853 860
 	YY_BREAK
854 861
 case 19:
855 862
 YY_RULE_SETUP
856
-#line 28 "al.lex"
863
+#line 35 "al.lex"
857 864
 { return tADD; }
858 865
 	YY_BREAK
859 866
 case 20:
860 867
 YY_RULE_SETUP
861
-#line 29 "al.lex"
868
+#line 36 "al.lex"
862 869
 { return tSUB; }
863 870
 	YY_BREAK
864 871
 case 21:
865 872
 YY_RULE_SETUP
866
-#line 30 "al.lex"
873
+#line 37 "al.lex"
867 874
 { return tMUL; }
868 875
 	YY_BREAK
869 876
 case 22:
870 877
 YY_RULE_SETUP
871
-#line 31 "al.lex"
878
+#line 38 "al.lex"
872 879
 { return tDIV; }
873 880
 	YY_BREAK
874 881
 case 23:
875 882
 YY_RULE_SETUP
876
-#line 32 "al.lex"
883
+#line 39 "al.lex"
877 884
 { return tEQ; }
878 885
 	YY_BREAK
879 886
 case 24:
880 887
 YY_RULE_SETUP
881
-#line 33 "al.lex"
888
+#line 40 "al.lex"
882 889
 { return tPV; }
883 890
 	YY_BREAK
884 891
 case 25:
885 892
 YY_RULE_SETUP
886
-#line 34 "al.lex"
893
+#line 41 "al.lex"
887 894
 {} //Ne pas les retourner à Yacc
888 895
 	YY_BREAK
889 896
 case 26:
890 897
 YY_RULE_SETUP
891
-#line 35 "al.lex"
898
+#line 42 "al.lex"
892 899
 {} //Ne pas les retourner à Yacc
893 900
 	YY_BREAK
894 901
 case 27:
895 902
 YY_RULE_SETUP
896
-#line 36 "al.lex"
903
+#line 43 "al.lex"
897 904
 { return tCOMA; }
898 905
 	YY_BREAK
899 906
 case 28:
900 907
 /* rule 28 can match eol */
901 908
 YY_RULE_SETUP
902
-#line 37 "al.lex"
909
+#line 44 "al.lex"
903 910
 {} //Ne pas les retourner à Yacc
904 911
 	YY_BREAK
905 912
 case 29:
906 913
 YY_RULE_SETUP
907
-#line 38 "al.lex"
914
+#line 45 "al.lex"
908 915
 { strcpy(yylval.id, yytext); return tID; }
909 916
 	YY_BREAK
910 917
 case 30:
911 918
 YY_RULE_SETUP
912
-#line 39 "al.lex"
919
+#line 46 "al.lex"
913 920
 { return tERROR; }
914 921
 	YY_BREAK
915 922
 case 31:
916 923
 YY_RULE_SETUP
917
-#line 41 "al.lex"
924
+#line 48 "al.lex"
918 925
 ECHO;
919 926
 	YY_BREAK
920
-#line 921 "lex.yy.c"
927
+#line 928 "lex.yy.c"
921 928
 case YY_STATE_EOF(INITIAL):
922 929
 	yyterminate();
923 930
 
@@ -1922,7 +1929,7 @@ void yyfree (void * ptr )
1922 1929
 
1923 1930
 #define YYTABLES_NAME "yytables"
1924 1931
 
1925
-#line 41 "al.lex"
1932
+#line 48 "al.lex"
1926 1933
 
1927 1934
 
1928 1935
 

BIN
Lex_Yacc/lex.yy.o View File


+ 0
- 0
Lex_Yacc/output.txt View File


+ 68
- 0
Symboles/tab_instruc.c View File

@@ -0,0 +1,68 @@
1
+#include "tab_instruc.h"
2
+int current_index = 0;
3
+struct operation_t tab_op[MAXTAILLE];
4
+
5
+void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3){
6
+	if (current_index == MAXTAILLE){
7
+		printf("Taillemax tableau operations atteinte\n");
8
+	}
9
+	else{
10
+		struct operation_t new_op = {opcode, arg1, arg2, arg3};
11
+		tab_op[current_index] = new_op;
12
+		current_index++;
13
+	}
14
+}
15
+
16
+
17
+
18
+char * get_asm_line_from_op(struct operation_t op){
19
+	char * buffer = malloc(sizeof(char)*200);
20
+	switch (op.opcode){
21
+		case (ADD):
22
+			sprintf(buffer,"ADD %d %d %d\n",op.arg1, op.arg2, op.arg3);
23
+			break;
24
+		case (MUL):
25
+			sprintf(buffer,"MUL %d %d %d\n",op.arg1, op.arg2, op.arg3);
26
+			break;
27
+		case (SOU):
28
+			sprintf(buffer,"SOU %d %d %d\n",op.arg1, op.arg2, op.arg3);
29
+			break;
30
+		case (DIV):
31
+			sprintf(buffer,"DIV %d %d %d\n",op.arg1, op.arg2, op.arg3);
32
+			break;
33
+		case (COP):
34
+			sprintf(buffer,"COP %d %d\n",op.arg1, op.arg2);
35
+			break;
36
+		case (AFC):
37
+			sprintf(buffer,"AFC %d %d\n",op.arg1, op.arg2);
38
+			break;
39
+		case (JMP):
40
+			sprintf(buffer,"JMP %d\n",op.arg1);
41
+			break;
42
+		case (JMF):
43
+			sprintf(buffer,"JMF %d %d\n",op.arg1, op.arg2);
44
+			break;
45
+		case (INF):
46
+			sprintf(buffer,"INF %d %d %d\n",op.arg1, op.arg2, op.arg3);
47
+			break;
48
+		case (SUP):
49
+			sprintf(buffer,"SUP %d %d %d\n",op.arg1, op.arg2, op.arg3);
50
+			break;
51
+		case (EQU):
52
+			sprintf(buffer,"DIV %d %d %d\n",op.arg1, op.arg2, op.arg3);
53
+			break;
54
+		case (PRI):
55
+			sprintf(buffer,"PRI %d\n",op.arg1);
56
+			break;
57
+	}
58
+	return buffer;
59
+}
60
+
61
+void create_asm(){
62
+	FILE * output = fopen("output.txt","w");
63
+	for (int i = 0; i < current_index; i++){
64
+		char * line = get_asm_line_from_op(tab_op[i]);
65
+		fputs(line, output);
66
+		free(line);
67
+	}
68
+}

+ 16
- 2
Symboles/tab_instruc.h View File

@@ -1,5 +1,19 @@
1
+#define MAXTAILLE 1024
2
+#include <stdlib.h>
3
+#include <string.h>
4
+#include <stdio.h>
1 5
 
2
-enum instructions_t {ADD,SUB}
3 6
 
7
+enum opcode_t {ADD,MUL,SOU,DIV,COP,AFC,JMP,JMF,INF,SUP,EQU,PRI};
4 8
 
5
-void add_operation(struct instructions_t inst, int * argv, int argv);
9
+struct operation_t {
10
+	enum opcode_t opcode;
11
+	int arg1;
12
+	int arg2;
13
+	int arg3;
14
+};
15
+
16
+extern struct operation_t tab_op[MAXTAILLE];
17
+
18
+void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3);
19
+void create_asm();

BIN
Symboles/tab_instruc.o View File


+ 30
- 5
Symboles/table_symboles.c View File

@@ -30,8 +30,12 @@ Opérations possible :
30 30
 #include <stdlib.h>
31 31
 #include <string.h>
32 32
 #include <stdio.h>
33
+#define MAXADDR 1024*5
33 34
 
34 35
 int last_addr = 0;
36
+int temp_addr = MAXADDR;
37
+int taille_types[] = {-1, 4};
38
+int profondeur = 0;
35 39
 
36 40
 struct element_t {
37 41
 	struct symbole_t symbole;
@@ -42,7 +46,6 @@ struct pile_t {
42 46
 	int taille;
43 47
 	struct element_t * first;
44 48
 };
45
-*
46 49
 struct pile_t * pile;
47 50
 
48 51
 char * type_to_string(enum type_t type) {
@@ -67,16 +70,21 @@ void init (void) {
67 70
 	pile->taille = 0;
68 71
 }
69 72
 
70
-void push(char * nom, int isInit, enum type_t type) {
73
+int push(char * nom, int isInit, enum type_t type) {
71 74
 	struct element_t * aux = malloc(sizeof(struct element_t));
75
+	struct symbole_t symbole = {"", last_addr, type, isInit,profondeur}; 
76
+	strcpy(symbole.nom,nom);
72 77
 	aux->symbole = symbole;
73 78
 	aux->suivant = pile->first;
74 79
 	pile->first = aux;
75 80
 	pile->taille++;
81
+	int addr_var = last_addr;
82
+	last_addr += taille_types[type]; 
83
+	return addr_var;
76 84
 }
77 85
 
78 86
 struct symbole_t pop() {
79
-	struct symbole_t retour = {"", 0, UNKNOWN, 0};
87
+	struct symbole_t retour = {"", 0, UNKNOWN, 0, 0};
80 88
 	struct element_t * aux;
81 89
 	if (pile->taille > 0) {
82 90
 		aux = pile->first;
@@ -84,6 +92,7 @@ struct symbole_t pop() {
84 92
 		retour = aux->symbole;
85 93
 		free(aux);
86 94
 		pile->taille--;
95
+		last_addr -= taille_types[retour.type]; 
87 96
 	}
88 97
 	return retour;
89 98
 }
@@ -107,13 +116,13 @@ char status(char * nom) {
107 116
 	return retour;
108 117
 }
109 118
 
110
-struct symbole_t * getVariable(char * nom){
119
+struct symbole_t * get_variable(char * nom){
111 120
 	struct symbole_t * retour = NULL;
112 121
 	struct element_t * aux = pile->first;
113 122
 	int i;
114 123
 	for (i=0; i < pile->taille; i++) {
115 124
 		if (!strcmp(nom, aux->symbole.nom)) {
116
-		    retour = element_t;
125
+		    retour = &aux->symbole;
117 126
 			break;
118 127
 		} else {
119 128
 			aux = aux->suivant;
@@ -135,3 +144,19 @@ void print() {
135 144
 		aux = aux->suivant;
136 145
 	}
137 146
 }
147
+
148
+
149
+int get_last_addr(){
150
+	return last_addr;
151
+}
152
+
153
+
154
+int allocate_mem_temp_var(enum type_t type){
155
+	temp_addr -= taille_types[type];
156
+	return temp_addr;
157
+}
158
+
159
+void reset_temp_vars(){
160
+	temp_addr = MAXADDR;
161
+}
162
+

+ 10
- 8
Symboles/table_symboles.h View File

@@ -28,9 +28,8 @@ Opérations possible :
28 28
 #include <stdint.h>
29 29
 
30 30
 enum type_t {UNKNOWN, INT};
31
-int taille_types[] = {-1, 4};
32
-
33
-char * tab_instructions[2] = {"ADD %d %d", "SUB %d %d"}
31
+extern int taille_types[];
32
+extern int profondeur;
34 33
 
35 34
 struct symbole_t {
36 35
 	char nom[30];
@@ -42,11 +41,14 @@ struct symbole_t {
42 41
 
43 42
 void print_symbole(struct symbole_t symbole);
44 43
 
45
-int profondeur = 0;
46 44
 
47 45
 void init(void);
48
-void push(struct symbole_t symbole, struct pile_t * pile);
49
-struct symbole_t pop(struct pile_t * pile);
46
+int push(char * nom, int isInit, enum type_t type);
47
+struct symbole_t pop();
50 48
 // renvoi 0 si nom n'existe pas, 2 si nom existe sans etre initialisée, 1 sinon
51
-char status(char * nom, struct pile_t * pile);
52
-void print(struct pile_t * pile);
49
+char status(char * nom);
50
+void print();
51
+int get_last_addr();
52
+struct symbole_t * get_variable(char * nom);
53
+int allocate_mem_temp_var(enum type_t type);
54
+void reset_temp_vars();

BIN
Symboles/table_symboles.o View File


Loading…
Cancel
Save