Aggiunti controlli su argomenti

This commit is contained in:
Giulio De Pasquale 2017-07-08 23:26:14 +02:00
parent 07dcd98e86
commit 6746d96fd4

297
vm/vm.cpp
View File

@ -856,107 +856,274 @@ bool VM::execGRMN(void) {
void VM::run(void) { void VM::run(void) {
uint8_t opcode; uint8_t opcode;
bool finished = false; bool finished = false;
bool ret;
while (!finished) { while (!finished) {
opcode = (uint8_t)as.code[regs[IP]]; opcode = (uint8_t)as.code[regs[IP]];
if (opcode == OPS[MOVI]) { if (opcode == OPS[MOVI]) {
execMOVI(); ret = execMOVI();
regs[IP] += MOVI_SIZE; if (ret) {
regs[IP] += MOVI_SIZE;
} else {
DBG_ERROR(("MOVI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[MOVR]) { } else if (opcode == OPS[MOVR]) {
execMOVR(); ret = execMOVR();
regs[IP] += MOVR_SIZE; if (ret) {
regs[IP] += MOVR_SIZE;
} else {
DBG_ERROR(("MOVR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[LODI]) { } else if (opcode == OPS[LODI]) {
execLODI(); ret = execLODI();
regs[IP] += LODI_SIZE; if (ret) {
regs[IP] += LODI_SIZE;
} else {
DBG_ERROR(("LODI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[LODR]) { } else if (opcode == OPS[LODR]) {
execLODR(); ret = execLODR();
if (ret) {
regs[IP] += LODR_SIZE;
} else {
DBG_ERROR(("LODR FAILED.\n"));
finished = true;
}
regs[IP] += LODR_SIZE; regs[IP] += LODR_SIZE;
} else if (opcode == OPS[STRI]) { } else if (opcode == OPS[STRI]) {
execSTRI(); ret = execSTRI();
regs[IP] += STRI_SIZE; if (ret) {
regs[IP] += STRI_SIZE;
} else {
DBG_ERROR(("MOVI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[STRR]) { } else if (opcode == OPS[STRR]) {
execSTRR(); ret = execSTRR();
regs[IP] += STRR_SIZE; if (ret) {
regs[IP] += STRR_SIZE;
} else {
DBG_ERROR(("STRR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[ADDI]) { } else if (opcode == OPS[ADDI]) {
execADDI(); ret = execADDI();
regs[IP] += ADDI_SIZE; if (ret) {
regs[IP] += ADDI_SIZE;
} else {
DBG_ERROR(("ADDI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[ADDR]) { } else if (opcode == OPS[ADDR]) {
execADDR(); ret = execADDR();
regs[IP] += ADDR_SIZE; if (ret) {
regs[IP] += ADDR_SIZE;
} else {
DBG_ERROR(("ADDR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[SUBI]) { } else if (opcode == OPS[SUBI]) {
execSUBI(); ret = execSUBI();
regs[IP] += SUBI_SIZE; if (ret) {
regs[IP] += SUBI_SIZE;
} else {
DBG_ERROR(("SUBI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[SUBR]) { } else if (opcode == OPS[SUBR]) {
execSUBR(); ret = execSUBR();
regs[IP] += SUBR_SIZE; if (ret) {
regs[IP] += SUBR_SIZE;
} else {
DBG_ERROR(("SUBR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[ANDB]) { } else if (opcode == OPS[ANDB]) {
execANDB(); ret = execANDB();
regs[IP] += ANDB_SIZE; if (ret) {
regs[IP] += ANDB_SIZE;
} else {
DBG_ERROR(("ANDB FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[ANDW]) { } else if (opcode == OPS[ANDW]) {
execANDW(); ret = execANDW();
regs[IP] += ANDW_SIZE; if (ret) {
regs[IP] += ANDW_SIZE;
} else {
DBG_ERROR(("ANDW FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[ANDR]) { } else if (opcode == OPS[ANDR]) {
execANDR(); ret = execANDR();
regs[IP] += ANDR_SIZE; if (ret) {
regs[IP] += ANDR_SIZE;
} else {
DBG_ERROR(("ANDR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[YORB]) { } else if (opcode == OPS[YORB]) {
execYORB(); ret = execYORB();
regs[IP] += YORB_SIZE; if (ret) {
regs[IP] += YORB_SIZE;
} else {
DBG_ERROR(("YORB FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[YORW]) { } else if (opcode == OPS[YORW]) {
execYORW(); ret = execYORW();
regs[IP] += YORW_SIZE; if (ret) {
regs[IP] += YORW_SIZE;
} else {
DBG_ERROR(("YORW FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[YORR]) { } else if (opcode == OPS[YORR]) {
execYORR(); ret = execYORR();
regs[IP] += YORR_SIZE; if (ret) {
regs[IP] += YORR_SIZE;
} else {
DBG_ERROR(("YORR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[XORB]) { } else if (opcode == OPS[XORB]) {
execXORB(); ret = execXORB();
regs[IP] += XORB_SIZE; if (ret) {
regs[IP] += XORB_SIZE;
} else {
DBG_ERROR(("XORB FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[XORW]) { } else if (opcode == OPS[XORW]) {
execXORW(); ret = execXORW();
regs[IP] += XORW_SIZE; if (ret) {
regs[IP] += XORW_SIZE;
} else {
DBG_ERROR(("XORW FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[XORR]) { } else if (opcode == OPS[XORR]) {
execXORR(); ret = execXORR();
regs[IP] += XORR_SIZE; if (ret) {
regs[IP] += XORR_SIZE;
} else {
DBG_ERROR(("XORR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[NOTR]) { } else if (opcode == OPS[NOTR]) {
execNOTR(); ret = execNOTR();
regs[IP] += NOTR_SIZE; if (ret) {
regs[IP] += NOTR_SIZE;
} else {
DBG_ERROR(("NOTR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[MULI]) { } else if (opcode == OPS[MULI]) {
execMULI(); ret = execMULI();
regs[IP] += MULI_SIZE; if (ret) {
regs[IP] += MULI_SIZE;
} else {
DBG_ERROR(("MULI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[MULR]) { } else if (opcode == OPS[MULR]) {
execMULR(); ret = execMULR();
regs[IP] += MULR_SIZE; if (ret) {
regs[IP] += MULR_SIZE;
} else {
DBG_ERROR(("MULR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[DIVI]) { } else if (opcode == OPS[DIVI]) {
execDIVI(); ret = execDIVI();
regs[IP] += DIVI_SIZE; if (ret) {
regs[IP] += DIVI_SIZE;
} else {
DBG_ERROR(("DIVI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[DIVR]) { } else if (opcode == OPS[DIVR]) {
execDIVR(); ret = execDIVR();
regs[IP] += DIVR_SIZE; if (ret) {
regs[IP] += DIVR_SIZE;
} else {
DBG_ERROR(("DIVR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[SHLI]) { } else if (opcode == OPS[SHLI]) {
execSHLI(); ret = execSHLI();
regs[IP] += SHLI_SIZE; if (ret) {
regs[IP] += SHLI_SIZE;
} else {
DBG_ERROR(("SHLI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[SHLR]) { } else if (opcode == OPS[SHLR]) {
execSHLR(); ret = execSHLR();
regs[IP] += SHLR_SIZE; if (ret) {
regs[IP] += SHLR_SIZE;
} else {
DBG_ERROR(("SHLR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[SHRI]) { } else if (opcode == OPS[SHRI]) {
execSHRI(); ret = execSHRI();
regs[IP] += SHRI_SIZE; if (ret) {
regs[IP] += SHRI_SIZE;
} else {
DBG_ERROR(("SHRI FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[SHRR]) { } else if (opcode == OPS[SHRR]) {
execSHRR(); ret = execSHRR();
regs[IP] += SHRR_SIZE; if (ret) {
regs[IP] += SHRR_SIZE;
} else {
DBG_ERROR(("SHRR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[PUSH]) { } else if (opcode == OPS[PUSH]) {
execPUSH(); ret = execPUSH();
regs[IP] += PUSH_SIZE; if (ret) {
regs[IP] += PUSH_SIZE;
} else {
DBG_ERROR(("PUSH FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[POOP]) { } else if (opcode == OPS[POOP]) {
execPOOP(); ret = execPOOP();
regs[IP] += POOP_SIZE; if (ret) {
regs[IP] += POOP_SIZE;
} else {
DBG_ERROR(("POOP FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[CMPB]) { } else if (opcode == OPS[CMPB]) {
execCMPB(); ret = execCMPB();
regs[IP] += CMPB_SIZE; if (ret) {
regs[IP] += CMPB_SIZE;
} else {
DBG_ERROR(("CMPB FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[CMPW]) { } else if (opcode == OPS[CMPW]) {
execCMPW(); ret = execCMPW();
regs[IP] += CMPW_SIZE; if (ret) {
regs[IP] += CMPW_SIZE;
} else {
DBG_ERROR(("CMPW FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[CMPR]) { } else if (opcode == OPS[CMPR]) {
execCMPR(); ret = execCMPR();
regs[IP] += CMPR_SIZE; if (ret) {
regs[IP] += CMPR_SIZE;
} else {
DBG_ERROR(("CMPR FAILED.\n"));
finished = true;
}
} else if (opcode == OPS[JMPI]) { } else if (opcode == OPS[JMPI]) {
execJMPI(); execJMPI();
} else if (opcode == OPS[JMPR]) { } else if (opcode == OPS[JMPR]) {