bool CMipsInstruction::Load(char* Name, char* Params) { bool paramfail = false; NoCheckError = false; for (int z = 0; MipsOpcodes[z].name != NULL; z++) { if (MipsOpcodes[z].ver & Mips.GetVersion()) { if (parseOpcode(MipsOpcodes[z],Name) == true) { if (LoadEncoding(MipsOpcodes[z],Params) == true) { Loaded = true; return true; } paramfail = true; } } } if (NoCheckError == false) { if (paramfail == true) { Logger::printError(Logger::Error,L"MIPS parameter failure \"%S\"",Params); } else { Logger::printError(Logger::Error,L"Invalid MIPS opcode \"%S\"",Name); } } return false; }
bool CMipsInstruction::Load(const char* Name, const char* Params, int RamPos) { bool paramfail = false; NoCheckError = false; this->RamPos = RamPos; const MipsArchDefinition& arch = mipsArchs[MARCH_PS2]; for (int z = 0; MipsOpcodes[z].name != NULL; z++) { if ((MipsOpcodes[z].archs & arch.supportSets) == 0) continue; if ((MipsOpcodes[z].archs & arch.excludeMask) != 0) continue; if ((MipsOpcodes[z].flags & MO_64BIT) && !(arch.flags & MO_64BIT)) continue; if ((MipsOpcodes[z].flags & MO_FPU) && !(arch.flags & MO_FPU)) continue; if (parseOpcode(MipsOpcodes[z],Name) == true) { if (LoadEncoding(MipsOpcodes[z],Params) == true) { Loaded = true; return true; } paramfail = true; } } if (NoCheckError == false) { if (paramfail == true) { error = "Parameter failure."; } else { error = "Invalid opcode."; } } return false; }
bool CMipsInstruction::Load(const char* Name, const char* Params) { bool paramfail = false; NoCheckError = false; const MipsArchDefinition& arch = mipsArchs[Mips.GetVersion()]; for (int z = 0; MipsOpcodes[z].name != NULL; z++) { if ((MipsOpcodes[z].archs & arch.supportSets) == 0) continue; if ((MipsOpcodes[z].archs & arch.excludeMask) != 0) continue; if ((MipsOpcodes[z].flags & MO_64BIT) && !(arch.flags & MO_64BIT)) continue; if ((MipsOpcodes[z].flags & MO_FPU) && !(arch.flags & MO_FPU)) continue; if (parseOpcode(MipsOpcodes[z],Name) == true) { if (LoadEncoding(MipsOpcodes[z],Params) == true) { Loaded = true; return true; } paramfail = true; } } if (NoCheckError == false) { if (paramfail == true) { Logger::printError(Logger::Error,L"MIPS parameter failure \"%S\"",Params); } else { Logger::printError(Logger::Error,L"Invalid MIPS %S opcode \"%S\"",arch.name,Name); } } return false; }
int main(int argc, char** argv) { char* line; /*Last line read */ char* label; /*Last label read*/ char* oCode; /*Last opcode read*/ char* a1; /*Last arguments read*/ char* a2; char* a3; char* a4; int steer; int stat; /*Status code of last line*/ int num; char *prgName = NULL; char *iFileName = NULL; char *oFileName = NULL; prgName = argv[0]; iFileName = argv[1]; oFileName = argv[2]; /*For manual testing*/ /*prgName = "OutProgram"; iFileName = "test2.txt"; oFileName = "test2_out.txt";*/ line=(char*)malloc((MAX_LINE_LENGTH+1)*sizeof(char)); printf("program name = '%s'\n", prgName); printf("input file name = '%s'\n", iFileName); printf("output file name = '%s'\n", oFileName); /* open the source file */ infile = fopen(argv[1], "r"); outfile = fopen(argv[2], "w"); /*For manual testing*/ /*infile = fopen(iFileName, "r"); outfile = fopen(oFileName, "w");*/ if (infile==NULL) { printf("Error: Cannot open file %s\n", argv[1]); exit(4); } if (outfile==NULL) { printf("Error: Cannot open file %s\n", argv[2]); exit(4); } stat = EMPTY_LINE; while(stat == EMPTY_LINE) /*Find first line */ stat=readAndParse( infile, line, &label, &oCode, &a1, &a2, &a3, &a4); if(strcmp(oCode, ".orig")!=0) { printf("Error: File does not begin with .orig"); closeFiles(); exit(4); } origin = toNum(a1); /*Make sure origin is in correct range */ if(origin < 0 || origin > 65534||origin%2 != 0) { printf("Error: Invalid Origin, must be between 0x0000 and 0xFFFF and even"); closeFiles(); exit(3); } PC = origin; while(stat != DONE) { stat = readLabel(infile, line, &label); if(*label != '\0') { addLabel(&label); } /*Increment PC */ if(stat == OK) PC+=2; } if(PC>65538) /*Prevents program from exceeding memory location 0xFFFF*/ { printf("Error: Program exceeds memory"); closeFiles(); exit(4); } rewind(infile); PC=origin; stat = EMPTY_LINE; while(stat == EMPTY_LINE) /*Finds .orig and goes to next line */ stat=readAndParse( infile, line, &label, &oCode, &a1, &a2, &a3, &a4); fprintf(outfile, "0x%0.4X\n", origin); /*Prints out formated Hex version of .orig line */ while(stat != DONE&&stat!=END_OP) { stat = readAndParse( infile, line, &label, &oCode, &a1, &a2, &a3, &a4); if(stat == OK) { steer = 0; num = parseOpcode(oCode,&steer); if(num== -1) { printf("Error: %s is not a valid opcode\n",oCode); closeFiles(); exit(2); } if(num == 17) stat=END_OP; else { /*Execute Opcode */ processOpcode( num, &steer, a1, a2, a3, a4); PC+=2; } } } /*Must end with .end */ if(stat != END_OP) { printf("Error: File does not have a .end pseudocode\n"); closeFiles(); exit(4); } closeFiles(); return 0; }
Instruction* Instruction::create(const std::string& opcode, BasicBlock* b) { return create(parseOpcode(opcode), b); }