Merge branch 'master' of dwarves.iut-fbleau.fr:foucher/SAE12_2021

This commit is contained in:
2021-12-17 18:47:47 +01:00

View File

@@ -4,7 +4,15 @@
#include"mars_types.h" /* importe les types utilisés dans le programme */
#include"options.h" /* Inclus les options du programme */
int verif_instru(char* instru, char* arg1, char* arg2){ /* vérifie les instructions */
printf("%s %s %s", instru, arg1, arg2);
}
int ouvrir_fichier(char* path){
union mars_instruction toto;
FILE* fluxouverture;
char instru[4];
char arg1[4], arg2[4];
@@ -12,6 +20,8 @@ int ouvrir_fichier(char* path){
int i;
int ligne=0;
char buffer[4];
char verifarg1[1], verifarg2[1];
int flagverif1, flagverif2;
char previnstru[4]; // contient l'instruction ayant été "mal interprétée" à cause d'une instruction mauvaise
int errinstru; // flag qui aide le prog à savoir si l'instruction précédente était mauvaise
@@ -28,21 +38,16 @@ int ouvrir_fichier(char* path){
if (fluxouverture){
while (!feof(fluxouverture)){
instru[0]='\0';
arg1[0]='\0';
arg2[0]='\0';
instru[0]='\0';
arg1[0]='\0';
arg2[0]='\0';
printf("\n");
/*fread(&instru,sizeof(char),1,fluxouverture);
fread(&arg1,sizeof(char),3,fluxouverture);
fread(&arg2,sizeof(char),3,fluxouverture);
printf("%s %s %s\n", instru, arg1, arg2);*/
fscanf(fluxouverture, "%s %s %s", instru, arg1, arg2);
fscanf(fluxouverture, "%4s %4s %4s", instru, arg1, arg2);
for (i=0; i<strlen(instru); i++){
printf("%c", instru[i]);
/*printf("%c", instru[i]);*/
}
printf(" ");
@@ -57,20 +62,24 @@ int ouvrir_fichier(char* path){
if (!feof(fluxouverture) || !strcmp(arg1, buffer)==0){
if (strcmp(arg1, "MOV")==0 || strcmp(arg1, "ADD")==0 || strcmp(arg1, "SUB")==0 || strcmp(arg1, "JMP")==0 || strcmp(arg1, "JMZ")==0 || strcmp(arg1, "JMG")==0 || strcmp(arg1, "DJZ")==0 || strcmp(arg1, "CMP")==0 || strcmp(arg1, "DAT")==0){
printf("\n");
fseek(fluxouverture, -1, SEEK_CUR);
/*printf("\n");*/
printf("test");
arg1[0]='\0';
fseek(fluxouverture, -2, SEEK_CUR);
for (i=0; i<strlen(arg1); i++){
previnstru[i]=arg1[i];
printf("%c", previnstru[i]);
/*verif_instru(previnstru, arg1, arg2);*/
errinstru=1;
/*printf("%c", previnstru[i]);*/
}
} else if (strcmp(arg1, "MOV")!=0 || strcmp(arg1, "ADD")!=0 || strcmp(arg1, "SUB")!=0 || strcmp(arg1, "JMP")!=0 || strcmp(arg1, "JMZ")!=0 || strcmp(arg1, "JMG")!=0 || strcmp(arg1, "DJZ")!=0 || strcmp(arg1, "CMP")!=0 || strcmp(arg1, "DAT")!=0) {
for (i=0; i<strlen(arg1); i++){
printf("%c", arg1[i]);
/*printf("%c", arg1[i]);*/
}
printf(" ");
} else {
printf("\n");
/*printf("\n");*/
}
}
@@ -81,20 +90,90 @@ int ouvrir_fichier(char* path){
if (!feof(fluxouverture) || !strcmp(arg2, buffer)==0){
if (strcmp(arg2, "MOV")==0 || strcmp(arg2, "ADD")==0 || strcmp(arg2, "SUB")==0 || strcmp(arg2, "JMP")==0 || strcmp(arg2, "JMZ")==0 || strcmp(arg2, "JMG")==0 || strcmp(arg2, "DJZ")==0 || strcmp(arg2, "CMP")==0 || strcmp(arg2, "DAT")==0){
arg2[0]='\0';
fseek(fluxouverture, -3, SEEK_CUR);
} else if (strcmp(arg2, "MOV")!=0 || strcmp(arg2, "ADD")!=0 || strcmp(arg2, "SUB")!=0 || strcmp(arg2, "JMP")!=0 || strcmp(arg2, "JMZ")!=0 || strcmp(arg2, "JMG")!=0 || strcmp(arg2, "DJZ")!=0 || strcmp(arg2, "CMP")!=0 || strcmp(arg2, "DAT")!=0) {
for (i=0; i<strlen(arg2); i++){
printf("%c", arg2[i]);
/*printf("%c", arg2[i]);*/
}
} else {
printf("\n");
/*printf("\n");*/
}
verifarg1[0]=arg1[0]; /* marche pas comme je le pensais :/ */
verifarg2[0]=arg2[0]; /* marche pas comme je le pensais :/ */
if(errinstru!=1){
verif_instru(instru, arg1, arg2);
}
errinstru=0;
// return de la fonction si pas d'erreur
// instru / arg1 / arg2
// return de la fonction si erreur
// previnstru / arg1 / arg2 ?
if (strcmp(instru, "MOV")==0){
toto.instruct.codeOp =MOV;
}
if (strcmp(instru, "ADD")==0){
toto.instruct.codeOp =ADD;
}
if (strcmp(instru, "SUB")==0){
toto.instruct.codeOp =SUB;
}
if (strcmp(instru, "JMP")==0){
toto.instruct.codeOp =JMP;
}
if (strcmp(instru, "JMZ")==0){
toto.instruct.codeOp =JMZ;
}
if (strcmp(instru, "JMG")==0){
toto.instruct.codeOp =JMG;
}
if (strcmp(instru, "DJZ")==0){
toto.instruct.codeOp =DJZ;
}
if (strcmp(instru, "CMP")==0){
toto.instruct.codeOp =CMP;
}
if (strcmp(instru, "DAT")==0){
toto.instruct.codeOp =DAT;
}
/*
commentaire pour la réflexion à avoir mais pas réussi à passer en code
toto.instruct.modeAddrA=DIRECT;
toto.instruct.modeAddrB=DIRECT;
if strcmp(arg1[0], "@")==0{
toto.instruct.modeAddrA=INDIRECT;
}
if strcmp(arg1[0], "#")==0{
toto.instruct.modeAddrA=IMMEDIAT;
}
if strcmp(arg2[0], "@")==0{
toto.instruct.modeAddrB=INDIRECT;
}
if strcmp(arg2[0], "#")==0{
toto.instruct.modeAddrB=IMMEDIAT;
}
toto.instruct.ArgA = arg1; mais sans le mode adressage
toto.instruct.ArgB = arg2; idem
*/
}
}