void main( int argc, char *argv[], char *envp[]) { int32_t i, j; for(i = 0; i < NUMOPCODES - 1; i++){ printf("\t%s\t", m88k_opcodes[i].name); if(m88k_opcodes[i].op[0].type == NIL) printf("\n"); for(j = 0; j < 3 && m88k_opcodes[i].op[j].type != NIL; j++){ switch(m88k_opcodes[i].op[j].type){ case CNST: #ifdef SIGNED_IMMEDIATES case SCNST: #endif printf("0x%04x", cnst() ); break; case REG: printf("r%d", reg() ); break; case BF: printf("%d<%d>", reg(), reg() ); break; case REGSC: printf("[r%d]", reg() ); break; case CRREG: printf("cr%d", creg() ); break; case FCRREG: printf("fcr%d", creg() ); break; case PCREL: printf("undef"); break; case CONDMASK: print_cond(); break; case CMPRSLT: print_cmp(); break; case ROT: printf("<%d>", reg() ); break; case E4ROT: printf("<%d>", creg() & ~0x3); break; case EREG: printf("r%d", reg() & ~0x1); break; case XREG: printf("x%d", reg()); break; } if(j == 2 || m88k_opcodes[i].op[j+1].type == NIL) printf("\n"); else if(m88k_opcodes[i].op[j+1].type != REGSC) printf(","); } } }
/* Print statments in proc */ void print_stmt(Stmt stmt, char* proc_id) { // Print based on statement kind switch (stmt->kind) { case STMT_ASSIGN: print_assign(stmt->info.assign, proc_id); break; case STMT_ASSIGN_ARRAY: print_assign_array(stmt->info.assign, stmt->info.assign.exprs, proc_id); break; case STMT_COND:{ printf("#if\n"); // Form label char ifCountStr[15]; char str[80]; if (stmt->info.cond.else_branch != NULL) { sprintf(ifCountStr, "%d", ifcount); strcpy (str,"else_"); strcat (str,ifCountStr); } else { sprintf(ifCountStr, "%d", ifcount); strcpy (str,"end_if_"); strcat (str,ifCountStr); } int currentIfCount = ifcount; ifcount++; // print conditions of if statment print_cond(stmt->info.cond.cond, proc_id, 0, 0, str, ""); // Print then statements print_stmts(stmt->info.cond.then_branch, proc_id); // Print labels char endIfLabel[80]; char currCountStr[15]; sprintf(currCountStr, "%d", currentIfCount); strcpy (endIfLabel,"end_if_"); strcat (endIfLabel,currCountStr); // Print else statements if (stmt->info.cond.else_branch != NULL) { // Branch unconditional printf("branch_uncond %s\n", endIfLabel); // Do False printf("%s:\n", str); print_stmts(stmt->info.cond.else_branch, proc_id); } // print label printf("%s:\n", endIfLabel); printf("\n"); break; } case STMT_WHILE:{ // Print start of while label printf("#while\n"); char whileStr[15]; sprintf(whileStr, "%d", loopcount); char top[80]; strcpy (top,"top_of_loop_"); strcat (top,whileStr); char loopbreak[80]; strcpy (loopbreak,"loop_is_false_"); strcat (loopbreak,whileStr); int currentLoopCount = loopcount; loopcount++; // print while condition print_cond(stmt->info.loop.cond, proc_id, 0, 1, top, loopbreak); // Print statements print_stmts(stmt->info.loop.body, proc_id); // Print unconditional branch printf("branch_uncond %s\n", top); // Print end loop label printf("%s:\n", loopbreak); printf("\n"); break; } case STMT_READ: print_read(stmt, proc_id); break; case STMT_READ_ARRAY: print_read_array(stmt, proc_id); break; case STMT_WRITE: print_write(stmt, proc_id); break; case STMT_FNCALL: print_fncall(stmt, proc_id); break; } }