void JIT::emit_op_jlesseq(Instruction* currentInstruction, bool invert) { unsigned op1 = currentInstruction[1].u.operand; unsigned op2 = currentInstruction[2].u.operand; unsigned target = currentInstruction[3].u.operand; // We generate inline code for the following cases in the fast path: // - int immediate to constant int immediate // - constant int immediate to int immediate // - int immediate to int immediate if (isOperandConstantImmediateChar(op1)) { emitGetVirtualRegister(op2, regT0); addSlowCase(emitJumpIfNotJSCell(regT0)); JumpList failures; emitLoadCharacterString(regT0, regT0, failures); addSlowCase(failures); addJump(branch32(invert ? LessThan : GreaterThanOrEqual, regT0, Imm32(asString(getConstantOperand(op1))->tryGetValue()[0])), target); return; } if (isOperandConstantImmediateChar(op2)) { emitGetVirtualRegister(op1, regT0); addSlowCase(emitJumpIfNotJSCell(regT0)); JumpList failures; emitLoadCharacterString(regT0, regT0, failures); addSlowCase(failures); addJump(branch32(invert ? GreaterThan : LessThanOrEqual, regT0, Imm32(asString(getConstantOperand(op2))->tryGetValue()[0])), target); return; } if (isOperandConstantImmediateInt(op2)) { emitGetVirtualRegister(op1, regT0); emitJumpSlowCaseIfNotImmediateInteger(regT0); int32_t op2imm = getConstantOperandImmediateInt(op2); addJump(branch32(invert ? GreaterThan : LessThanOrEqual, regT0, Imm32(op2imm)), target); } else if (isOperandConstantImmediateInt(op1)) { emitGetVirtualRegister(op2, regT1); emitJumpSlowCaseIfNotImmediateInteger(regT1); int32_t op1imm = getConstantOperandImmediateInt(op1); addJump(branch32(invert ? LessThan : GreaterThanOrEqual, regT1, Imm32(op1imm)), target); } else { emitGetVirtualRegisters(op1, regT0, op2, regT1); emitJumpSlowCaseIfNotImmediateInteger(regT0); emitJumpSlowCaseIfNotImmediateInteger(regT1); addJump(branch32(invert ? GreaterThan : LessThanOrEqual, regT0, regT1), target); } }
nodeADT parse(FILE * file, int state) { nodeADT first; nodeADT current; tNumbers vecWhile; tNumbers vecIf; tNumbers vecBalance; vecWhile.numbers = malloc((sizeof(int)) * BLOQUE); vecWhile.pos = 0; vecIf.numbers = malloc(sizeof(int) * BLOQUE); vecIf.pos = 0; vecBalance.numbers = calloc(sizeof(int), BLOQUE); vecBalance.pos = 0; char * string = malloc(sizeof(char) * BLOQUE); int index = 0; int c, i; Commands com = empty; int isFirst = TRUE; Stack stack; stack_init(&stack); while ((c = fgetc(file)) != EOF) { switch (c) { case '(': vecBalance.numbers = resizeMemInt(vecBalance.pos, vecBalance.numbers); (vecBalance.numbers)[vecBalance.pos] = c; for (i = 0; i < index; i++) { string[i] = toupper(string[i]); } if (strncmp(string, "INC", index) == 0) { com = inc; } else if (strncmp(string, "DEC", index) == 0) { com = dec; } else if (strncmp(string, "MR", index) == 0) { com = mr; } else if (strncmp(string, "ML", index) == 0) { com = ml; } else if (strncmp(string, "CZ", index) == 0) { com = cz; } else if (strncmp(string, "IF", index) == 0) { com = ifa; } else if (strncmp(string, "ENDIF", index) == 0) { com = endif; } else if (strncmp(string, "WHILE", index) == 0) { com = whilea; } else if (strncmp(string, "ENDWHILE", index) == 0) { com = endwhile; } else { fprintf(stderr, "Parser invalido1\n"); exit(1); } if (isFirst) { first = newNode(com); current = first; isFirst = FALSE; } else { nodeADT next = newNode(com); addNext(current, next); current = next; } index = 0; break; case ')': if (vecBalance.numbers[vecBalance.pos] != '(') { if (state) { fseek(file, -1, SEEK_CUR); return first; } else { fprintf(stderr, "Parser invalido2\n"); exit(1); } } else { vecBalance.numbers[vecBalance.pos] = 0; } if (index == 0) { if (com != cz) { fprintf(stderr, "Parser invalido3\n"); exit(1); } else { addParam(current, -1); } } else { if (com == endif) { if (vecIf.numbers[(vecIf.pos) - 1] != toInt(string, index)) { fprintf(stderr, "Parser invalido4\n"); exit(1); } (vecIf.pos) -= 1; nodeADT returnTO = (nodeADT) stack_top(&stack); stack_pop(&stack, 0); addReturn(current, returnTO); //le digo al ENDIF cual es su IF correspondiente addJump(returnTO, current); //le digo al IF cual es su ENDIF correspondiente addParam(current, getParam(returnTO)); } else if (com == endwhile) { if (vecWhile.numbers[(vecWhile.pos) - 1] != toInt(string, index)) { fprintf(stderr, "Parser invalido5\n"); exit(1); } (vecWhile.pos) -= 1; nodeADT returnTO = (nodeADT) stack_top(&stack); //castear, maybe stack_pop(&stack, 0); addReturn(current, returnTO); addJump(returnTO, current); addParam(current, getParam(returnTO)); } else if (com == cz) { fprintf(stderr, "Parser invalido6\n"); exit(1); } else { hasNumbers(string, index); addParam(current, toInt(string, index)); } vecBalance.numbers[vecBalance.pos] = 0; index = 0; } break; case ',': if (index != 0 && (com == ifa || com == whilea)) { hasNumbers(string, index); addParam(current, toInt(string, index)); if (com == ifa) { vecIf.numbers = resizeMemInt(vecIf.pos, vecIf.numbers); vecIf.numbers[(vecIf.pos)++] = toInt(string, index); } else { vecWhile.numbers = resizeMemInt(vecWhile.pos, vecWhile.numbers); vecWhile.numbers[(vecWhile.pos)++] = toInt(string, index); } stack_push(&stack, current); addExe(current, parse(file, TRUE)); } else { fprintf(stderr, "Parser invalido7\n"); exit(1); } break; case ' ': case '\n': case '\t': break; default: string = resizeMemChar(index, string); string[index++] = c; break; } } if (vecBalance.numbers[vecBalance.pos] != 0) { fprintf(stderr, "Parser invalido8\n"); exit(1); } return first; }