Dernieres modifs

This commit is contained in:
Foussats Morgane 2021-05-20 12:08:52 +02:00
parent db6969e20e
commit 7d8e760392
15 changed files with 2044 additions and 65 deletions

File diff suppressed because it is too large Load diff

View file

@ -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 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 : tSUB E {} ;
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 : 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 : 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;
@ -162,7 +161,7 @@ tAO {table.depth++;} Instructions {generate_instruction_1(&array, JMP, -1);} tAF
int adr_jmp = array.index;
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 : {$$ = array.index;};
@ -171,7 +170,6 @@ 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;
@ -179,7 +177,6 @@ While : tWHILE tPO {
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);
};

View file

@ -1,16 +1,19 @@
int fonction1(int * a){
int b = *a;
int fonction1(int * p){
int b = *p;
printf(b);
return 1;
}
*p = 5;
return 2;
}
int main(){
int l = 21;
int * p = &l;
int c = fonction1(p);
int a = 7;
int * pointeur = &a;
int c = fonction1(pointeur);
printf(c);
p = &c;
*p = 2;
printf(c);
printf(*pointeur);
return 0;
}

BIN
compiler/compiler Executable file

Binary file not shown.

View file

@ -1,12 +1,14 @@
JMP 8
JMP 10
COP 255 0
COP_LD 255 [255]
COP 1 255
COP 255 1
PRI 255
AFC 255 1
AFC 255 5
COP_STR [0] 255
AFC 255 2
RET 255
AFC 255 21
AFC 255 7
COP 0 255
LEA 255 0
COP 1 255
@ -16,11 +18,8 @@ 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
COP 255 1
COP_LD 255 [255]
PRI 255
AFC 255 0
RET 255

View file

@ -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")

BIN
cross_assembleur/cross_assembler Executable file

Binary file not shown.

View file

@ -1,3 +1,7 @@
ADD 1 2 3
SOU 1 2 3
COP 1 2

View file

@ -8,3 +8,7 @@
8 1 3 0
7 1 2 0
8 1 1 0

BIN
interpreter/interpreter Executable file

Binary file not shown.

View file

@ -1,26 +1,25 @@
JMP 8
COP 49 0
COP_LD 49 [49]
COP 1 49
COP 49 1
PRI 49
AFC 49 1
RET 49
AFC 49 21
COP 0 49
LEA 49 0
COP 1 49
COP 49 1
COP 5 49
JMP 10
COP 255 0
COP_LD 255 [255]
COP 1 255
COP 255 1
PRI 255
AFC 255 5
COP_STR [0] 255
AFC 255 2
RET 255
AFC 255 7
COP 0 255
LEA 255 0
COP 1 255
COP 255 1
COP 5 255
CALL 1 6
COP 2 49
COP 49 2
PRI 49
LEA 49 2
COP 1 49
AFC 49 2
COP_STR [1] 49
COP 49 2
PRI 49
AFC 49 0
RET 49
COP 2 255
COP 255 2
PRI 255
COP 255 1
COP_LD 255 [255]
PRI 255
AFC 255 0
RET 255

View file

@ -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
if (ins == AFC || ins == JMF) {
if (ins == AFC || ins == JPF) {
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);
has_error = 1;
@ -120,9 +120,11 @@ int exec(int ip) {
case JMP:
printf("JMP to %d\n", arg1);
next_ip = arg1; break;
case JMF:
printf("JMF cond@%d[%d] to %d\n", arg1, memory[arg1 + EBP], arg2);
if (memory[arg1 + EBP] == 0) next_ip = arg2;
case JPF:
printf("JPF cond@%d[%d] to %d\n", arg1, memory[arg1], arg2);
if (memory[arg1] != 0) {
next_ip = arg2;
}
break;
case LT:
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;
case COP_STR:
printf("COP_STR @%d = @%d[%d]\n", arg1, arg2, memory[arg2]);
memory[memory[arg1]] = memory[arg2];
memory[arg1] = memory[arg2];
break;
case RET:
printf("RET @%d[%d] \n", arg1, memory[arg1 + EBP]);
printf("RET @%d[%d] \n", arg1, memory[arg1]);
if (EBP != 0){
next_ip = memory[EBP - 2];
EBP = memory[EBP - 1];

View file

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

View file

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

View file

@ -12,7 +12,7 @@
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 tLEA tCOP_LD tCOP_STR
%token tOB tCB
@ -45,8 +45,8 @@ Instruction:
{asm_add_2(AFC, $2, $3);}
| tJMP tNB
{asm_add_1(JMP, $2);}
| tJMF tNB tNB
{asm_add_2(JMF, $2, $3);}
| tJPF tNB tNB
{asm_add_2(JPF, $2, $3);}
| tLT tNB tNB tNB
{asm_add_3(LT, $2, $3, $4);}
| tGT tNB tNB tNB