Dernieres modifs
This commit is contained in:
parent
db6969e20e
commit
7d8e760392
15 changed files with 2044 additions and 65 deletions
1967
compiler/analyse_syntaxique.output
Normal file
1967
compiler/analyse_syntaxique.output
Normal file
File diff suppressed because it is too large
Load diff
|
@ -139,20 +139,19 @@ E : E tADD E {generate_instruction_3(&array, ADD, $1, $1, $3); free_temp(&table)
|
||||||
E : E tMUL E {generate_instruction_3(&array, MUL, $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 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 : E tDIV E {generate_instruction_3(&array, DIV, $1, $1, $3); free_temp(&table); $$ = $1;} ;
|
||||||
E : tSUB E {printf("Variable negative\n");} ;
|
E : tSUB E {} ;
|
||||||
E : Invocation {
|
E : Invocation {
|
||||||
//int vt = new_temp(&table);
|
//int vt = new_temp(&table);
|
||||||
//generate_instruction_2(&array, COP, vt, $1);
|
//generate_instruction_2(&array, COP, vt, $1);
|
||||||
remove_symboles(&table);
|
remove_symboles(&table);
|
||||||
table.depth--;
|
table.depth--;
|
||||||
$$ = $1;};
|
$$ = $1;};
|
||||||
E : tPO E tPF {printf("Parenthèse\n"); $$ = $2; } ;
|
E : tPO E tPF {$$ = $2; } ;
|
||||||
E : tAPPERSAND tVAR {int vt = new_temp(&table); int varAddr = variable_exists(&table, $2); generate_instruction_2(&array, LEA, vt, varAddr); $$ = vt;};
|
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;};
|
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 {
|
If : tIF tPO Cond tPF {
|
||||||
//gen_jmpf(&table, &array, $3, -1);
|
|
||||||
generate_instruction_2(&array, JMF, $3, -1);
|
generate_instruction_2(&array, JMF, $3, -1);
|
||||||
free_temp(&table);
|
free_temp(&table);
|
||||||
$1 = array.index;
|
$1 = array.index;
|
||||||
|
@ -162,7 +161,7 @@ tAO {table.depth++;} Instructions {generate_instruction_1(&array, JMP, -1);} tAF
|
||||||
int adr_jmp = array.index;
|
int adr_jmp = array.index;
|
||||||
update_jmf(&array, $1, adr_jmp);
|
update_jmf(&array, $1, adr_jmp);
|
||||||
}
|
}
|
||||||
Else {printf("updating jump\n"); update_jmp(&array, $8, $13);};
|
Else {update_jmp(&array, $8, $13);};
|
||||||
|
|
||||||
Else : tELSE tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {$$ = array.index;} ;
|
Else : tELSE tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {$$ = array.index;} ;
|
||||||
Else : {$$ = array.index;};
|
Else : {$$ = array.index;};
|
||||||
|
@ -171,7 +170,6 @@ Else : tELSE If {$$ = array.index;} ;
|
||||||
While : tWHILE tPO {
|
While : tWHILE tPO {
|
||||||
$2 = array.index ;
|
$2 = array.index ;
|
||||||
} Cond tPF {
|
} Cond tPF {
|
||||||
//gen_jmpf(&table, &array, $4, -1);
|
|
||||||
generate_instruction_2(&array, JMF, $4, -1);
|
generate_instruction_2(&array, JMF, $4, -1);
|
||||||
free_temp(&table);
|
free_temp(&table);
|
||||||
$1 = array.index;
|
$1 = array.index;
|
||||||
|
@ -179,7 +177,6 @@ While : tWHILE tPO {
|
||||||
tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {
|
tAO {table.depth++;} Instructions tAF {remove_symboles(&table); table.depth--;} {
|
||||||
int adr_jmp = array.index;
|
int adr_jmp = array.index;
|
||||||
update_jmf(&array, $1, adr_jmp);
|
update_jmf(&array, $1, adr_jmp);
|
||||||
//gen_jmpf(&table, &array, $1, $2);
|
|
||||||
generate_instruction_1(&array, JMP, $2);
|
generate_instruction_1(&array, JMP, $2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
int fonction1(int * a){
|
int fonction1(int * p){
|
||||||
int b = *a;
|
int b = *p;
|
||||||
printf(b);
|
printf(b);
|
||||||
return 1;
|
*p = 5;
|
||||||
}
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
int l = 21;
|
int a = 7;
|
||||||
int * p = &l;
|
int * pointeur = &a;
|
||||||
int c = fonction1(p);
|
int c = fonction1(pointeur);
|
||||||
printf(c);
|
printf(c);
|
||||||
p = &c;
|
printf(*pointeur);
|
||||||
*p = 2;
|
return 0;
|
||||||
printf(c);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
BIN
compiler/compiler
Executable file
BIN
compiler/compiler
Executable file
Binary file not shown.
|
@ -1,12 +1,14 @@
|
||||||
JMP 8
|
JMP 10
|
||||||
COP 255 0
|
COP 255 0
|
||||||
COP_LD 255 [255]
|
COP_LD 255 [255]
|
||||||
COP 1 255
|
COP 1 255
|
||||||
COP 255 1
|
COP 255 1
|
||||||
PRI 255
|
PRI 255
|
||||||
AFC 255 1
|
AFC 255 5
|
||||||
|
COP_STR [0] 255
|
||||||
|
AFC 255 2
|
||||||
RET 255
|
RET 255
|
||||||
AFC 255 21
|
AFC 255 7
|
||||||
COP 0 255
|
COP 0 255
|
||||||
LEA 255 0
|
LEA 255 0
|
||||||
COP 1 255
|
COP 1 255
|
||||||
|
@ -16,11 +18,8 @@ CALL 1 6
|
||||||
COP 2 255
|
COP 2 255
|
||||||
COP 255 2
|
COP 255 2
|
||||||
PRI 255
|
PRI 255
|
||||||
LEA 255 2
|
COP 255 1
|
||||||
COP 1 255
|
COP_LD 255 [255]
|
||||||
AFC 255 2
|
|
||||||
COP_STR [1] 255
|
|
||||||
COP 255 2
|
|
||||||
PRI 255
|
PRI 255
|
||||||
AFC 255 0
|
AFC 255 0
|
||||||
RET 255
|
RET 255
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
(0=>"00000111000000010000001000000000", 1=>"00000111000000100000001100000000", 2=>"00000001000000110000000100000010", 3=>"00001000000000010000001100000000", 4=>"00000111000000010000001000000000", 5=>"00000111000000100000001100000000", 6=>"00000011000000110000000100000010", 7=>"00001000000000010000001100000000", 8=>"00000111000000010000001000000000", 9=>"00001000000000010000000100000000", others => "00000000000000000000000000000000")
|
(0=>"00000111000000010000001000000000", 1=>"00000111000000100000001100000000", 2=>"00000001000000110000000100000010", 3=>"00001000000000010000001100000000", 4=>"00000111000000010000001000000000", 5=>"00000111000000100000001100000000", 6=>"00000011000000110000000100000010", 7=>"00001000000000010000001100000000", 8=>"00000111000000010000001000000000", 9=>"00001000000000010000000100000000", others => "00000000000000000000000000000000")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
cross_assembleur/cross_assembler
Executable file
BIN
cross_assembleur/cross_assembler
Executable file
Binary file not shown.
|
@ -1,3 +1,7 @@
|
||||||
ADD 1 2 3
|
ADD 1 2 3
|
||||||
SOU 1 2 3
|
SOU 1 2 3
|
||||||
COP 1 2
|
COP 1 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,7 @@
|
||||||
8 1 3 0
|
8 1 3 0
|
||||||
7 1 2 0
|
7 1 2 0
|
||||||
8 1 1 0
|
8 1 1 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
interpreter/interpreter
Executable file
BIN
interpreter/interpreter
Executable file
Binary file not shown.
|
@ -1,26 +1,25 @@
|
||||||
JMP 8
|
JMP 10
|
||||||
COP 49 0
|
COP 255 0
|
||||||
COP_LD 49 [49]
|
COP_LD 255 [255]
|
||||||
COP 1 49
|
COP 1 255
|
||||||
COP 49 1
|
COP 255 1
|
||||||
PRI 49
|
PRI 255
|
||||||
AFC 49 1
|
AFC 255 5
|
||||||
RET 49
|
COP_STR [0] 255
|
||||||
AFC 49 21
|
AFC 255 2
|
||||||
COP 0 49
|
RET 255
|
||||||
LEA 49 0
|
AFC 255 7
|
||||||
COP 1 49
|
COP 0 255
|
||||||
COP 49 1
|
LEA 255 0
|
||||||
COP 5 49
|
COP 1 255
|
||||||
|
COP 255 1
|
||||||
|
COP 5 255
|
||||||
CALL 1 6
|
CALL 1 6
|
||||||
COP 2 49
|
COP 2 255
|
||||||
COP 49 2
|
COP 255 2
|
||||||
PRI 49
|
PRI 255
|
||||||
LEA 49 2
|
COP 255 1
|
||||||
COP 1 49
|
COP_LD 255 [255]
|
||||||
AFC 49 2
|
PRI 255
|
||||||
COP_STR [1] 49
|
AFC 255 0
|
||||||
COP 49 2
|
RET 255
|
||||||
PRI 49
|
|
||||||
AFC 49 0
|
|
||||||
RET 49
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ void asm_add_3(char ins, int arg1, int arg2, int arg3) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ip are validated at runtime; memory addr are validated here
|
// ip are validated at runtime; memory addr are validated here
|
||||||
if (ins == AFC || ins == JMF) {
|
if (ins == AFC || ins == JPF) {
|
||||||
if (!valid_memory_addr(arg1)) {
|
if (!valid_memory_addr(arg1)) {
|
||||||
fprintf(stderr, "ERROR readfile : INVALID addr at line %d, please verify that addr is in range 0 to MAX_MEMORY_SIZE\n", current_line);
|
fprintf(stderr, "ERROR readfile : INVALID addr at line %d, please verify that addr is in range 0 to MAX_MEMORY_SIZE\n", current_line);
|
||||||
has_error = 1;
|
has_error = 1;
|
||||||
|
@ -120,9 +120,11 @@ int exec(int ip) {
|
||||||
case JMP:
|
case JMP:
|
||||||
printf("JMP to %d\n", arg1);
|
printf("JMP to %d\n", arg1);
|
||||||
next_ip = arg1; break;
|
next_ip = arg1; break;
|
||||||
case JMF:
|
case JPF:
|
||||||
printf("JMF cond@%d[%d] to %d\n", arg1, memory[arg1 + EBP], arg2);
|
printf("JPF cond@%d[%d] to %d\n", arg1, memory[arg1], arg2);
|
||||||
if (memory[arg1 + EBP] == 0) next_ip = arg2;
|
if (memory[arg1] != 0) {
|
||||||
|
next_ip = arg2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case LT:
|
case LT:
|
||||||
printf("LT @%d = @%d[%d] < @%d[%d] ? 1 : 0\n", arg1, arg2, memory[arg2], arg3, memory[arg3]);
|
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) {
|
||||||
break;
|
break;
|
||||||
case COP_STR:
|
case COP_STR:
|
||||||
printf("COP_STR @%d = @%d[%d]\n", arg1, arg2, memory[arg2]);
|
printf("COP_STR @%d = @%d[%d]\n", arg1, arg2, memory[arg2]);
|
||||||
memory[memory[arg1]] = memory[arg2];
|
memory[arg1] = memory[arg2];
|
||||||
break;
|
break;
|
||||||
case RET:
|
case RET:
|
||||||
printf("RET @%d[%d] \n", arg1, memory[arg1 + EBP]);
|
printf("RET @%d[%d] \n", arg1, memory[arg1]);
|
||||||
if (EBP != 0){
|
if (EBP != 0){
|
||||||
next_ip = memory[EBP - 2];
|
next_ip = memory[EBP - 2];
|
||||||
EBP = memory[EBP - 1];
|
EBP = memory[EBP - 1];
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#define COP 5
|
#define COP 5
|
||||||
#define AFC 6
|
#define AFC 6
|
||||||
#define JMP 7
|
#define JMP 7
|
||||||
#define JMF 8
|
#define JPF 8
|
||||||
#define LT 9
|
#define LT 9
|
||||||
#define GT 10
|
#define GT 10
|
||||||
#define EQ 11
|
#define EQ 11
|
||||||
|
|
|
@ -13,7 +13,7 @@ DIV {return tDIV;}
|
||||||
COP {return tCOP;}
|
COP {return tCOP;}
|
||||||
AFC {return tAFC;}
|
AFC {return tAFC;}
|
||||||
JMP {return tJMP;}
|
JMP {return tJMP;}
|
||||||
JMF {return tJMF;}
|
JPF {return tJPF;}
|
||||||
LT {return tLT;}
|
LT {return tLT;}
|
||||||
LTE {return tLTE;}
|
LTE {return tLTE;}
|
||||||
GT {return tGT;}
|
GT {return tGT;}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
int nb;
|
int nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
%token tADD tMUL tSOU tDIV tCOP tAFC tJMP tJMF tPRI tRET tCALL
|
%token tADD tMUL tSOU tDIV tCOP tAFC tJMP tJPF tPRI tRET tCALL
|
||||||
%token tLT tLTE tGT tGTE tEQ tNEQ tAND tOR tNOT
|
%token tLT tLTE tGT tGTE tEQ tNEQ tAND tOR tNOT
|
||||||
%token tLEA tCOP_LD tCOP_STR
|
%token tLEA tCOP_LD tCOP_STR
|
||||||
%token tOB tCB
|
%token tOB tCB
|
||||||
|
@ -45,8 +45,8 @@ Instruction:
|
||||||
{asm_add_2(AFC, $2, $3);}
|
{asm_add_2(AFC, $2, $3);}
|
||||||
| tJMP tNB
|
| tJMP tNB
|
||||||
{asm_add_1(JMP, $2);}
|
{asm_add_1(JMP, $2);}
|
||||||
| tJMF tNB tNB
|
| tJPF tNB tNB
|
||||||
{asm_add_2(JMF, $2, $3);}
|
{asm_add_2(JPF, $2, $3);}
|
||||||
| tLT tNB tNB tNB
|
| tLT tNB tNB tNB
|
||||||
{asm_add_3(LT, $2, $3, $4);}
|
{asm_add_3(LT, $2, $3, $4);}
|
||||||
| tGT tNB tNB tNB
|
| tGT tNB tNB tNB
|
||||||
|
|
Loading…
Reference in a new issue