Browse Source

Dernieres modifs

Foussats Morgane 4 months ago
parent
commit
7d8e760392

+ 1967
- 0
compiler/analyse_syntaxique.output
File diff suppressed because it is too large
View File


+ 3
- 6
compiler/analyse_syntaxique.y View File

@@ -139,20 +139,19 @@ E : E tADD E {generate_instruction_3(&array, ADD, $1, $1, $3); free_temp(&table)
139 139
 E : E tMUL E {generate_instruction_3(&array, MUL, $1, $1, $3); free_temp(&table); $$ = $1;}  ;
140 140
 E : E tSUB E {generate_instruction_3(&array, SOU, $1, $1, $3); free_temp(&table); $$ = $1;} ;
141 141
 E : E tDIV E {generate_instruction_3(&array, DIV, $1, $1, $3); free_temp(&table); $$ = $1;} ;
142
-E : tSUB E {printf("Variable negative\n");} ;
142
+E : tSUB E {} ;
143 143
 E : Invocation {
144 144
 	//int vt = new_temp(&table);
145 145
 	//generate_instruction_2(&array, COP, vt, $1);
146 146
 	remove_symboles(&table);
147 147
 	table.depth--;
148 148
 	$$ = $1;};
149
-E : tPO E tPF {printf("Parenthèse\n"); $$ = $2; } ;
149
+E : tPO E tPF {$$ = $2; } ;
150 150
 E : tAPPERSAND tVAR {int vt = new_temp(&table); int varAddr = variable_exists(&table, $2); generate_instruction_2(&array, LEA, vt, varAddr); $$ = vt;};
151 151
 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;};
152 152
 
153 153
 
154 154
 If : tIF tPO Cond tPF {
155
-    //gen_jmpf(&table, &array, $3, -1);
156 155
     generate_instruction_2(&array, JMF, $3, -1);
157 156
     free_temp(&table);
158 157
     $1 = array.index;
@@ -162,7 +161,7 @@ tAO {table.depth++;} Instructions {generate_instruction_1(&array, JMP, -1);} tAF
162 161
     int adr_jmp = array.index;
163 162
     update_jmf(&array, $1, adr_jmp);
164 163
 }
165
-Else {printf("updating jump\n"); update_jmp(&array, $8, $13);};
164
+Else {update_jmp(&array, $8, $13);};
166 165
 
167 166
 Else : tELSE tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {$$ = array.index;} ;
168 167
 Else : {$$ = array.index;};
@@ -171,7 +170,6 @@ Else : tELSE If {$$ = array.index;} ;
171 170
 While : tWHILE tPO {
172 171
 	$2 = array.index ;
173 172
 } Cond tPF {
174
-	//gen_jmpf(&table, &array, $4, -1);
175 173
 	generate_instruction_2(&array, JMF, $4, -1);
176 174
 	free_temp(&table);
177 175
 	$1 = array.index;
@@ -179,7 +177,6 @@ While : tWHILE tPO {
179 177
 tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {
180 178
 	int adr_jmp = array.index;
181 179
 	update_jmf(&array, $1, adr_jmp);
182
-	//gen_jmpf(&table, &array, $1, $2);
183 180
 	generate_instruction_1(&array, JMP, $2);
184 181
 };
185 182
 

+ 16
- 13
compiler/code_c View File

@@ -1,16 +1,19 @@
1
-int fonction1(int * a){
2
-      int b = *a;
3
-      printf(b);
4
-      return 1;
5
-    }
1
+int fonction1(int * p){
2
+    int b = *p;
3
+    printf(b);
4
+    *p = 5;
5
+    return 2;
6
+}
6 7
 
7 8
 int main(){
8
-  int l = 21;
9
-  int * p = &l;
10
-  int c = fonction1(p);
11
-  printf(c);
12
-  p = &c;
13
-  *p = 2;
14
-  printf(c);
9
+    int a = 7;
10
+    int * pointeur = &a;
11
+    int c = fonction1(pointeur);
12
+    printf(c);
13
+    printf(*pointeur);
14
+    return 0;
15
+} 
16
+
17
+
18
+
15 19
 
16
-  return 0;

BIN
compiler/compiler View File


+ 7
- 8
compiler/memory_oriented_assembly.txt View File

@@ -1,12 +1,14 @@
1
-JMP 8
1
+JMP 10
2 2
 COP 255 0
3 3
 COP_LD 255 [255]
4 4
 COP 1 255
5 5
 COP 255 1
6 6
 PRI 255
7
-AFC 255 1
7
+AFC 255 5
8
+COP_STR [0] 255
9
+AFC 255 2
8 10
 RET 255
9
-AFC 255 21
11
+AFC 255 7
10 12
 COP 0 255
11 13
 LEA 255 0
12 14
 COP 1 255
@@ -16,11 +18,8 @@ CALL 1 6
16 18
 COP 2 255
17 19
 COP 255 2
18 20
 PRI 255
19
-LEA 255 2
20
-COP 1 255
21
-AFC 255 2
22
-COP_STR [1] 255
23
-COP 255 2
21
+COP 255 1
22
+COP_LD 255 [255]
24 23
 PRI 255
25 24
 AFC 255 0
26 25
 RET 255

+ 5
- 1
cross_assembleur/STD_LOGIC_VECTOR_output View File

@@ -1 +1,5 @@
1
-(0=>"00000111000000010000001000000000", 1=>"00000111000000100000001100000000", 2=>"00000001000000110000000100000010", 3=>"00001000000000010000001100000000", 4=>"00000111000000010000001000000000", 5=>"00000111000000100000001100000000", 6=>"00000011000000110000000100000010", 7=>"00001000000000010000001100000000", 8=>"00000111000000010000001000000000", 9=>"00001000000000010000000100000000", others => "00000000000000000000000000000000")
1
+(0=>"00000111000000010000001000000000", 1=>"00000111000000100000001100000000", 2=>"00000001000000110000000100000010", 3=>"00001000000000010000001100000000", 4=>"00000111000000010000001000000000", 5=>"00000111000000100000001100000000", 6=>"00000011000000110000000100000010", 7=>"00001000000000010000001100000000", 8=>"00000111000000010000001000000000", 9=>"00001000000000010000000100000000", others => "00000000000000000000000000000000")
2
+
3
+
4
+
5
+

BIN
cross_assembleur/cross_assembler View File


+ 5
- 1
cross_assembleur/cross_input.txt View File

@@ -1,3 +1,7 @@
1 1
 ADD 1 2 3
2 2
 SOU 1 2 3
3
-COP 1 2
3
+COP 1 2
4
+
5
+
6
+
7
+

+ 4
- 0
cross_assembleur/cross_output.txt View File

@@ -8,3 +8,7 @@
8 8
 8 1 3 0
9 9
 7 1 2 0
10 10
 8 1 1 0
11
+
12
+
13
+
14
+

BIN
interpreter/interpreter View File


+ 24
- 25
interpreter/interpreter_input.txt View File

@@ -1,26 +1,25 @@
1
-JMP 8
2
-COP 49 0
3
-COP_LD 49 [49]
4
-COP 1 49
5
-COP 49 1
6
-PRI 49
7
-AFC 49 1
8
-RET 49
9
-AFC 49 21
10
-COP 0 49
11
-LEA 49 0
12
-COP 1 49
13
-COP 49 1
14
-COP 5 49
1
+JMP 10
2
+COP 255 0
3
+COP_LD 255 [255]
4
+COP 1 255
5
+COP 255 1
6
+PRI 255
7
+AFC 255 5
8
+COP_STR [0] 255
9
+AFC 255 2
10
+RET 255
11
+AFC 255 7
12
+COP 0 255
13
+LEA 255 0
14
+COP 1 255
15
+COP 255 1
16
+COP 5 255
15 17
 CALL 1 6
16
-COP 2 49
17
-COP 49 2
18
-PRI 49
19
-LEA 49 2
20
-COP 1 49
21
-AFC 49 2
22
-COP_STR [1] 49
23
-COP 49 2
24
-PRI 49
25
-AFC 49 0
26
-RET 49
18
+COP 2 255
19
+COP 255 2
20
+PRI 255
21
+COP 255 1
22
+COP_LD 255 [255]
23
+PRI 255
24
+AFC 255 0
25
+RET 255

+ 8
- 6
interpreter/src/instructions.c View File

@@ -34,7 +34,7 @@ void asm_add_3(char ins, int arg1, int arg2, int arg3) {
34 34
     }
35 35
 
36 36
     // ip are validated at runtime; memory addr are validated here
37
-    if (ins == AFC || ins == JMF) {
37
+    if (ins == AFC || ins == JPF) {
38 38
         if (!valid_memory_addr(arg1)) {
39 39
             fprintf(stderr, "ERROR readfile : INVALID addr at line %d, please verify that addr is in range 0 to MAX_MEMORY_SIZE\n", current_line);
40 40
             has_error = 1;
@@ -120,9 +120,11 @@ int exec(int ip) {
120 120
     case JMP:
121 121
         printf("JMP to %d\n", arg1);
122 122
         next_ip = arg1; break;
123
-    case JMF:
124
-        printf("JMF cond@%d[%d] to %d\n", arg1, memory[arg1 + EBP], arg2);
125
-        if (memory[arg1 + EBP] == 0) next_ip = arg2;
123
+    case JPF:
124
+        printf("JPF cond@%d[%d] to %d\n", arg1, memory[arg1], arg2);
125
+        if (memory[arg1] != 0) {
126
+            next_ip = arg2;
127
+        }
126 128
         break;
127 129
     case LT:
128 130
         printf("LT @%d = @%d[%d] < @%d[%d] ? 1 : 0\n", arg1, arg2, memory[arg2], arg3, memory[arg3]);
@@ -173,10 +175,10 @@ int exec(int ip) {
173 175
         break;
174 176
     case COP_STR:
175 177
         printf("COP_STR @%d = @%d[%d]\n", arg1, arg2, memory[arg2]);
176
-        memory[memory[arg1]] = memory[arg2];
178
+        memory[arg1] = memory[arg2];
177 179
         break;
178 180
     case RET:
179
-        printf("RET @%d[%d] \n", arg1, memory[arg1 + EBP]);
181
+        printf("RET @%d[%d] \n", arg1, memory[arg1]);
180 182
         if (EBP != 0){
181 183
             next_ip = memory[EBP - 2];
182 184
             EBP = memory[EBP - 1];

+ 1
- 1
interpreter/src/instructions.h View File

@@ -8,7 +8,7 @@
8 8
 #define COP 5
9 9
 #define AFC 6
10 10
 #define JMP 7
11
-#define JMF 8
11
+#define JPF 8
12 12
 #define LT 9
13 13
 #define GT 10
14 14
 #define EQ 11

+ 1
- 1
interpreter/src/interpreter.l View File

@@ -13,7 +13,7 @@ DIV {return tDIV;}
13 13
 COP {return tCOP;}
14 14
 AFC {return tAFC;}
15 15
 JMP {return tJMP;}
16
-JMF {return tJMF;}
16
+JPF {return tJPF;}
17 17
 LT {return tLT;}
18 18
 LTE {return tLTE;}
19 19
 GT {return tGT;}

+ 3
- 3
interpreter/src/interpreter.y View File

@@ -12,7 +12,7 @@
12 12
     int nb;
13 13
 }
14 14
 
15
-%token tADD tMUL tSOU tDIV tCOP tAFC tJMP tJMF tPRI tRET tCALL
15
+%token tADD tMUL tSOU tDIV tCOP tAFC tJMP tJPF tPRI tRET tCALL
16 16
 %token tLT tLTE tGT tGTE tEQ tNEQ tAND tOR tNOT
17 17
 %token tLEA tCOP_LD tCOP_STR
18 18
 %token tOB tCB
@@ -45,8 +45,8 @@ Instruction:
45 45
         {asm_add_2(AFC, $2, $3);}
46 46
     | tJMP tNB
47 47
         {asm_add_1(JMP, $2);}
48
-    | tJMF tNB tNB
49
-        {asm_add_2(JMF, $2, $3);}
48
+    | tJPF tNB tNB
49
+        {asm_add_2(JPF, $2, $3);}
50 50
     | tLT tNB tNB tNB
51 51
         {asm_add_3(LT, $2, $3, $4);}
52 52
     | tGT tNB tNB tNB

Loading…
Cancel
Save