final conditions and loops tested

This commit is contained in:
Raphaël LACROIX 2023-04-20 11:48:47 +02:00
parent ff74c5be44
commit c34150e026
5 changed files with 43 additions and 18 deletions

View file

@ -74,12 +74,12 @@ void displayASMTable(){
for (int i = 0; i < lineCounter; ++i) { for (int i = 0; i < lineCounter; ++i) {
ASMLine a = asmTable[i]; ASMLine a = asmTable[i];
if(a.jumpLine == -1) { if(a.jumpLine == -1) {
printf("%d | %s", i, a.name); printf("%d | %s\n", i, a.name);
} else { } else {
if(a.conditionAddr == -1) { if(a.conditionAddr == -1) {
printf("%d | %s @%d\n", i, a.name,a.jumpLine); printf("%d | %s %d\n", i, a.name,a.jumpLine);
} else { } else {
printf("%d | %s @%d @%d\n", i, a.name,a.conditionAddr,a.jumpLine); printf("%d | %s %d %d\n", i, a.name,a.conditionAddr,a.jumpLine);
} }
} }
if (i != lineCounter -1) { if (i != lineCounter -1) {
@ -88,3 +88,22 @@ void displayASMTable(){
} }
doubleLine(); doubleLine();
} }
/*exports the entire table to asm*/
void exportASMTable(){
FILE* fp;
fp = fopen("asm", "a");
for (int i = 0; i < lineCounter; ++i) {
ASMLine a = asmTable[i];
if(a.jumpLine == -1) {
fprintf(fp,"%s\n",i, a.name);
} else {
if(a.conditionAddr == -1) {
fprintf(fp,"%s %d\n",i, a.name,a.jumpLine);
} else {
fprintf(fp,"%s %d %d\n",i, a.name,a.conditionAddr,a.jumpLine);
}
}
}
fclose(fp);
}

View file

@ -40,8 +40,9 @@ void setConditionAddr(int index, int addr);
/*returns the current line (i.e. next one to insert)*/ /*returns the current line (i.e. next one to insert)*/
int getCurrentLineNumber(); int getCurrentLineNumber();
/*displays the entire table at this moment*/ /*displays the entire table at this moment*/
void displayASMTable(); void displayASMTable();
/*exports the entire table to asm*/
void exportASMTable();
#endif //PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H #endif //PROJET_SYSTEMES_INFORMATIQUES_ASMTABLE_H

View file

@ -30,7 +30,7 @@ void clearOp(){
int operation_add(int addr1, int addr2){ int operation_add(int addr1, int addr2){
int addr = addTempINTAndGetAddress(); int addr = addTempINTAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "ADD @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "ADD %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -40,7 +40,7 @@ int operation_add(int addr1, int addr2){
int operation_sub(int addr1, int addr2){ int operation_sub(int addr1, int addr2){
int addr = addTempINTAndGetAddress(); int addr = addTempINTAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "SUB @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "SUB %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -50,7 +50,7 @@ int operation_sub(int addr1, int addr2){
int operation_mul(int addr1, int addr2){ int operation_mul(int addr1, int addr2){
int addr = addTempINTAndGetAddress(); int addr = addTempINTAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "MUL @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "MUL %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -60,7 +60,7 @@ int operation_mul(int addr1, int addr2){
int operation_divInt(int addr1, int addr2){ int operation_divInt(int addr1, int addr2){
int addr = addTempINTAndGetAddress(); int addr = addTempINTAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "DIV_INT @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "DIV_INT %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -70,7 +70,7 @@ int operation_divInt(int addr1, int addr2){
int operation_divRem(int addr1, int addr2){ int operation_divRem(int addr1, int addr2){
int addr = addTempINTAndGetAddress(); int addr = addTempINTAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "DIV_REM @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "DIV_REM %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -81,7 +81,7 @@ int operation_divRem(int addr1, int addr2){
*/ */
void operation_afc_nb(int addr, int value){ void operation_afc_nb(int addr, int value){
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "AFC @%d #%d\n", addr, value); sprintf(s, "AFC %d %d", addr, value);
printOp(s); printOp(s);
} }
@ -102,7 +102,7 @@ int operation_afc_nb_tmp(int value){
*/ */
void operation_copy(int addr1, int addr2){ void operation_copy(int addr1, int addr2){
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "COP @%d @%d\n", addr1, addr2); sprintf(s, "COP %d %d", addr1, addr2);
printOp(s); printOp(s);
} }
@ -111,7 +111,7 @@ void operation_copy(int addr1, int addr2){
int cond_inf(int addr1, int addr2){ int cond_inf(int addr1, int addr2){
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "INF @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "INF %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -121,7 +121,7 @@ int cond_inf(int addr1, int addr2){
int cond_sup(int addr1, int addr2){ int cond_sup(int addr1, int addr2){
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "SUP @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "SUP %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -131,7 +131,7 @@ int cond_sup(int addr1, int addr2){
int cond_eq(int addr1, int addr2) { int cond_eq(int addr1, int addr2) {
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "EQU @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "EQU %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -141,7 +141,7 @@ int cond_eq(int addr1, int addr2) {
int cond_not(int addr1){ int cond_not(int addr1){
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "NOT @%d @%d\n", addr, addr1); sprintf(s, "NOT %d %d", addr, addr1);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -151,7 +151,7 @@ int cond_not(int addr1){
int cond_and(int addr1, int addr2){ int cond_and(int addr1, int addr2){
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "AND @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "AND %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }
@ -161,7 +161,7 @@ int cond_and(int addr1, int addr2){
int cond_or(int addr1, int addr2){ int cond_or(int addr1, int addr2){
int addr = addTempCONDAndGetAddress(); int addr = addTempCONDAndGetAddress();
char s[ASM_TEXT_LEN]; char s[ASM_TEXT_LEN];
sprintf(s, "OR @%d @%d @%d\n", addr, addr1, addr2); sprintf(s, "OR %d %d %d", addr, addr1, addr2);
printOp(s); printOp(s);
return addr; return addr;
} }

View file

@ -58,6 +58,10 @@ Symbol getStruct(char* name){
return symbolTable[i]; return symbolTable[i];
} }
} }
if (VERBOSITY) {
printf("\n\n%s not found \n\n", name);
displayTable();
}
error("No structure found"); error("No structure found");
return (createNewStructure("error", 0)); return (createNewStructure("error", 0));
} }

3
yacc.y
View file

@ -116,7 +116,7 @@ IfStatement1 : %empty {
}; };
IfStatement : tIF Condition IfStatement1 InnerBlock tELSE { IfStatement : tIF Condition IfStatement1 InnerBlock tELSE {
int current = getCurrentLineNumber(); printf("current Line %d", current); addLine("JMP"); $1 = current; setJumpLine($3, current+1); setConditionAddr($3,$2); int current = getCurrentLineNumber(); printf("current Line %d", current); addLine("JMP"); $1 = current; setJumpLine($3, current+1);
} InnerBlock { } InnerBlock {
int current = getCurrentLineNumber() ; printf("%d, %d",$1, current);setJumpLine($1, current); int current = getCurrentLineNumber() ; printf("%d, %d",$1, current);setJumpLine($1, current);
} }
@ -204,5 +204,6 @@ int main(void) {
initSymbolTable(); initSymbolTable();
initASMTable(); initASMTable();
yyparse(); yyparse();
exportASMTable();
} }
// SI >> SC // SI >> SC